Trying to add labels to a contour map of a given function
4 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Voss
on 11 Jan 2023
X1 = 1:10;
X2 = 5:20;
F = X1.^2 + X1.*X2(:) - X2(:).^2;
contour(X1,X2,F,'ShowText','on')
xlabel('X1')
ylabel('X2')
2 Comments
Voss
on 11 Jan 2023
Edited: Voss
on 11 Jan 2023
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')
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!