Trying to add labels to a contour map of a given function
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Voss
il 11 Gen 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 Commenti
Voss
il 11 Gen 2023
Modificato: Voss
il 11 Gen 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')
Vedere anche
Categorie
Scopri di più su Contour Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!