Trying to add labels to a contour map of a given function
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Voss
le 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 commentaires
Voss
le 11 Jan 2023
Modifié(e) : Voss
le 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')
Voir également
Catégories
En savoir plus sur Contour Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!