Overlaying individual contours on a contour plot
Mostrar comentarios más antiguos
I'm sure this isn't difficult to do but I'm pretty new to matlab and am not sure how to add individual contour lines to a contour plot.
For example I have a contour plot of the function
which is subject to a constraint
. I've got the contour plot of f(x) just fine, however I am not sure how to plot the constraint contour on the same plot as well. How do I display the individual curve of h(x) on the contour plot of f(x)?
My current code just for the contour plot of f(x) is:
syms x1 x2;
f = (x2-x1^2)^2 + 0.1*(1-x1)^2;
grad = jacobian(f,[x1;x2]);
hess = jacobian(grad,[x1;x2]);
figure;
[gridx,gridy] = meshgrid([-1.5:.1:1.5],[-1:0.1:1.5]);
[c,h] = contour(gridx,gridy,subs(f,{x1,x2},{gridx,gridy}),[0,0.1,0.5:0.5:10]);
clabel(c,h,'LabelSpacing',2000);
title('f');
xlabel('x_1');
ylabel('x_2');
Respuestas (0)
Categorías
Más información sobre Contour Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!