How to add a restriction in fmincon with external parameters and a variable state of ODE?
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi, folkes!
Let me take the example available in https://es.mathworks.com/matlabcentral/answers/135277-how-to-solve-differential-equations-with-parameters-using-fmincon-to-find-out-optimized-parameters by Jason Nicholson.
The main program:
ab0 = [1; 1]; % initial guess
A = [ 1 0; % a<100
-1 0; % a>0
0 1; % b<22
0 -1];% b>0
b = [100*(1-eps); % a<100
0-eps; % a>0
22*(1-eps); % b<22
0-eps]; % b>0
ab = fmincon(@objectiveFunction, ab0, A, b);
a = ab(1);
b = ab(2);
The derivate function:
function df = derivative(x, f, ab)
a = ab(1);
b = ab(2);
df = zeros(3,1);
df(1)=3*a/b*f(2)*f(1)+16*(f(3)-f(1));
df(2)=-3*a/b*f(2)*f(1)+(f(3)-f(1));
df(3)= 5*a/b*f(1)+(f(2)+f(3));
end % end function, derivative
and, finally, the objetive function:
function cost = objectiveFunction(ab)
f0 = [1;1;1];
[~, f] = ode113(@(t,f) derivative(t, f, ab), [0 1], f0);
cost = f(2, end) + f(1, end) - 0.576;
end % end function, objectiveFunction
I see this program calculates the values of a and b that minimise cost subject to some restrictions.
The question is: how could I add a new restriction condition related to a state variable f?
I appreciate your help! Greetings!
댓글 수: 0
답변 (1개)
Walter Roberson
2017년 10월 17일
For linear inequality restrictions, you would add to A and b. For linear equality restrictions, you would add new parameters, Aeq and beq after A and b. For upper and lower bounds, you would add lb and ub parameters after Aeq and beq (leaving Aeq and beq as [] if you have no equality constraints).
For non-linear restrictions, you would add a function or anonymous function that took t and y as input, and returned the nonlinear inequality "values are in range" conditions as the first output, and the nonlinear equality "values are in range" conditions as the second output (both must be returned, return [] if need be), and you would put those after lb and ub (putting in [] for those if you need to.) If you have nonlinear constraints that you need extra values to calculate, then http://www.mathworks.com/help/matlab/math/parameterizing-functions.html parameterize the function.
댓글 수: 2
Walter Roberson
2017년 10월 17일
If a derivative being calculated through an ode*() call needs to have restrictions put on it, then the way to do that is to add an event function to the ode options. See https://www.mathworks.com/help/matlab/math/ode-event-location.html
참고 항목
카테고리
Help Center 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!