How can i plot it in 3D

3 visualizaciones (últimos 30 días)
Minh Nguyen
Minh Nguyen el 20 de Dic. de 2020
Comentada: Minh Nguyen el 20 de Dic. de 2020
x = linspace(-5,5,40);
y = linspace(-5,5,40);
z = x.^2+y.^4-2*x*y.^2+1
surf(x,y,z)
xlabel ('x')
ylabel ('y')
zlabel ('z')
I tried to plot this function in 3D but i met some error:
-Error using *
-Inner matrix dimensions must agree.

Respuestas (1)

Alan Stevens
Alan Stevens el 20 de Dic. de 2020
Like so
x = linspace(-5,5,40);
y = linspace(-5,5,40);
[x, y] = meshgrid(x,y);
z = x.^2+y.^4-2*x*y.^2+1
surf(x,y,z)
xlabel ('x')
ylabel ('y')
zlabel ('z')
  3 comentarios
Walter Roberson
Walter Roberson el 20 de Dic. de 2020
The plot for that equation does not look like that second figure, no matter which way you rotate it and no matter how small a section of it you plot.
syms x y
z = x.^2+y.^4-2*x*y.^2+1
z = 
fsurf(z, [1 2 -2 2]); view(88, -4)
You have to cut the x axis to minimum 1 in order to get a section that curves away from you like the foreground of the sample plot you show -- I know this output might not look like it curves away but if you grab the axes and rotate it slightly then it becomes clear. But once you have the section that curves away from you, the main plot has to curve away from you too, unlike the sample plot given as the desired, where the ends curve towards the viewer.
Note: the equation given to us can also be written as (x-y^2)^2 + 1, which is at minima along the line y = +/- sqrt(x)
Minh Nguyen
Minh Nguyen el 20 de Dic. de 2020
oh thanks you so much!!!

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by