Plot a function in 3D that can be either positive or negative?
3 次查看(过去 30 天)
显示 更早的评论
Hello, I have to plot a 3D function that is described by: y= +- (B/2)[1-(2*x/L)^2][1-(2*z/T)^2].
I have B=1.2, L=4, T=0.5, -2<=x<=2 and -0.5<=z<=2.
I know I have to make two matrices from x and z using meshgrid and then get the value of matrix y from the corresponding equation so I substituted the values of B,L and T in the equation and simplified it. Here is my code:
x=-2:2;
z=-0.5:0.5:2;
[X,Z]=meshgrid(x,z)
Y=(2.4.*X.^2.*Z.^2 - 9.6.*Z.^2 - 0.15.*X.^2 + 0.6);
mesh (X,Y,Z)
grid off
xlabel('x'); ylabel('y'); zlabel('z');
It runs and I see a figure close to the real shape but not the real shape because the function has +- at the beginning of it (+ or -) and I don't know how to write this in Matlab. I uploaded the figure it should looks like and my figure for comparison, any help will be much appreciated. Thanks in advance
0 个评论
采纳的回答
Mischa Kim
2014-4-18
编辑:Mischa Kim
2014-4-18
Mahmoud, a quick fix would be to add
hold on
Y = -(2.4.*X.^2.*Z.^2 - 9.6.*Z.^2 - 0.15.*X.^2 + 0.6);
mesh (X,Y,Z)
As an alternative, you could - it looks like - solve for z(x,y).
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!