Filter löschen
Filter löschen

how to constraint the input variables of ode45 with the odeset function (nonnegative option)

9 Ansichten (letzte 30 Tage)
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
Can I solve this problem with the odeset function (nonnegative option), and how ??
Thanks

Antworten (1)

Torsten
Torsten am 9 Apr. 2015
You can't limit the solution of an ODE.
Once you have defined the ODE and given its initial conditions, the solution over your interval of integration [0:20] is entirely determined.
So the only thing you can do is to vary the initial conditions to satisfy your constraints.
Best wishes
Torsten.
  2 Kommentare
yosra welhazi
yosra welhazi am 9 Apr. 2015
Can I solve this problem with the odeset function (nonnegative option)
Torsten
Torsten am 9 Apr. 2015
The nonnegative option is a tool that helps to keep the solution of your ODE system positive if you know that the solution of the ODE system is positive.
So if e.g. you solve the ODE
y'(x)=-1, y(0)=0
with solution y(x)=-x and you activate the nonnegative option, the solver will fail.
I guess this is true for your problem - the solution exceeds the limits you want to impose by
-2<=x(1)<=2
-1<=x(2)<=1
So constraining the solution cannot be successful.
Best wishes
Torsten.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by