How to show the Graphical Solution Method for an Optimization Problem
Show older comments
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)

The video can be found here: https://www.mathworks.com/videos/part-4-problem-based-nonlinear-programming-1549458887351.html
Thank you in advance
1 Comment
Sujoy Barua
on 2 Nov 2022
https://www.mathworks.com/help/optim/ug/optimization-toolbox-tutorial.html
Answers (2)
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.
Sujoy Barua
on 2 Nov 2022
Edited: Matt J
on 2 Nov 2022
0 votes
Categories
Find more on Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!