Solving matrix differential equation

조회 수: 2 (최근 30일)
Ibraheem
Ibraheem 2025년 2월 15일
댓글: Ibraheem 2025년 2월 15일
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]

채택된 답변

Walter Roberson
Walter Roberson 2025년 2월 15일
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
Walter Roberson
Walter Roberson 2025년 2월 15일
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 = 
Ibraheem
Ibraheem 2025년 2월 15일
Thanks

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by