How can I extract a single dimension from an InterpolatingFunction
? As an example:
ClearAll[x];
s = NDSolve[
Evaluate[Derivative[1][x][t] == -x[t]] && x[0] == {10, -10, 4},
x, {t, 0, 5}]
x = x /. First@s
Plot[x[t], {t, 0, 5}]
I can easily extract values (and also plot) for a single dimension like this
x[1][[1]] + x[1][[3]]
(* 5.15031 *)
but if I want to create a new function representing the sum? The following generates a lot of warnings.
sum = FunctionInterpolation[x[t][[1]] + x[t][[3]], {t, 0, 5}]
(* Part::partw: Part 3 of
InterpolatingFunction[{{0.,5.}},{5,3,1,{57},{4},0,0,0,0,Automatic,{},{},
False},{{0.,0.000114457,<<48>>,<<7>>}},{{{10.,-10.,4.},{-10.,10.,-4.}},{
{9.99886,-9.99886,3.99954},{-9.99886,9.99886,-3.99954}},{{9.99771,-9.997
71,3.99908},{-9.99771,9.99771,-3.99908}},{{9.9603,-9.9603,3.98412},{-9.9
603,9.9603,-3.98412}},<<44>>,{{0.229328,-0.229328,0.0917314},{-0.229328,
0.229328,-0.0917314}},{{0.194925,-0.194925,0.0779699},{-0.194925,0.19492
5,-0.0779699}},<<7>>},{Automatic}][t] does not exist. >>
....
General::stop: Further output of Part::partw will be suppressed during
this calculation. >> **)
I have also noticed that
x2 = FunctionInterpolation[x[t], {t, 0, 5}]
appears to throw away all but the first dimension.
{x[2], x2[2]} // TableForm
(*
1.35335 -1.35335 0.541341
1.35335
*)
What is the best way to extract a single dimension from InterpolatingFunction
?