# LMS distance from a point to an InterpolatingFunction

I have a short script to NDSolve a second-order nonlinear BVP, which as its output produces an InterpolatingFunction object. I would like to load in some data, and check how well this data fits the function by performing a Least-Mean-Squares sum.

I don't know how to go about this with a function represented by one of these InterpolatingFunction objects. Minimal(ish) code to produce the function is included below.

{r0, f0} = {1.349, 1.421}; {r1, f1} = {3.913, 0.044};
eqn = 2 H == f''[r]/((1 + f'[r]^2)^(3/2)) + (1/r) (f'[r]/(1 + f'[r]^2)^(1/2));
H = -0.021414;
F = First[f /. NDSolve[{eqn, f'[r0] == -1.127435, f[r1] == f1}, f, {r, r0, r1}]]


Any help would be appreciated.

I guess you mean something like this:

{r0, f0} = {1.349, 1.421}; {r1, f1} = {3.913, 0.044};
eqn = 2 h == f''[r]/((1 + f'[r]^2)^(3/2)) + (1/r) (f'[r]/(1 + f'[r]^2)^(1/2));
h = -0.021414;
ff = First[f /. NDSolve[{eqn, f'[r0] == -1.127435, f[r1] == f1}, f, {r, r0, r1}]];
data = {#, ff[#]} + {0, RandomReal[{-.1, .1}]} & /@  RandomReal[{r0, r1}, 30];
Show[Plot[ff[r], {r, r0, r1}, Evaluated -> True], ListPlot[data]]

Tr[(#[] - ff[#[]])^2 & /@ data] 0.245836

Of course Mathematica provides infinite ways for doing the same:

Norm[Differences /@ MapAt[ff, data, {All, 1}]] (*Sqrt of previous result*)

Norm[Subtract @@@ (data /. {x_, y_} -> {ff[x], y})]


Etc.