Mesh and Contour not plotting correctly

2 ビュー (過去 30 日間)
Ameen Yar Khan
Ameen Yar Khan 2020 年 3 月 10 日
回答済み: Star Strider 2020 年 3 月 10 日
This is in regards to F2 in the code below. I graphed the meshplot on wolfram as well as saw how one of my classmates did it. Their's look the same however mine looks different. Not sure why F2 isn't being plotted correctly. It should have a different shape with two minima at the center. MATLAB output is shown first (screen snip) along with the Wolfram alpha output (assumed correct).
Any help/suggestion is greatly appreciated.
x1 = -10:0.1:10;
x2 = -10:0.1:10;
[X1,X2] = meshgrid(x1,x2);
F1 = (X1.^2 + X2.^2 + (4*X1) - (2*X2));
F2 = ((5*X1.^2) + (X1.^4) - (9*(X1.^2)*X2) + 3*(X2.^2) + (2*X2.^4) + (0.25*X1));
subplot(2,2,1); mesh(X1,X2,F1); title('F_1');
subplot(2,2,2); mesh(X1,X2,F2); title('F_2');
subplot(2,2,3); contour(X1,X2,F1); title('F1 Contour');
subplot(2,2,4); contour(X1,X2,F2); title('F2 Contour');

回答 (1 件)

Star Strider
Star Strider 2020 年 3 月 10 日
I slightly changed your code to make it a bit less confusing (creating ‘x’ and ‘y’ and ‘X’ and ‘Y’):
x = -10:0.1:10;
y = -10:0.1:10;
[X,Y] = meshgrid(x,y);
There is one error. You need to do element-wise multiplication:
F2 = ((5*X.^2) + (X.^4) - (9*(X.^2).*Y) + 3*(Y.^2) + (2*Y.^4) + (0.25*X));
↑ ← HERE
They now appear to be the same.

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by