フィルターのクリア

Error with plotting function

2 ビュー (過去 30 日間)
Annelotte
Annelotte 2023 年 1 月 21 日
編集済み: Star Strider 2023 年 1 月 21 日
I want to plot z = (1.5-x1+x1*x2)^2 +(2.25-x1+x1*(x1^2))^2+(2.625-x1+x1*(x2)^3)^2 with -5<x1<5 and -5<x2<5.
I tried:
x1 = -5:5;
x2 = -5:5;
z = (1.5-x1+x1*x2).^2 +(2.25-x1+x1*(x1.^2)).^2+(2.625-x1+x1*(x2).^3).^2;
plot(x1,x2,z);
What am I doing wrong? It gives error: Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To perform elementwise multiplication, use '.*'.

採用された回答

Star Strider
Star Strider 2023 年 1 月 21 日
編集済み: Star Strider 2023 年 1 月 21 日
You will need to use element-wise operators with vector arguments. See Array vs. Matrix Operations for details.
Use surf for the plot.
The fsurf function can also be used plot the resulting surface —
z = @(x1,x2) (1.5-x1+x1.*x2).^2 +(2.25-x1+x1.*(x1.^2))^2+(2.625-x1+x1.*(x2).^3).^2;
x1 = -5:5;
x2 = -5:5;
[X1,X2] = ndgrid(x1,x2);
figure
surf(X1, X2, z(X1,X2))
grid
xlabel('X_1')
ylabel('X_2')
zlabel('z')
syms x1 x2
z = (1.5-x1+x1*x2)^2 +(2.25-x1+x1*(x1^2))^2+(2.625-x1+x1*(x2)^3)^2;
figure
grid
fsurf(z, [-5 5 -5 5])
xlabel('X_1')
ylabel('X_2')
zlabel('z')
EDIT — Corrected typographical errors.
.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangePhysics についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by