How can i plot it in 3D
3 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
回答 (1 件)
Alan Stevens
2020 年 12 月 20 日
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 件のコメント
Walter Roberson
2020 年 12 月 20 日
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
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)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


