From solving n times a numerical (complex) equation, like:
n = 10;
eq = Range[n];
For[a = 1, a < (n + 1), a++,
eq[[a]] =
NDSolve[{y''[x] + a*y[x] == 0, y[0] == 1 + I, y'[0] == 1 + 0 I},
y, {x, 0, 30}]]
I get the (complex) n solutions in the variable value:
value = Range[n];
For[a = 1, a < (n + 1), a++,
value[[a]] =
With[{exp = Through[({y} /. First[eq[[a]]])[#]]}, exp &]];
Which is a list of 10 complex interpolating functions. I can plot the real and imaginary parts of each element of value with no problem.
Now, I'm interested in working with the squared modulus of value, i.e. its squared real part plus its squared imaginary part. I'm trying to define two new variables as the real and imaginary parts of value:
valuereal = Range[n];
valueim = Range[n];
For[a = 1, a < (n + 1), a++,
valuereal[[a]] =
Re[value[[a]]]];
For[a = 1, a < (n + 1), a++,
valueim[[a]] =
Im[value[[a]]]];
But it seems that I can't plot these new variables (maybe I can't define the real/imaginary parts in this way?). How can I work correctly with the real/imaginary part of value (an complex interpolating function)?
Question: How can work with the real/imaginary parts of an complex Interpolating function?
Note: I tried to work with:
Abs[value[[a]]]
But I had the same problem.
I'd appreciate all kind of answers a lot.
For. UseTableinstead. Something likef[a_] := NDSolve[{y''[x] + a*y[x] == 0, y[0] == 1 + I, y'[0] == 1 + 0 I}, y, {x, 0, 30}]; eq = Table[f[a], {a, 1, n}];– Nasser Jun 09 '16 at 09:02