# differential equations – How to obtain the same result of the same system if I write the system in different ways (NDSolve)?

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?

Posted on Categories Articles