1
$\begingroup$

I did program where I solved a system when I organized in matrix form, this is the code

Clear["Global`*"]

SeedRandom[1234]

Nmax = 5; (*Number of sites*)

tini = 0; (*initial time*)

tmax = 200; (*maximal time*)

\[Sigma]2 = 0; (*Variance*)

n0 = 5; (*initial condition*)

ra = 1; (*coupling range*)

\[Psi]ini = Table[KroneckerDelta[n0 - i], {i, 1, Nmax}];

RR = RandomReal[{-Sqrt[3*\[Sigma]2], Sqrt[3*\[Sigma]2]}, Nmax];

Z = Table[
    Sum[KroneckerDelta[i - j + k], {k, 1, ra}] + 
     Sum[KroneckerDelta[i - j - k], {k, 1, ra}], {i, 1, Nmax}, {j, 1, 
     Nmax}] + DiagonalMatrix[RR];

Clear[\[Psi]]

usol = NDSolveValue[{I D[\[Psi][t], t] == 
    Z.\[Psi][t], \[Psi][0] == \[Psi]ini}, \[Psi], {t, tini, tmax}]

Plot[usol[t], {t, tini, tmax}]

Now, I´m trying to solve the same system but writing the equations

Clear["Global`*"]

tini = 0;

tmax = 200;

usol = NDSolveValue[{I x1'[t] == x2[t], I x2'[t] == x1[t] + x3[t], 
    I x3'[t] == x2[t] + x4[t], I x4'[t] == x3[t] + x5[t], 
    I x5'[t] == x4[t], x1[0] == 0, x2[0] == 0, x3[0] == 0, x4[0] == 0,
     x5[0] == 1}, {x1, x2, x3, x4, x5}, {t, tini, tmax}];

Plot[usol[t], {t, tini, tmax}]

Why the second code doesn´t give me the same result if I write the same system?

$\endgroup$
2
$\begingroup$

In the first case, usol is a five-dimensional InterpolatingFunction: enter image description here

In the second case, usol is a list of five InterpolatingFunctions: enter image description here

You can plot them using Through:

Plot[Through[usol[t]], {t, tini, tmax}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks @Chris K, you solved my doubt $\endgroup$ May 22 at 15:56

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.