Nonlinear constraint on optimization using ODE - system state involved
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I need to incorporate a nonlinear constraint on my optimization problem but there is a ODE involved. The constraint involves a system state so that is why I am having some difficulty in incorporating it. I do not know if it can be done.
It is easy to write some constraint that depends only on the paramaters themselves or values that are available at t = 0 (e.g., initial conditions) but I do not know a priori the values of the states. So, adapting one MATLAB example from https://nl.mathworks.com/help/matlab/ref/ode23s.html let us say I am trying to optimize the two parameters in the vector p inside that ODE but some some reason I want to limit y(2) to a maximum value during optimization. Can someone help on this generic example?
tspan = [0 5];
y0 = [0 0.01];
function SSE = fobj(p,tspan,y0)
[t,y] = ode23s(@(t,y) odefcn(t,y,p), tspan, y0);
...
SSE = sum((y - yexp).^2); % let us say we have some experimental data to define a sum of squared errors
end
function dydt = ode_example(t,y,p)
dydt = zeros(2,1);
dydt(1) = y(2);
dydt(2) = p(1)*t.*y(1)+p(2);
end
function [c] = nlincon(y,p,max_value)
c = y(2)-max_value; % ?? how do I access the value of y(2) at all times outside the ODE function itself?
end
0 个评论
采纳的回答
Torsten
2022-8-9
I guess you have a time vector for which you have your data vector of measurements "yexp" ?
In nlincon, with these measurement times as tspan and with the actual parameter vector p, call the ODE function and define the vector c of size tspan as
c = y(:,2) - max_value
So defining tspan as [0 5] is not suitable. tspan should exactly contain the times at which "yexp" was measured.
7 个评论
Torsten
2022-8-10
Maybe MATLAB support can tell you more about order and frequency of calls to the input functions of fmincon in order to save computation time in your case.
I cannot.
Torsten
2022-8-15
There was a similar question with the following answer given:
https://de.mathworks.com/help/optim/ug/objective-and-nonlinear-constraints-in-the-same-function.html
Hope it helps.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!