I have a series of data:


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:


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[0] == a, x'[0] == b, y[0] == c, 
 y'[0] == 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]


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?


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)

  • $\begingroup$ 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. $\endgroup$ – CA Trevillian Sep 8 '20 at 3:33
  • $\begingroup$ Should I also serve tee and cake? $\endgroup$ – Daniel Huber Sep 8 '20 at 8:04
  • $\begingroup$ Exactly. But I can't find such an exemple to help me. $\endgroup$ – Orion Sep 8 '20 at 8:38
  • $\begingroup$ I solved it minimizing a chi square variable with NMinimize. $\endgroup$ – Orion Sep 9 '20 at 8:14

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.