필터 지우기
필터 지우기

How can I limit the state variables of ODE to upper and lower limits ?

조회 수: 18 (최근 30일)
yosra welhazi
yosra welhazi 2015년 3월 25일
답변: Jan 2015년 4월 5일
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

답변 (1개)

Jan
Jan 2015년 4월 5일
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.

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by