# How can I subtract the components of these 2 solutions if the components are interpolating functions?

I have solved for solutions of the Lorentz system but for some reason Mathematica spit out InterpolatingFunction[] as components.

Input 1:

eqns = {x'[t] == 10 (y[t] - x[t]),
y'[t] == 28 x[t] - y[t] - x[t] z[t],
z'[t] == (-8/3) z[t] + x[t] y[t]};

sol1 = NDSolve[{eqns, x[0] == 10, y[0] == -10, z[0] == 25}, {x, y,
z}, {t, 0, 30}, MaxSteps -> \[Infinity]]


Output 1:

Input 2:

eqns2 = {x'[t] == 10 (y[t] - x[t]),
y'[t] == 28.0001 x[t] - y[t] - x[t] z[t],
z'[t] == (-8/3) z[t] + x[t] y[t]};

sol2 = NDSolve[{eqns2, x[0] == 10, y[0] == -10, z[0] == 25}, {x, y,
z}, {t, 0, 30}, MaxSteps -> \[Infinity]]


Output 2:

I need to find the Euclidean distance of the 2 solutions given by (for some time $t$):

$$d(t) = \sqrt{(x_1-x_2)^2+(y_1-y_2)^2+(z_1-z_2)^2}$$

How can I do this with this output though?

• "...for some reason Mathematica spit out InterpolatingFunction[] as components." As stated in the NDSolve documentation, "NDSolve gives results in terms of InterpolatingFunction objects." Mar 20, 2017 at 21:46

compacted notation by Bob Hanlon

f[t_] := EuclideanDistance@@({x[t], y[t], z[t]} /.{sol1, sol2})


original attempt

f[t_] := EuclideanDistance[({x[t], y[t], z[t]} /.
sol1[[1]]), ({x[t], y[t], z[t]} /. sol2[[1]])]

f[3]
(* 0.00631062 *)


• Slightly more compact is f[t_] = EuclideanDistance @@ ({x[t], y[t], z[t]} /. {sol1, sol2}); Mar 20, 2017 at 22:06
• @BobHanlon putting your implementation as an edit with credits. Thanks ! Mar 20, 2017 at 22:08