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!