# NonlinearModelFit with NDSolve

I have a series of data:

 data={{x1(t),y1(t)},...,{xN(t),yN(t)}}


data represent a particle's orbit in the {x,y} plane. I would like to fit these observations with an orbit coming from two differential equations:

xt''[t]=f[x,y]
yt''[t]=g[x,y]


I would like to use NonlinearModel fit but I'm not able to define the model. The model would be given by {xt[t],yt[t]}; I should fit {x(t),y(t)} with {xt[t],yt[t]}, where the parameters are the initial conditions. Have you any general suggestions on the syntax?

My example of code is the following:

 model[a_?NumberQ, b_?NumberQ, c_?NumberQ, d_?NumberQ] :=
Module[{x, y, t},
First[{x,y} /. Eq1, Eq2, x == a, x' == b, y == c,
y' == d}, {x, y}, {t, 1992.224, 2009.61},
Method -> {StiffnessSwitching,
Method -> {ExplicitRungeKutta, Automatic}}, AccuracyGoal -> 15,
PrecisionGoal -> 16, MaxSteps -> Infinity]]]

nlm = NonlinearModelFit[data, model[a, b, c, d][t], {{a, b, c, d}, t]

nlm["ParameterTable"]


But all I get is error message

NonlinearModelFit::nrlnum: The function value ... is not a list of real           numbers with dimensions {70} at... >>


Is there something to modify in the code?

## 1 Answer

The field {xt'',yt''} is an acceleration field. Giving 2 initial conditions (e.g. initial position and velocity or the first 2 points) the trajectory is uniquely determined. You may now define an error function: err that is the sum of the distances (or easier, the squares thereof) from your data points. And now you want to minimize err over 4 parameters (e.g. initial position:2 parameters initial velocity:2 parameters)

• This answer would be made better if you can define the syntax using code that the OP is looking for. This answer is informative, however. – CA Trevillian Sep 8 '20 at 3:33
• Should I also serve tee and cake? – Daniel Huber Sep 8 '20 at 8:04
• Exactly. But I can't find such an exemple to help me. – Orion Sep 8 '20 at 8:38
• I solved it minimizing a chi square variable with NMinimize. – Orion Sep 9 '20 at 8:14