Nonlinear optimization with differential equations in Constraint

Hello, I have a nonlinear optimization problem like min f(X), where X is a vector of four elements. And the constraints are in the form of dX/dt=g(X,u), where u is the decision variable and it is defined by: u=h(X). I tried to use fmincon and ode23 together, however, I do not know what to do with u=h(X) as the constraint. If I want to define that as a nonlinear constraint in fmincon, how to define the function as X is not still known. Thank you.

답변 (2개)

Nikhil Negi
Nikhil Negi 2018년 5월 18일

1 개 추천

i can think of two ways you can try both try replacing the dX/dt = g(X,u) with dX/dt = g(X,h(X)) so eventually you have dX/dt = p(X) and then continue with how you did it.
or you can define u as a separate function and pass it as a parameter when calculating dX/dt.

댓글 수: 4

Thanks Nikhil for your reply. I tried to define all the equations based on X, and make X the decision variable of fmincon instead of u. But, I still cannot get an accurate result. Here is the main body of my code (the simple version):
x0 = [0.1,0,-0.0002,0];
alpha=2;
x=zeros(N,4);
for ct1 = 0:Ts:Duration
options = optimoptions('fmincon','Algorithm','sqp','Display','none');
COSTFUN = @(x) MyobjFunction(u,x,x0) ;
nonlcon = []; lb=[]; ub=[];
x = fmincon(COSTFUN,x,[],[],[],[],lb,ub,nonlcon,options);
u=-alpha*x(:,2);
end
function costtot = MyobjFunction(u,x,x0)
x00=x0;
for k=1:N
tspan=[ct1+(k-1)*Ts ct1+k*Ts];
[~, x] = ode23(@(t,x) derivative(u,x),tspan, x00);
cost(k) =0.5*J1*(x(end,2)^2)+0.5*J2*(x(end,4)^2);
costtot=costtot+cost(k);
x00=[x(end,1),x(end,2),x(end,3),x(end,4)];
end
end
function dx = derivative(u,x)
dx = zeros(4,1);
dx(1)=x(2);
dx(2)=(xref1/J1)-((E*V)/(J1*X12))*sin(x(1)-x(3))-(-alpha*x(2))/J1;
dx(3)=x(4);
dx(4)=(xref2/J2)-((E*V)/(J2*X12))*sin(x(3)-x(1));
end
hello sareh, can you provide the mathematical equations also. that would be really helpful
Nikhil Negi
Nikhil Negi 2018년 5월 21일
편집: Nikhil Negi 2018년 5월 21일
i don't think your x0 is getting updated to x00=[x(end,1),x(end,2),x(end,3),x(end,4)] should it get updated for the next window of time?? i'm not really familiar with model predictive control but from your code it seems like you want it to get updated.
Thank you Nikhil for your help. x00 and x is getting updated in MyobjFunction, but the problem is the results of x is not returned to the main program. So, what I get for both x and u is just zero.

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

Sareh Agheb
Sareh Agheb 2018년 5월 21일
편집: Sareh Agheb 2018년 5월 21일

1 개 추천

Hello Nikhil. I am going to apply Model Predictive Control on the above optimization problem. So, the objective should be minimized over the control time horizon. U is the control input and x is the states. Since, I am using a feedback control, u=-kx2. u is a vector of N by 1, and x is a matrix of N by 4, where N is the prediction horizon.

댓글 수: 1

Hello Sareh, were you able to solve this problem? I am trying to solve an optimization problem similar to yours, and I am having a similar problem. I am unable to find any answer.

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

카테고리

도움말 센터File Exchange에서 Nonlinear Control에 대해 자세히 알아보기

질문:

2018년 5월 18일

댓글:

2020년 9월 26일

Community Treasure Hunt

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

Start Hunting!

Translated by