linspace error while trying to plot
1 view (last 30 days)
Show older comments
fartash2020
on 30 Nov 2017
Commented: Walter Roberson
on 30 Nov 2017
Dear all,
I have written a code for linspace I want a 3D plot of it:
% First we set the constants:
kd=6;
lambda= 0.01;
Delta_E=0.02;
% Then we write down the Formulas:
z=linspace(-1,1,200);
kappa=linspace(0,1,200);
q=((Delta_E)+(lambda.*z)+(((sqrt((1+z)./2)).*exp(-(kd.*(sqrt(2.*lambda'.*(1+z))))))).*(kappa.*(sqrt((1-z)./(1+z)))-(sqrt((1+z)./(1-z )))));
% Now we plot q(Z,kappa) vs Z and kappa :
figure(1)
mesh(z,kappa,q)
% title('kd=6');
xlabel('Z');
ylabel('lambda');
zlabel('q)');
I think that my "q" must have 200*200 matrix, but it is not. Its gives just 1*200.
I would highly appreciate if you help me.
Thanks,
0 Comments
Accepted Answer
Walter Roberson
on 30 Nov 2017
Change
z=linspace(-1,1,200);
kappa=linspace(0,1,200);
to
Z = linspace(-1,1,200);
KAPPA = linspace(0,1,200);
[z, kappa] = meshgrid(Z, KAPPA);
Note: you have
ylabel('lambda');
which is not correct. Your lambda is a constant. Your y axes is kappa, not lambda.
2 Comments
Walter Roberson
on 30 Nov 2017
contour(z, kappa, q, [0 0])
the [0 0] is a trick that has to be used when you are only asking for one contour value; if you were to try to pass in the scalar 0 at that point, it would try to interpret the scalar 0 as the number of contour levels to draw.
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays 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!