Let me first explain the background problem. I'm trying to solve a problem with a projectile motion in 4D such that the position vector is:
$\boldsymbol{r}(t)=\boldsymbol{r}[x(t),y(t),z(t)]$
I have the differential equations with $F(t)=mr''(t)$ such that:
$\boldsymbol{F}_{drag}(t)=\frac{1}{2} \rho A C_{drag} R (\boldsymbol{r'}(t))^2; \\ \boldsymbol{F}_{grav}=m\boldsymbol{g};\\ \boldsymbol{F}_{total}(t)=\boldsymbol{F}_{drag}(t)+\boldsymbol{F}_{grav}$
I want to fit $C_{drag}$ as a parameter; $m$, $\rho$, $A$ and $R$ are known.
In Mathematica I'm solving them as:
r[t_] := {xx[t], yy[t], zz[t]};
(* Initial velocity V0 is known *)
V0 = {v0x,v0y,v0z};
(* Gravitical Force *)
GravForce = {0, -9.8*M, 0};
(* Drag Force *)
DragForce[t_] := 0.5*Cdrag*rho*A*Norm[r'[t]]*r'[t];
(* Total force *)
TotalForce[t_] := {DragForce[t][[1]] + GravForce[[1]], DragForce[t][[2]] + GravForce[[2]], DragForce[t][[3]] + GravForce[[3]]};
(* Parametric solution *)
ParametricSolution = ParametricNDSolve[{
r''[t][[1]] == TotalForce[t][[1]]/M, r'[0][[1]] == V0[[1]], r[0][[1]] == 0,
r''[t][[2]] == TotalForce[t][[2]]/M, r'[0][[2]] == V0[[2]], r[0][[2]] == 0,
r''[t][[3]] == TotalForce[t][[3]]/M, r'[0][[3]] == V0[[3]], r[0][[3]] == 0},
{xx, yy, zz}, {t, 20}, {Cdrag}];
Until here everything is working fine! But now I have a set of {x,y} experimental data that I want to find the best fit with Cdrag as a parameter.
data = {{0, 0}, {20, 8}, {40, 17}, {60, 24}, {80, 27}, {100,
23}, {115, 14}, {126.7, 0}};
It looks like this:
I needed something like this:
NonlinearModelFit[data,
{xx[CMag][t], yy[CMag][t]} /. ParametricSolution,
{CMag}, {xx[t], yy[t]}];
But I get the error: "NonlinearModelFit::fitc: Number of coordinates (1) is not equal to the number of variables (2)."
Can you help me? Thanks ;)
EDIT:
The values for the constants are:
M = .04593; (* Mass of the ball in Kg *)
R = .04267/2; (* Ball Radius *)
A = Pi*R^2; (* Cross section area of the golf ball *)
rho = 1.2041; (* kg/m^3 Density of air at 20C, 1 atm*)
theta = 19.9;(* Starting angle from the horizontal *)
v0=48.54; (*speed in m/s*)
V0 = {v0*Cos[theta Degree], v0*Sin[theta Degree], 0};(* Ball velocity components*)
Area
in your code which is a Mathematica function $\endgroup$Area
toA
(it wasn't a problem) and added the values for the constants, hope you can help me now $\endgroup$