using control constraints in ode45

11 views (last 30 days)
I need to use ode45 to solve a system of simultaneous differential equations that must meet a constraint on a function of a couple of its variables (this is part of a control system on which there is a control constraint). I can’t find any help documentation that provides for this situation so I assume that it can be done manually. This means that I need to check the value of an expression that is a function of a portion of the solution vector at every time and step, and if it exceeds a constraint, I’ll need to recalculate that particular time step of the numerical integral. Without understanding the nuances of the underlying computations in ode45 it’s hard to tell how I should do that. Anyone know how?
Could I just rewrite the new system after checking the condition and ode45 will handle it correctly?
For example:
%the original system
%epsilon is a constant and ms and bs are computed before the following
dydt(1) = y(2);
u = -(2*epsilon^2*ms'*bs*y(2)^2+y(4))/(2*epsilon^2*ms'*ms);
dydt(2) = u;
dydt(3) = 0;
dydt(4) = -4*epsilon^2*(bs'*bs*y(2)^3+ms'*bs*y(2)*(-(2*epsilon^2*ms'*bs*y(2)^2+y(4))/(2*epsilon^2*ms'*ms)))-y(3);
%check for violation of constraint
u=f(y(1),y(2),y(3)
If (u >= constant)
u=constant
% constraint is violated, solve new system with constraint
dydt(1) = y(2);
dydt(2) = u;
dydt(3) = 0;
dydt(4) = -4*epsilon^2*(bs'*bs*y(2)^3+ms'*bs*y(2)*(-
(2*epsilon^2*ms'*bs*y(2)^2+y(4))/(2*epsilon^2*ms'*ms)))-y(3);
end
Basically what I need to know is how to make ode45 reiterate a step and use a different set of equations. There must be someway to impose constraints like this, maybe I missed it in the help files….
My question is similar to what someone is trying to do here: ( http://www.mathworks.com/matlabcentral/answers/14164-using-saturated-inputs-in-ode45), they have implemented the constraint before the set of differential equations which I think is incorrect due to the fact that his control inputs should be a function of the current states, not the ones from the last state….
Can anyone help me please?
Thanks,
Kyle Stanhouse
  4 Comments
Walter Roberson
Walter Roberson on 16 Jan 2012
http://www.mathworks.com/matlabcentral/answers/help/markup
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
yosra welhazi
yosra welhazi on 9 Apr 2015
Dear friend;
I have the same problem as you and when I simulate and plot my control inputs, they are not saturated , what can I do please

Sign in to comment.

Accepted Answer

Matt Tearle
Matt Tearle on 16 Jan 2012
I must be missing something subtle. It looks like your equations are essentially
dydt(1) = y(2);
if (f(y(1),(2),y(3)) < constant)
dydt(2) = -(2*epsilon^2...
else
dydt(2) = constant;
end
dydt(3) = 0;
dydt(4) = -4*epsilon...
Can you explain what I'm missing?
  3 Comments
Matt Tearle
Matt Tearle on 17 Jan 2012
ode45 calls your rate equation function at a given time with given values of y (at that time). No update is done to y until this function returns dy/dt. Once it returns dy/dt, ode45, like any RK method, projects forward, updating t and y, and reevaluates dy/dt for the new values of (t,y). So unless your constraint is based on what the values of y *will be* at some point in the future, you should be fine. (And it it does... yikes. That's going to be a nightmare to code, although perhaps you could frame it as a delay differential equation.)
To put it another way, this function knows nothing of past or future values of y. All it knows is the here and now. So everything that happens during a given function call is all at one moment in time.
Hope that helps.
ode45: the ultimate Buddhist :)
yosra welhazi
yosra welhazi on 9 Apr 2015
Dear friend;
I have the same problem as you and when I simulate and plot my control inputs, they are not saturated , what can I do please ? please help me

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!