Borrar filtros
Borrar filtros

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

3 visualizaciones (últimos 30 días)
Mahmoud
Mahmoud el 18 de Abr. de 2014
Editada: Mischa Kim el 18 de Abr. de 2014
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

Respuesta aceptada

Mischa Kim
Mischa Kim el 18 de Abr. de 2014
Editada: Mischa Kim el 18 de Abr. de 2014
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).

Más respuestas (0)

Categorías

Más información sobre Surface and Mesh Plots en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by