4 commentaires

Walter Roberson
Walter Roberson le 11 Nov 2022
I do not understand what you are trying to do?
You minimize fun under some constraints, and you get back xopt (the 1 x 2 location of a minima) and fopt (the value of the function at the minima). Then you create a grid of discrete values, overwriting the location and function value information you stored.
The only way I can see to "make a contour plot of the results from minimizing a function" would be be for the case where the function had two parameters, and you wanted to minimize the function at each location in a grid of the two parameters.
Roneau
Roneau le 11 Nov 2022
Sorry I had the objective wrong, I'm trying to create a contour plot of the ojective function, display the minimum values & function value, and add constraint information to it.
Walter Roberson
Walter Roberson le 12 Nov 2022
Well you can certainly create a grid and contour() it. And you can plot(xopt(1), xopt(2), '*') to mark the location of the minima on the contour plot.
Drawing the boundaries of the nonlinear constraints could be more difficult, depending on what they are. You could, though, evaluate the nonlcon function at each grid location and figure out from the output whether each point is inside the boundary or not, and draw something appropriate on the contour plot.
Roneau
Roneau le 12 Nov 2022
Thank you. I think I understand now.

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 11 Nov 2022
[x, y] = meshgrid(-5:5, -5:5);
z = x.^2 + 10.*y.^2 - 3.*x.*y;
contour(x, y, z)

2 commentaires

Roneau
Roneau le 11 Nov 2022
Thank you for this!
Matt J
Matt J le 12 Nov 2022
@Roneau, you should Accept-click the answer if it addresses your question.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Contour Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by