I want to know the simplest way to plot vectors in MATLAB. For example:
a = [2 3 5];
b = [1 1 0];
c = a + b;
I want to visualize this vector addition as head-to-tail/parallelogram method. How do I plot these vectors with an arrow-head?
I want to know the simplest way to plot vectors in MATLAB. For example:
a = [2 3 5];
b = [1 1 0];
c = a + b;
I want to visualize this vector addition as head-to-tail/parallelogram method. How do I plot these vectors with an arrow-head?
a = [2 3 5];
b = [1 1 0];
c = a+b;
starts = zeros(3,3);
ends = [a;b;c];
quiver3(starts(:,1), starts(:,2), starts(:,3), ends(:,1), ends(:,2), ends(:,3))
axis equal
I found this arrow(start, end) function on MATLAB Central which is perfect for this purpose of drawing vectors with true magnitude and direction.
I agree with Aamir that the submission arrow.m from Erik Johnson on the MathWorks File Exchange is a very nice option. You can use it to illustrate the different methods of vector addition like so:
Tip-to-tail method:
o = [0 0 0]; %# Origin
a = [2 3 5]; %# Vector 1
b = [1 1 0]; %# Vector 2
c = a+b; %# Resultant
arrowStarts = [o; a; o]; %# Starting points for arrows
arrowEnds = [a; c; c]; %# Ending points for arrows
arrow(arrowStarts,arrowEnds); %# Plot arrows
Parallelogram method:
o = [0 0 0]; %# Origin
a = [2 3 5]; %# Vector 1
b = [1 1 0]; %# Vector 2
c = a+b; %# Resultant
arrowStarts = [o; o; o]; %# Starting points for arrows
arrowEnds = [a; b; c]; %# Ending points for arrows
arrow(arrowStarts,arrowEnds); %# Plot arrows
hold on;
lineX = [a(1) b(1); c(1) c(1)]; %# X data for lines
lineY = [a(2) b(2); c(2) c(2)]; %# Y data for lines
lineZ = [a(3) b(3); c(3) c(3)]; %# Z data for lines
line(lineX,lineY,lineZ,'Color','k','LineStyle',':'); %# Plot lines