How can i plot it in 3D

3 vues (au cours des 30 derniers jours)
Minh Nguyen
Minh Nguyen le 20 Déc 2020
Commenté : Minh Nguyen le 20 Déc 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.

Réponses (1)

Alan Stevens
Alan Stevens le 20 Déc 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 commentaires
Walter Roberson
Walter Roberson le 20 Déc 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 le 20 Déc 2020
oh thanks you so much!!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by