Fsurf plot wrong when x coefficient is 0

1 view (last 30 days)
The script will produce graph like this
syms x y z u v
fsurf(214.90609811873839701574097069388 - 2.032409294075229574399388894873*v,v,u,[-200,+200],'FaceColor','red');
hold on
fsurf(2.5564704196832668259276033495553*y-14.255253156645956380543793784454+0.00000000000*x,[-200,+200],'FaceColor','green')
fsurf(256.06484646683490299896860383123 - 1.2578521595702952545440650237956*x,[-200,+200],'FaceColor','blue')
xlabel('X')
ylabel('Y')
zlabel('Z')
hold off
untitled.png
As you can see the green plane is wrong MatLab is treating y as x, despite the x coefficient is 0

Accepted Answer

Star Strider
Star Strider on 21 Apr 2019
The fsurf function cannot guess what you are thinking.
Try this version of your code:
syms x y z u v
f1(v) = 214.90609811873839701574097069388 - 2.032409294075229574399388894873*v;
f2(x,y) = 2.5564704196832668259276033495553*y-14.255253156645956380543793784454+0.00000000000*x;
f3(x) = 256.06484646683490299896860383123 - 1.2578521595702952545440650237956*x;
figure
fsurf(f1,v,u,[-200,+200],'FaceColor','red');
hold on
fsurf(f2,[-200,+200],'FaceColor','green')
fsurf(f3,[-200,+200],'FaceColor','blue')
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
view(-50,15)
Experiment to get the result you want.
  2 Comments
Xinhua
Xinhua on 22 Apr 2019
Yep that works,never know we have to address the y variable this way.Strange behavior though.
Thank you.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 21 Apr 2019
When you construct an expression A*x + B*y + C with symbolic x and Y, and A is 0, then the symbolic engine does not deliberately hold on to the 0*x "just in case" you wanted to know later that X had been part of the equation at some point. Instead it simplifies it to B*y + C -- an expression with a single symbolic variable.
When you fsurf() an expression with a single symbolic variable, then fsurf() assumes that that symbolic variable is the independent variable, and it always puts the independent variable along the x axes. It does not look at the name of the symbolic variable. There is no difference between
syms x y u
fsurf(5*x + 2)
fsurf(5*y + 2)
fsurf(5*u + 2)
The only context in which it looks at the actual names of the variables is that it uses symvar() on the expression to order the variables, and symvar sorts the variables by name.
syms a b c
fsurf(5*a - 3 * b + 2) %a sorts first, it is the independent variable
fsurf(5*c - 3 * b + 2) %b sorts first, it is the independent variable

Tags

Products


Release

R2016b

Community Treasure Hunt

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

Start Hunting!