How to show the Graphical Solution Method for an Optimization Problem

17 visualizaciones (últimos 30 días)
Perry Marvin
Perry Marvin el 2 de Feb. de 2022
Editada: Matt J el 2 de Nov. de 2022
I am atempting to solve an Optimization problem using a graphical approach so that a solution can be observed. I do not need to solve the problem explicitly, but instead create a graph showing the objective function and the constaints placed on the system. I found a MathWorks video outlining how to approach and solve this type of problem. In the video a command is used called "visualizeProblem" which appears to create the graphical solution that I am trying to create. However, when I call this function it displays an error "Unrecognized function or variable 'visualizeProblem'." (A link to the video is attached below for reference.) I cannot find any doccumentation on this function or any potential replacements, and following the video, I believe I have the correct. As follows is my code:
prob = optimproblem;
x = optimvar("x_1","LowerBound",0,"UpperBound",10);
y = optimvar("x_2","LowerBound",0,"UpperBound",10);
prob.Objective = 4*x.^2 * y.^2;
cond1 = x + y <= 8;
cond2 = y <= 4;
cond3 = x >= 0;
cond4 = y >= 0;
prob.Constraints = cond1;
prob.Constraints = cond2;
prob.Constraints = cond3;
prob.Constraints = cond4;
showproblem(prob)
visualizeProblem
And I am atempting to achieve something that looks like this: (Note: This is not the same problem as shown above, this is the example graph from the MathWorks video I am referencing)
Thank you in advance

Respuestas (2)

Matt J
Matt J el 2 de Feb. de 2022
Editada: Matt J el 2 de Feb. de 2022
All I see in the figure is a contour plot of the objective. If that's all you need, you can use fcontour, e.g.,
fcontour(@(x,y) 4*x.^2 .* y.^2,[0,10],'LevelList',0:2:20)
Obviously, you can overaly contours of the constraint functions on this in a similar manner.
  4 comentarios
Perry Marvin
Perry Marvin el 3 de Feb. de 2022
I understand I can plot each individually, but I am asking if there is a way to plot the optimization problem. The code above sets up an optimization problem and the showproblem outputs the objective and the constraints. Is there a simple builtin command that plots that problem
Matt J
Matt J el 3 de Feb. de 2022
Editada: Matt J el 3 de Feb. de 2022
No, there is no built-in command. The visualizeProblem in the video was almost certainly a user-defined script that they forgot to provide. Notice that it didn't take any input arguments that let you specify an optimization problem.

Iniciar sesión para comentar.


Sujoy Barua
Sujoy Barua el 2 de Nov. de 2022
Editada: Matt J el 2 de Nov. de 2022

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by