How can i plot it in 3D

3 ビュー (過去 30 日間)
Minh Nguyen
Minh Nguyen 2020 年 12 月 20 日
コメント済み: Minh Nguyen 2020 年 12 月 20 日
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.

回答 (1 件)

Alan Stevens
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
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
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 2020 年 12 月 20 日
oh thanks you so much!!!

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by