Using this technique from Simon, I want to solve a matrix differential equation with a matrix that contains an explicit time-dependence(our variable), but I want to be able to solve this problem for a generic number of functions K+1
thus auto-indexing them. My code, stripped of a few things which don't seem to be the problem, (with I= imaginary unit):
K=2;
dl = ConstantArray[ 1/2 Exp[-I t], K]; %defining M
dm = Array[(# - 1)^2 &, K + 1];
dr = ConstantArray[1/2 Exp[I t], K];
M = SparseArray[{Band[{1, 2}] -> dr, Band[{1, 1}] -> dm,
Band[{2, 1}] -> dl}] // Normal
a[t_] := Table[g[k][t], {k, 0, K}] %defining a as a list of functions g
NDSolve[{a'[t] == I *M.a[t], g[0][0] == 0, g[1][0] == 1, g[2][0] == 0}, {g[0], g[1], g[2]}, {t, 0, 10}][[1, All, 2]] //Abs
%solving the diff. eq.
Which returns a list of three InterpolatingFunctions with output scalar as I would expect. However,
Plot[%,{t,0,10}]
Only draws axes without any graphs. But I solved these equations for K=2 beforehands in another way(but still with DSolve) and saw some results which should also be shown the domain of this graph, but are missing. Similarly, function evaluation for a random value of t
%%[1]
Doesn't give a number either.
My intention when this works for a generic K is add a manipulate to change some parameters I put equal to one now and make the whole thing a function of K.
(*comments look like this in Mathematica*)
, single line comments aren't really used. The answer here provides some discussion on the topic. $\endgroup$ – dionys Oct 22 '15 at 13:40