This is an ODE, I want to plot P
on x-axis and vars
on y-axis. My code works fine but gives an empty plot
Subscript[V, 0] = -2.5;
Subscript[k, 0] = Pi/2;
\[Epsilon] = 0.05;
n = 10;
B = Sqrt[3];
Subscript[t, fin] = 25;
A = Table[Subscript[V, i], {i, n}];
For[j = 1, j < n + 1, j++, A[[j]] = 0];
A[[n/2]] = Subscript[V, 0]*(1 + \[Epsilon]);
A[[n/2 + 1]] = Subscript[V, 0]*(1 - \[Epsilon]);
P = Table[Subscript[\[Alpha], i], {i, n}];
For[j = 1, j < n + 1, j++, P[[j]] = 0];
P[[n/2]] = 1; P[[n/2 + 1]] = 1;
Subscript[\[Phi], 0][t_] := Subscript[\[Phi], 1][t];
Subscript[\[Phi], n + 1][t_] := Subscript[\[Phi], n][t];
eqns = Table[{Sqrt[-1]*Subscript[\[Phi], i]'[t] ==
A[[i]]*Subscript[\[Phi], i][t] - Subscript[\[Phi], i + 1][t] -
Subscript[\[Phi], i - 1][
t] + (P[[i]]*Abs[Subscript[\[Phi], i][t]]^2*
Subscript[\[Phi], i][t]), Subscript[\[Phi], i][0] == B}, {i,
n}];
vars = Table[
Sum[Abs[\[Phi][i, Subscript[t, fin]]]^2, {i, n/2 + 2, n}], {i,
25}]/Table[Sum[Abs[\[Phi][i, 0]]^2, {i, n/2 - 1}], {i, 25}];
sol = NDSolve[eqns, vars, {t, 0, 25},
Method -> {"ExplicitRungeKutta", "StiffnessTest" -> False},
MaxSteps -> \[Infinity], AccuracyGoal -> 8, PrecisionGoal -> 8];
Plot=ListPlot[Table[vars /. First[%], {t, 0, 250}],
PlotRange -> All, ImageSize -> 400]
with vars
explicitly given by vars
$=\frac{\sum_{n>\frac{M}{2}+1}|\phi_n(t_{fin})|^2}{\sum_{n<\frac{M}{2}}|\phi_n(0)|^2}$
vars
beceause is nonsense ? $\endgroup$P
. did I make a mistake in writing it appropriately you mean? $\endgroup$vars = Table[Subscript[\[Phi], i][t], {i, 0, n}];Plot[Evaluate[vars /. sol // ReIm], {t, 0, 25}, PlotRange -> All, ImageSize -> 400, PlotLegends -> Table[\[Phi][i][t], {i, 0, n}]]
? $\endgroup$vars
=$\frac{\sum_{n>\frac{M}{2}+1}|\phi_n(t_{fin})|^2}{\sum_{n<\frac{M}{2}}|\phi_n(0)|^2}$ $\endgroup$Subscript[\[Phi], 6][t]
were as your variables look like(Abs[\[Phi][7, 25]]^2) +...
. Your main problem is due to the use of subscripted variables! $\endgroup$