How to show the Graphical Solution Method for an Optimization Problem

17 Ansichten (letzte 30 Tage)
Perry Marvin
Perry Marvin am 2 Feb. 2022
Bearbeitet: Matt J am 2 Nov. 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

Antworten (2)

Matt J
Matt J am 2 Feb. 2022
Bearbeitet: Matt J am 2 Feb. 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 Kommentare
Perry Marvin
Perry Marvin am 3 Feb. 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 am 3 Feb. 2022
Bearbeitet: Matt J am 3 Feb. 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.

Melden Sie sich an, um zu kommentieren.


Sujoy Barua
Sujoy Barua am 2 Nov. 2022
Bearbeitet: Matt J am 2 Nov. 2022

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by