1
$\begingroup$

I'm trying to solve matrix differential equation with DSolve, but I got an error.

L = 1 - t;
f1 = Integrate[1/(1 - u)^2, {u, 0, t}]; 
d = Table[If[k == n, 0, ((k*n)/(k^2 - n^2))*
           Exp[I*Pi^2*(k^2 - n^2)*f1]], {k, 4}, {n, 4}]; 
g = D[L, t]/L; 
B[t_] = {b1[t], b2[t], b3[t], b4[t]}; 


sol = DSolve[B'[t] ==- 2 g d.B[t], B[t], t]

The error :

DSolve::nolist: List encountered within {ConditionalExpression[(b1^\[Prime])[t]==(2 (-(2/3) E^(3 I Power[<<2>>] Power[<<2>>] t) b2[t]-3/8 E^(8 <<3>> t) b3[t]-4/15 E^(15 I <<1>> Power[<<2>>] t) b4[t]))/(1-t),Re[t]<=1||t\[NotElement]\[DoubleStruckCapitalR]],ConditionalExpression[(b2^\[Prime])[t]==(2 (<<1>>))/(1-t),Re[t]<=1||t\[NotElement]\[DoubleStruckCapitalR]],<<21>>[<<1>>==<<1>>,<<1>>],ConditionalExpression[(b4^\[Prime])[t]==(2 (<<1>>))/(1-t),Re[t]<=1||t\[NotElement]\[DoubleStruckCapitalR]]}. There should be no lists on either side of the equations.

I have tried this procedure on solving simpler matrix differential equation of the same format and it worked :

a = {{1, 2}, {3, 4}};
X[t_] = {x1[t], x2[t]};
sol = DSolve[X'[t] == a.X[t], X[t], t]

Output :

{{x1[t] -> -(1/22) E^((5 t)/2 - (Sqrt[33] t)/
      2) (-11 - Sqrt[33] - 11 E^(Sqrt[33] t) + 
       Sqrt[33] E^(Sqrt[33] t)) C[1] + (
    2 E^((5 t)/2 - (Sqrt[33] t)/2) (-1 + E^(Sqrt[33] t)) C[2])/Sqrt[
    33], 
x2[t] -> Sqrt[3/11] E^((5 t)/2 - (Sqrt[33] t)/2) (-1 + E^(Sqrt[33] t)) C[
         1] + 1/22 E^((5 t)/2 - (Sqrt[33] t)/
          2) (11 - Sqrt[33] + 11 E^(Sqrt[33] t) + 
           Sqrt[33] E^(Sqrt[33] t)) C[2]}}
$\endgroup$
1
  • 1
    $\begingroup$ Consider switching away from If (which is really more appropriate for program flow control) to Piecewise or Boole in your conditional definitions. $\endgroup$
    – MarcoB
    Oct 4, 2021 at 14:57

1 Answer 1

4
$\begingroup$

DSolve can't solve the system. It has complex numbers. You can try NDSolve

First we try DSolve

ClearAll[u, t, B, b, k, n];
L = 1 - t;
f1 = Integrate[1/(1 - u)^2, {u, 0, t}, GenerateConditions -> False];
d = Table[
   If[k == n, 0, ((k*n)/(k^2 - n^2))*Exp[I*Pi^2*(k^2 - n^2)*f1]], {k, 
    4}, {n, 4}];
g = D[L, t]/L;
B[t_] := {b1[t], b2[t], b3[t], b4[t]};
odeSys = MapThread[Equal, {B'[t], -2 g d . B[t]}]

Mathematica graphics

Now

sol = DSolve[odeSys, B[t], t]

Returns after few second unevaluated. No errors or warnings generated. It just can't be solved analytically.

Try numerically. But need some IC. So made up some random ones

deps = {b1, b2, b3, b4};
ic = MapThread[Equal, {B[t] /. t -> 0, {0, 1, 0, 1}}]

Mathematica graphics

Now

sol = NDSolve[{odeSys, ic}, deps, {t, 0, .9}]

Mathematica graphics

But solution is complex

 Evaluate[b1[t] /. sol] /. t -> .5

Mathematica graphics

So you can plot the real part and the imaginary part separately

Plot[Evaluate[Im@Evaluate[B[t] /. sol]], {t, 0, .9}]

Mathematica graphics

Plot[Evaluate[Re@Evaluate[B[t] /. sol]], {t, 0, .9}]

Mathematica graphics

Or

 Plot[Evaluate[Abs@Evaluate[B[t] /. sol]], {t, 0, .9}]

Mathematica graphics

or can use ReImPlot

ReImPlot[Evaluate[Evaluate[B[t] /. sol]], {t, 0, .9}, 
 PlotLegends -> deps]

Mathematica graphics

$\endgroup$
4
  • $\begingroup$ Thanks a lot man! 1 question, what is the significance of deps? I tried replacing all the deps with B[t] as saw no difference. $\endgroup$ Oct 5, 2021 at 5:36
  • $\begingroup$ Oh and 1 more thing. If B[t] contains a lot of elements (e.g. 100), is there a quick way to write its elements instead of writing B[t_]={b1[t],b2[t],b3[t],....}? $\endgroup$ Oct 5, 2021 at 5:43
  • 1
    $\begingroup$ @ForacleFunacle ` what is the significance of deps` normally for NDSolve it is better to use just b instead of b[t] for the dependent variable. It makes things little easier to post process. But both will work. For DSolve I use b[t] and not b. See help on NDSolve. This is how they do the examples. So deps was just a lazy way remove the t, that is all. $\endgroup$
    – Nasser
    Oct 5, 2021 at 5:58
  • 1
    $\begingroup$ @ForacleFunacle If B[t] contains a lot of elements (e.g. 100), is there a quick way to write its elements you can try B[t_] = Table[ToExpression["b" <> ToString[n] <> "[t]"], {n, 100}] $\endgroup$
    – Nasser
    Oct 5, 2021 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.