I have an error with the plot3 function "vectors must be the same length"

As the title says, I get the error and I'm new to matlab so I can't really figure out what is the problem. I tried to read previous questions on the same subject but those codes were too complicated for me to understand.
my code:
close all
syms x y
fmesh(((x^2)*y)/((x^2+y)^2),[0 2 -1 1], 'ShowContours','on')
hold on;
t = -1:0.1:1;
x1 = t;
x2 = t.^2;
x3 = (t.^4)/(4*t.^4);
p=plot3(x1,x2,x3);grid
xlabel('x');
ylabel('y');
zlabel('z');
length(p);

 Accepted Answer

The problem you had was that you were using the / operator.
In MATLAB A/B means roughly the same as A * pinv(B) --- it does not mean that each element of A is to be divided by the corresponding element of B.
The MATLAB operator for element-by-element division of corresponding positions is the ./ operator instead of the / operator.
syms x y
fmesh(((x^2)*y)/((x^2+y)^2),[0 2 -1 1], 'ShowContours','on')
hold on;
t = -1:0.1:1;
x1 = t;
x2 = t.^2;
x3 = (t.^4)./(4*t.^4);
p=plot3(x1,x2,x3);grid
xlabel('x');
ylabel('y');
zlabel('z');
length(p)
ans = 1

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!