Reputation: 53
I was trying an example about using fsurf using a code from this tread ( Using Matlab to plot a cylinder bounded by a plane ).
The problem comes when I change the name of a declared syms variable the output of the graph changes completely, which I don´t really understand. Here is the output using the original code:
symObj = syms;
cellfun(@clear,symObj)
clear all
close all
syms r t u
fsurf(cos(r),sin(r),u*(cos(r)+2),[0,2*pi,0,1])
hold on
fsurf(r*cos(t),r*sin(t),r*cos(t)+2,[0,1,0,2*pi],'FaceColor','r')
rotate3d on
and here is the same example in which I only changed the name of the variable 't' to 'phi' in the declaration variable and the three places it was used in:
symObj = syms;
cellfun(@clear,symObj)
clear all
close all
syms r phi u
fsurf(cos(r),sin(r),u*(cos(r)+2),[0,2*pi,0,1])
hold on
fsurf(r*cos(phi),r*sin(phi),r*cos(phi)+2,[0,1,0,2*pi],'FaceColor','r')
rotate3d on
fsurf result with alternative variable name:
Upvotes: 5
Views: 115
Reputation: 60494
I don’t have the symbolic toolbox installed at the moment to test this out, but I think this is the problem: fsurf
is given two intervals to plot in as a single vector: [0,1,0,2*pi]
. One variable will run from 0 to 1, another from 0 to 2 pi. But which variable will be given each interval?
Since there is no explicit ordering of variables in the function call, all fsurf
can do is sort them alphabetically. Usually people use x and y, or u and v, which are sorted alphabetically. Note that the order in which you originally declared the variables is not recorded anywhere in MATLAB, this information can only be recovered by examining the source code that was run to declare those variables. fsurf
certainly doesn’t know the order in which you think of these variables.
The first code uses variables r and t, the second one uses phi and r. Switching the order of the two intervals in the interval array should fix your issue if my guess is right.
Upvotes: 4