Solving matrix differential equation

2 views (last 30 days)
Hi I want to solve a 2x2 matrix differential equation, how do I go by it?
this is what i currently have
syms x1 x2
Dx1 = diff(x1);
Dx2 = diff(x2);
A = [22.2 -6.2; -9.8 9.8];
ode = diff(x1,x2,2) == A*[x1;x2]
ode = 
cond1 = x1(0) == 0;
Array indices must be positive integers or logical values.

Error in indexing (line 956)
R_tilde = builtin('subsref',L_tilde,Idx);
cond2 = Dx1(0) == 0;
cond3 = x2(0) == 1;
cond4 = Dx2(0) == 0;
conds = [cond1 cond2 cond3 cond4];
ySol(t) = dsolve(ode,conds);
ySol = simplify(ySol);
A is a matrix [22.2 -6.2; -9.8 9.8]

Accepted Answer

Walter Roberson
Walter Roberson on 15 Feb 2025
You try to take the derivative of x1 with respect to x2. You cannot meaningfully take the derivative of a function with respect to a different function.
If you try to define x1 as a function of x2 then you are going to end up with a function of more than one variable, which would be a PDE rather than an ODE.
syms x1(t) x2(t)
Dx1 = diff(x1);
Dx2 = diff(x2);
A = [22.2 -6.2; -9.8 9.8];
ode = diff(x1,x2,2) == A*[x1;x2]
ode(t) = 
cond1 = x1(0) == 0;
cond2 = Dx1(0) == 0;
cond3 = x2(0) == 1;
cond4 = Dx2(0) == 0;
conds = [cond1 cond2 cond3 cond4];
ySol = dsolve(ode,conds)
ySol = struct with fields:
x2: 0 x1: 0
  2 Comments
Walter Roberson
Walter Roberson on 15 Feb 2025
Guessing at what you really want:
syms x1(t) x2(t)
Dx1 = diff(x1);
Dx2 = diff(x2);
A = [22.2 -6.2; -9.8 9.8];
ode = diff([x1;x2],2) == A*[x1;x2]
ode(t) = 
cond1 = x1(0) == 0;
cond2 = Dx1(0) == 0;
cond3 = x2(0) == 1;
cond4 = Dx2(0) == 0;
conds = [cond1 cond2 cond3 cond4];
ySol = dsolve(ode, conds)
ySol = struct with fields:
x2: exp(-t*(16 - (4*155^(1/2))/5)^(1/2))*((10*(16 - (4*155^(1/2))/5)^(1/2))/49 - (5*(16 - (4*155^(1/2))/5)^(3/2))/784)*((155^(1/2)*(16 - (4*155^(1/2))/5)^(1/2))/80 - (155^(... x1: exp(-t*(16 - (4*155^(1/2))/5)^(1/2))*((5*(16 - (4*155^(1/2))/5)^(1/2))/49 - (5*(16 - (4*155^(1/2))/5)^(3/2))/784)*((155^(1/2)*(16 - (4*155^(1/2))/5)^(1/2))/80 - (155^(1...
ySol = simplify([ySol.x1; ySol.x2])
ySol = 

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!