user1834153
user1834153

Reputation: 330

how can I plot the span of a matrix 3x2 in matlab?

I tried this way:

    gl1 =
   -2.5000   -1.0000
    4.3301    1.7321
    0         0
syms a b
span=gl1(:,1)*a+gl1(:,2)*b
a=[-100:0.1:100];
b=[-100:0.1:100];
span=eval(span)

and then I'd do plot3(span). unfortunatly at the last row it gives me this error:

Error using vertcat
Dimensions of matrices being concatenated are not consistent.

Error in sym/eval (line 11)
s = evalin('caller',vectorize(map2mat(char(x))));

any idea? I've found someone using a polytope method to do it,but I have no idea where I can get or I how can I realize such method.

thanks you in advice.

edit:in this case the span should be a line,since the rank of my matrix is one,but the question stands for a matrix with rank 2.

Upvotes: 1

Views: 2481

Answers (1)

Stewie Griffin
Stewie Griffin

Reputation: 14939

Why use symbolics? This works like a charm:

gl1 =
   -2.5000   -1.0000
    4.3301    1.7321
    0         0

a=[-100:0.1:100];
b=[-100:0.1:100];

span=gl1(:,1)*a+gl1(:,2)*b

Remember that you need several inputs to plot3, i.e. the x, y, and z-values. Thus it should be something like this:

plot3(span(1,:),span(2,:),span(3,:)) 

Upvotes: 1

Related Questions