52 views (last 30 days)

Show older comments

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

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

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?

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

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

Start Hunting!