I have a coupled first order system of differential equations which I'm solving numerically (my actual system is more complicated so I use this simple example). I'm trying to plot the solutions for different values of $n$ on one graph:
sol = Table[{n,
NDSolve[{y'[x] + n z[x] == 0, z'[x] - n y[x] == 0, y[0] == 1,
z[0] == 1}, {y, z}, {x, 0, 1}]}, {n, 1, 2}]
Plot[Evaluate[y[x] /. sol[[1]][[2]]], {x, 0, 1}, PlotRange -> All]
Plot[Evaluate[y[x] /. sol[[2]][[2]]], {x, 0, 1}, PlotRange -> All]
Plot[Table[Evaluate[y[x] /. sol[[n]][[2]]], {n, 1, 2}], {x, 0, 1},
PlotRange -> All]
The last line doing this gives me an error "Part::pkspec1: The expression n cannot be used as a part specification." However I can still plot solutions for different $n$s on different graphs, as illustrated by running the previous two lines. What is going wrong and how do I fix it?
Thanks in advance for any help.
Dimensions[sol[[1]][[2]]]
. You can change the last replacement toy[x] /. sol[[n]][[2]]][[1]]
. $\endgroup$