Mathematica Asked on August 12, 2021
Is there a way to solve below $n$ simultaneous differential equations in Mathematica?
$$ifrac{d}{dt}M_{n}left(tright) =bsqrt{N+3+n}M_{n+1}left(tright)+hsqrt{nleft(2N+5right)}M_{n-1}left(tright)
$$
I also want to plot $M_{n}$.
h,b,N are constants.Range of n is from 0 to N
For small number of ODE's, Mathematica DSolve
solves it, but it takes longer time as more ODE's are added.
ClearAll[t, h, b, r, n];
NN = 2;
odes = Table[
I ToExpression["M" <> ToString[n]]'[t] ==
b Sqrt[NN + 3 + n]*ToExpression["M" <> ToString[n + 1]][t] +
h *Sqrt[n*(2*NN + 5)]*ToExpression["M" <> ToString[n - 1]][t],
{n, 0, NN}
];
deps = Table[ToExpression["M" <> ToString[n]][t], {n, 0, NN}]
Now call DSolve
DSolve[odes, deps, t]
The solution is too long to post. For N=6
you get
Now it will take much longer time to solve it. I did not want to wait for it.
You did not say how big N
is. (btw, N
is reserved, so better use different letter)
Edit
To answers comments. To hope to get a solution that can be plotted, need to supply IC and values for the missing parameters $h,b$ and the last $M(t)$. Here is an example for 3 equations just for illustration.
ClearAll[t, h, b, n, M];
NN = 2;
h = 5; b = 6; (*some made up values*)
odes = Table[
I ToExpression["M" <> ToString[n]]'[t] ==
b Sqrt[NN + 3 + n]*ToExpression["M" <> ToString[n + 1]][t] +
h *Sqrt[n*(2*NN + 5)]*ToExpression["M" <> ToString[n - 1]][t], {n,
0, NN}]
deps = Table[ToExpression["M" <> ToString[n]][t], {n, 0, NN}]
M3[t_] := 2*t; (*some function for the last one, which has no ODE*)
ic = {M0[0] == 1, M1[1] == 2, M2[0] == 2}; (*some IC*)
Now solve the system
DSolve[{odes, ic}, deps, t]
Now the solutions can be plotted. But they are complex. So can plot either the abs or imaginary or real parts. They are complex, since your ODE is complex.
For example
Plot[Re[M0[t] /. sol], {t, 0, 3}]
Plot[Re[M1[t] /. sol], {t, 0, 3}]
etc.
Btw, if IC and other values are available, it will be better to use NDSolve
instead of DSolve
for this. DSolve
takes too long time for large N
.
Correct answer by Nasser on August 12, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP