TransWikia.com

Solving 4 coupled linear 1st order ODE with constant coefficients

Mathematica Asked by KarryMa on December 6, 2020

I’m getting trouble solving these 4 coupled differential equations, just can’t get a result while it keep running.
enter image description here

eqs = 
{
A1'[t] ==  I (μ0 - 2*g) A1[t] - I g0 (B1[t] + C1[t]), 
B1'[t] == -I (g0 (2 + n) A1[t] + Ω C1[t] + g0 D1[t]), 
C1'[t] == -I (g0 (2 + n) A1[t] + Ω B1[t] + g0 D1[t]), 
D1'[t] == -I g0 (1 + n) (B1[t] + C1[t]) - I (μ0 - 2 g) D1[t], 
A1[0] == 0, B1[0] == 0, C1[0] == 0, D1[0] == 1
};
dusol = DSolve[eqs, {A1, B1, C1, D1}, t][[1]] // FullSimplify

One Answer

I've found 3 work-arounds.

First one is to make use of the ConstantsGrouping` package:

head = {A1, B1, C1, D1};
var = Through@head@t;

{newrhs, rule} = GroupConstants[eqs[[;; 4, -1]], {t, var} // Flatten]

lhs = eqs[[;; 4, 1]]

solmid = DSolve[{lhs == newrhs // Thread, eqs[[5 ;;]]}, head, t]; // AbsoluteTiming
(* {12.4674, Null} *)

sol = var /. solmid[[1]] /. rule;

Second one is based on LaplaceTransform:

teqs = LaplaceTransform[eqs[[;; 4]], t, s] /. Rule @@@ eqs[[5 ;;]]

tsol = Solve[teqs, LaplaceTransform[var, t, s]][[1, All, -1]]

sol2 = InverseLaplaceTransform[tsol, s, t]; // AbsoluteTiming
(* {0.968162, Null} *) 

Last, and the fastest one is to utilize MatrixExp:

{barray, marray} = CoefficientArrays[eqs[[;; 4, -1]], var];

sol3 = MatrixExp[marray t, eqs[[5 ;;, -1]]]; // AbsoluteTiming
(* {0.458083, Null} *)

Correct answer by xzczd on December 6, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP