2
$\begingroup$

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: enter image description here

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:

enter image description here

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?

$\endgroup$
  • $\begingroup$ "...for some reason Mathematica spit out InterpolatingFunction[] as components." As stated in the NDSolve documentation, "NDSolve gives results in terms of InterpolatingFunction objects." $\endgroup$ – Bob Hanlon Mar 20 '17 at 21:46
2
$\begingroup$

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 *)

enter image description here

$\endgroup$
  • 2
    $\begingroup$ Slightly more compact is f[t_] = EuclideanDistance @@ ({x[t], y[t], z[t]} /. {sol1, sol2}); $\endgroup$ – Bob Hanlon Mar 20 '17 at 22:06
  • $\begingroup$ @BobHanlon putting your implementation as an edit with credits. Thanks ! $\endgroup$ – Ali Hashmi Mar 20 '17 at 22:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.