How can I limit the state variables of ODE to upper and lower limits ?
18 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Dear friends; I have the differential equations given as follows:
x1'=x1*(1-x2^2)-x2
x2'=x1
I have created an m-file which contains these differential equations and I have constrained the variables x1 and x2 to their upper and lower limits (-limit and +limit)
function xdot=fun(t,x)
limit1=2;
limit2=1;
if (abs(x(1))>limit1)
x(1)=sign(x(1))*limit1;
end
if (abs(x(2))>limit2)
x(2)=sign(x(2))*limit2;
end
xdot=zeros(2,1);
xdot(1)=x(1)*(1-x(2)^2)-x(2);
xdot(2)=x(1);
end
then I have simulated the differential equation defined in the function fun over the interval 0<=t<=20;
x0=[0;0.25];
[t,x]=ode45('fun',[0:0.01:20],x0);
plot(t,x)
My problem consists in how to limit the state variable x because I have the condition
-2<=x(1)<=2
-1<=x(2)<=1
So, how can I simulate the differential equation over the interval 0<=t<=20 with satisfying this condition, I will be very grateful if someone can help me, because I have tried but it not works
Thanks
0 commentaires
Réponses (1)
Jan
le 5 Avr 2015
If you do this without event functions and a restart of the integration, you try to integrate a non-smooth function. This collides with the specifications of standard ODE functions such that the results has eitehr an extremely poor accuracy or the integration might even stop. See http://www.mathworks.com/matlabcentral/answers/59582#answer_72047 .
Event functions are the only reliable solution: Detect the limit, stop the integration, change the function to be integrated and restart the ODE solver.
0 commentaires
Voir également
Catégories
En savoir plus sur Ordinary Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!