Mathematica Asked on December 5, 2020
I’m trying to fit an observed orbit
data={years,xobs,dx,yobs,dy}
where xobs and yobs are the observed coordinates and dx,dy the corresponding errors. I must fit this orbit with solutions coming from two differential equations
Eq1=x''[t]=f[x,y]
Eq2=y''[t]=g[x,y]
I want to build a chi square variable and to minimize it over four parameters (initial conditions on position and velocities). I wrote the following code:
ss = ParametricNDSolve[{Eq1, Eq2, x[1992.22] == x0,
x'[1992.22] == vx0*(yr/AU), y[1992.22] == y0,
y'[1992.22] == vy0*(yr/AU)}, {x, y}, {t, 1992.22,
2009.61}, {x0, vx0, y0, vy0},
Method -> {StiffnessSwitching,
Method -> {ExplicitRungeKutta, Automatic}}, AccuracyGoal -> 15,
PrecisionGoal -> 16, MaxSteps -> Infinity]
X[tt_] = x[tt] /. ss /. tt -> t;
Y[tt_] = y[tt] /. ss /. tt -> t;
xconv[tt_] = ((c1*X[tt]) + (c2*Y[tt]))/. ss[[1]] /. tt -> t;
yconv[tt_] = ((d1*X[tt]) + (d2*Y[tt])) /. ss[[1]] /. tt -> t;
where ci,di are given constants. The function to minimize is:
chisquare[x0_?NumberQ, vx0_?NumberQ, y0_?NumberQ, vy0_?NumberQ] :=
1/(70 - 2)
Sum[(((xconv[t = years[[i]]] - xobs[[i]])/(dx[[i]] 2))^2 + ((
yconv[t = years[[i]]] - yobs[[i]])/(dy[[i]] 2)))^2, {i, 1, 70}]
NMinimize[
chisquare[x0, vx0, y0,
vy0], {{x0 > 850}, {vx0 > 600}, {y0 > 1570}, {vy0 > 50}}, {x0, vx0,
y0, vy0}]
But I get several error messages
Hold::fpct: -- Message text not found -- ({x0,vx0,y0,vy0}) ({1992.22}) >>
the function value ...
is not a number at {vx0,vy0,x0,y0} =
{601.4626035460618`,51.586099690163145`,851.0994304457607`,1571.
9647629127392`}. >>
The function value 1...is not a number at {vx0,vy0,x0,y0} = {601.463,51.5861,851.099,1571.96}. >>
Is this the right way or is there something completely wrong in the syntax?
EDIT1:
I modified a little the code and now it is running but it’s too slow.
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP