Plot a function in 3D that can be either positive or negative?

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

 採用された回答

Mischa Kim
Mischa Kim 2014 年 4 月 18 日
編集済み: Mischa Kim 2014 年 4 月 18 日

0 投票

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 件)

カテゴリ

質問済み:

2014 年 4 月 18 日

編集済み:

2014 年 4 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by