Solving two systems of DEs using the ode45 function.

13 Ansichten (letzte 30 Tage)
Vassil Botev
Vassil Botev am 22 Jul. 2014
Kommentiert: Vassil Botev am 23 Jul. 2014
I am trying to solve two systems of differential equations in variables x1, x2, x3 using the ode45 function. The equations are given below:
dx1=-2*lambda*beta*x1+2*lambda*alpha*x2+lambda^2*sigma^2;
dx2=beta*x1-(alpha+lambda*beta)*x2+lambda*alpha*x3;
dx3=2*beta*x2-2*alpha*x3;
where alpha=alpha0+alpha1*t and beta=beta0+beta1*t and alpha0, alpha1, beta0, beta1, sigma, lambda are known constants.
The values I am trying to find are X1, X2 and X3. The derivatives of these desired values are given by:
dX1=beta*x1;
dX2=alpha*x2;
dX3=x3;
I am having difficulties implementing the above using the ode45 function given that the problem is defined by two sets of simultaneous differential equations. Any suggestions as to how this can be solved would be much appreciated. Thanks.

Akzeptierte Antwort

Mischa Kim
Mischa Kim am 23 Jul. 2014
Vassil, check out
function my_ode()
alpha0 = 1;
alpha1 = 1;
beta0 = 1;
beta1 = 1;
lambda = 1;
sigma = 1;
param = [alpha0; alpha1; beta0; beta1; lambda; sigma];
[t,X] = ode45(@EOM,[0 5],[1 2 3 4 5 6],[],param);
plot(t,X(:,1))
grid
end
function dX = EOM(t,x,param)
x1 = x(1);
x2 = x(2);
x3 = x(3);
alpha0 = param(1);
alpha1 = param(2);
beta0 = param(3);
beta1 = param(4);
lambda = param(5);
sigma = param(6);
alpha = alpha0+alpha1*t;
beta = beta0+beta1*t;
dx1 = -2*lambda*beta*x1+2*lambda*alpha*x2+lambda^2*sigma^2;
dx2 = beta*x1-(alpha+lambda*beta)*x2+lambda*alpha*x3;
dx3 = 2*beta*x2-2*alpha*x3;
dX1 = beta*x1;
dX2 = alpha*x2;
dX3 = x3;
dX = [dx1; dx2; dx3; dX1; dX2; dX3];
end

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by