How to plot the optimal point of an objective function

조회 수: 12 (최근 30일)
Ancy S G
Ancy S G 2022년 3월 1일
편집: Binaya 2024년 1월 18일
I want to maximise the optimization model ∑F with respect to x,y.But this function has different values for two conditions:
F=y*Eb-x*Es+c*(Es-Eb) ; Es≥Eb
F=y*Eb-x*Es+d*(Es-Eb) ; Es<Eb
subject to : c ≤ x , y ≤ d
The parameters are Eb,Es,c & d can choose random variables.
I want to plot the optimal values of this function on graph
  댓글 수: 2
Alan Weiss
Alan Weiss 2022년 3월 1일
I do not understand your question. Do the parameters "choose random variables" before optimization or during optimization? If before, then you can take the values and try to solve the problem. If during, then I have no idea what the problem means.
Alan Weiss
MATLAB mathematical toolbox documentation
jessupj
jessupj 2022년 3월 1일
편집: jessupj 2022년 3월 1일
Also, the question says something about plotting. you have 4 parameters so you need to clarify whether you're trying to plot the optmial point in the 4d parameter space (a 2d function F(x,y | optimal_parameters) ) or the optimal point (x,y) as a function of the parameters.
But as long as i'm making a comment, you can define a single objective funtion:
F= y*Eb-x*Es+( c*(Es>=Eb) + d*(Es<Eb) ) *(Es-Eb)
that might be easier to call from e.g. fmincon subject to the other nonlinear constraints. (And, of course, if you're tring to find a maximum, you'd try to minimize -1*F)

댓글을 달려면 로그인하십시오.

답변 (1개)

Binaya
Binaya 2024년 1월 18일
편집: Binaya 2024년 1월 18일
Hi Ancy
I see that you would like to maximize the optimization model w.r.t. "x" and "y". where "Eb", "Es", "c" and "d" are parameters to the optimization that is fixed before the optimization starts.
You can follow the following steps to maximize the optimization model and plot the optimal values on a graph:
  1. Initialize "Eb", "Es", "c" and "d" to a random value using "rand".
  2. Define the objective function, inequality and equality constraints. Here is an example code:
objectiveFunction = @(vars) -piecewiseObjective(vars, Eb, Es, c, d);
constraintsFunction = @(vars) constraints(vars, c, d);
function F = piecewiseObjective(vars, Eb, Es, c, d)
x = vars(1);
y = vars(2);
if Es >= Eb
F = y * Eb - x * Es + c * (Es - Eb);
else
F = y * Eb - x * Es + d * (Es - Eb);
end
end
function [c, ceq] = constraints(vars, c, d)
x = vars(1);
y = vars(2);
% Inequality constraints (c(x) <= 0)
c = [c - x; y - d];
% No equality constraints
ceq = [];
end
3. Setup the options for optimization model using "optimoptions" according to the requirement.
4. Call the "fmincon" function for optimization using the objective functions, constraints and options defined above.
5. Create a grid of "x" and "y" values using "meshgrid" for plotting.
6. Find the value of the objective function over the mesh grid:
FGrid = arrayfun(@(x, y) piecewiseObjective([x, y], Eb, Es, c, d), xGrid, yGrid);
7. Plot a 3d plot using "xGrid", "yGrid" and "FGrid".
8. Plot the optimum point which is returned by "fmincon" in the existing figure.
Hope this helps

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by