How can i plot it in 3D

3 views (last 30 days)
Minh Nguyen
Minh Nguyen on 20 Dec 2020
Commented: Minh Nguyen on 20 Dec 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.

Answers (1)

Alan Stevens
Alan Stevens on 20 Dec 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 Comments
Walter Roberson
Walter Roberson on 20 Dec 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 on 20 Dec 2020
oh thanks you so much!!!

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!