user678392
user678392

Reputation: 2031

Not understanding some (basic) Matlab commands to plot

 plot([0 u(1,1)], [0 u(2,1)]);
 plot([0 u(1,2)], [0 u(2,2)]);

These commands do what I want. However, why are the zeros in front.

The effect of these commands is the second plot on the page: enter image description here

Upvotes: 0

Views: 46

Answers (1)

Benoit_11
Benoit_11

Reputation: 13945

The 0s are used to denote plotting boundaries; since Matlab need to have starting and ending values for both x and y.

For instance, in this statement:

plot([0 u(1,1)], [0 u(2,1)]);

the 2 terms in the first square brackets represent the range of x-values to plot, i.e. from 0 to u(1,1), while those in the 2nd square bracket represent the y-values. It basically plots a line going from (x1,y1) to (x2,y2), with x1 and y1 being (0,0), x2 being u(1,1) and y2 being u(2,1).

From the code you were given, u looks like this: (I'm not showing you the whole solution since this is homework :)

u =

   -0.7055   -0.7087
   -0.7087    0.7055

Therefore, the line corresponding to the line above will have x-values form 0 to u(1,1) = -0.7055 and y-values going from 0 to u(2,1) = -0.7087. The same applies for the 2nd call to plot.

Here is a figure obtained with the data; I plotted both curves with different colors so you can see the difference: (I used @knedlsepp's suggestion to use axis equal to see that both lines are orthogonal.

enter image description here

Hope that helps get you started. Good luck!

Upvotes: 1

Related Questions