Trying to add labels to a contour map of a given function
4 ビュー (過去 30 日間)
古いコメントを表示
The function uses two varying X1 and X2 variables and I want the function to be mapped as a contour plot given the varying X1 and X2 values. I also want to label the contour lines with their respective value.
0 件のコメント
回答 (1 件)
Voss
2023 年 1 月 11 日
X1 = 1:10;
X2 = 5:20;
F = X1.^2 + X1.*X2(:) - X2(:).^2;
contour(X1,X2,F,'ShowText','on')
xlabel('X1')
ylabel('X2')
2 件のコメント
Voss
2023 年 1 月 11 日
編集済み: Voss
2023 年 1 月 11 日
Use the transpose of Y (i.e., Y.') or Y(:) in the calculation of Z, because Z must be a matrix:
l1 = 10
l2 = 10
K1 = 8
K2 = 1
P1= 5
P2 = 5
X = -10:2:10
Y = -10:2:10
Z = 1/2*(K1)*(sqrt(X.^2+(l1-Y(:)).^2)-l1).^2+1/2*(K2)*(sqrt(X.^2+(l2+Y(:)).^2)-l2).^2-P1*X-P2*Y(:)
contour(X,Y,Z,'ShowText','on')
xlabel('X')
ylabel('Y')
参考
カテゴリ
Help Center および File Exchange で Contour Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!