How can I use fmincon objective function with different inputs and ODE
Show older comments
Hi,
I am new at optimization on Matlab and need help about how to use fmincon. I know fmincon can find min x at f(x) but I have a little bit different problem to solve.
My code is below. I defined one array with two variable for fmincon (points). The thing that I want fmincon to do is by changing points in given internal find the minimum objective function.
Something is wrong and it gives the initial points as a solution and this message.
Local minimum found that satisfies the constraints.
Optimization completed because the objective function is non-decreasing in
feasible directions, to within the default value of the function tolerance,
and constraints are satisfied to within the default value of the constraint tolerance.
<stopping criteria details>
No active inequalities.
Maybe I could not explain what I mean. If you are confused please let me know so I can add new explanations :)
Thank you,
%------ main.m ------------------------------
global point_1 point_2
options = optimset('Algorithm','sqp');
A = [-1 0;0 -1;1 1];
b = [-900;-1500;8000];
points_initial = [1000;2000];
[points,feval] = fmincon(@ode_fun,points_initial,A,b);
%-----------------------------------------------------
%-----------------------------------------------------
function obj = ode_fun(points)
initial_condition = [0;1];
tspan = 0:0.1:180;
global point_1 point_2
point_1 = points(1);
point_2 = points(2);
[t,X] = ode45(@train_model,tspan,initial_condition);
obj = obj_fun_calc(t,X(:,2),X(:,1));
return
%------------------------------------------------------
function dx_dt= ode_model(t,x)
global point_1 point_2
if var1 < point_1
dx_dt= [...;...];
elseif (point_1 < var1)&&(var1 <= point_2)
dx_dt= [...;...];
elseif (point_2 < var1)&&(var1 <= point_3)
dx_dt= [...;...];
else
dx_dt= [...;...];
end
%-----------------------------------------------
function system = obj_fun_calc(t,x2,x1);
for i=1:length(t)
global point_1 point_2
if x2(i) <= point_1
sys(i) = ...;
elseif (point_1 < x2(i)) && (x2(i) <= point_2)
sys(i) = ...;
elseif (point_2 < x2(i)) && (x2(i) <= point_3)
sys(i) = 0.01;
else
sys(i) = 0.01;
end
system(i) = sys(i)*1500;
end
Accepted Answer
More Answers (0)
Categories
Find more on Solver Outputs and Iterative Display 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!