how to plot a surface in MATLAB?
2 views (last 30 days)
Show older comments
Commented: Walter Roberson on 3 Feb 2017
[fi, fn] = meshgrid(linspace(10,180,N),linspace(1,2,N));
surf(fi, fn, Gdc, 'edgecolor', 'b')
I have to plot a surface by these equations but it is not giving me what i expected. Can anyone help me?
You did not give us any ideas what you were expecting so it is difficult to debug.
Possibly in c, g, h, you want .* (1-cosd(fi)) instead of * (1-cosd(fi))
By the way, for efficiency you should calculate (1-cosd(fi)) only once and use the result multiple times.
I was hoping for mathematical equations, to reduce the ambiguity of .* compared to * as you coded some multiplications with * (algebraic matrix multiplication).
What you just posted contains in part
As lamda is a scalar rather than a matrix, the lamda can be moved in front in both subexpressions,
and you can see that the two sub-expressions are the same but of opposite signs and so will cancel out to 0. In your original question these were d and e
In the below code I have left them in as expressions d and e even though they mathematically cancel out, so as to make it easier for you to find the place that will have to be changed.
N = 50;
fi = linspace(0, 180, N) * pi/180;
fn = linspace(0.1, 5, N);
[FI, FN] = ndgrid(fi, fn);
rl = 2.2;
GAMMA = pi ./ FN;
cosFI = cos(FI);
M1cosFI = 1 - cosFI;
FIlamda = lamda .* FI;
FI2lamda = FIlamda .* FI;
d = (0.5*FI2lamda);
e = (0.5*FI2lamda);
Gdc = M1cosFI ./ (M1cosFI + ((GAMMA/rl) .* (1-0.5.*M1cosFI)) - ((0.25*FI2lamda).*M1cosFI) + d - e + (0.5*FIlamda.*sin(FI)) - ((0.25*FIlamda.*GAMMA).*M1cosFI) + (0.5*FI2lamda).*M1cosFI);
surf(FI, FN, Gdc)
This implements the equations fairly efficiently, but the outcome is not like you had hoped, which is partly due to the problem with d and e. But only partly -- over those ranges, these equations have a bunch of narrow peaks that would be difficult to miss if you happened to plot at the wrong resolution or with slightly the wrong locations.
More Answers (0)
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!