In what follows data
contains the list of observations without the header.
Evaluating Part[data, All, {1, -1}]
will return a list of pairs {t,X}
(time and X value pairs). This list, will be transformed accordingly, in order to be used with LinearModelFit
(see below).
The solution for X[t]
of the differential system is given by X[t]->Exp[p t]C[2]
and can be written as Log[X[t]]==Log[C[2]] + p t
(taking logs on each hand side and turning ->
into ==
).
This last (algebraic) expression can be interpreted as a linear equation in t
of the form eg y==a+b t
. This form can be estimated using LinearModelFit
after applying a simple transformation to the available data.
According to the documentation, LinearModelFit
requires the data that are passed to it, to be in the form {{x11, x21, ..., x1n, y1}...}
(the dependent variable is the last entry in every row of data).
Since we'll be using the logarithmic transformation of the solution for X[t]
, we are going to need to transform all the X
values (the dependent variable in our regression) into (natural) logs. This is accomplished thus: MapAt[Log, Part[data, All, {1, -1}], {All, -1}]
.
Finally, evaluating lmf=LinearModelFit[transd,t,t]; lmf["BestFit"]
, where transd
holds the transformed data (see above) produces
-1.90346 + 1.70275 t
The (point estimate of the) slope or $\hat{ρ}$ is equal to 1.703
(approx.).
edit
code I've used
Clear[naught]
(* returns the symbols in 'x' appended with '0' eg 'naught[x,y]' evaluates to '{x0, y0}' *)
naught[x__] := Map[ToExpression[StringJoin[ToString[#], "0"]] &, {x}]
ClearAll[lin]
SetAttributes[{lin}, Listable]
(* returns a linear approximation of 'f' around 'naught[x]' *)
lin[f_, x__] := Module[{x0 = naught[x], deriv0, f0, diff0},
f0 = f @@ x0;
deriv0 = D[f[x], {{x}}] /. Thread[{x} -> x0];
diff0 = {x} - x0;
f0 + Total[diff0 deriv0]
]
ClearAll[sep]
SetAttributes[{sep}, Listable]
(* returns a list of coefficients for variables 'x' present in 'f';
the first entry contains constant terms eg 'sep[a+bx+cy]' returns '{a,b,c}' *)
sep[f_, x__] := Module[{coefs = Coefficient[f, {x}]},
Flatten[{Simplify[f - coefs.{x}], coefs}]
]
I have defined the rhs of the differential system as
f1[x_, s_] := p s x/(s + k) - a x
f2[x_, s_] := a (si - s) - p/y s x /(s + k)
Evaluating
lin[{f1, f2}, X, S]
returns the linearised system
{
(-a + (p S0)/(k + S0)) (X - X0) - a X0 + (p S0 X0)/(k + S0) + (S - S0) (-((p S0 X0)/(k + S0)^2) + (p X0)/(k + S0)),
a (-S0 + si) + (S - S0) (-a + (p S0 X0)/((k + S0)^2 y) - (p X0)/((k + S0) y)) - (p S0 (X - X0))/((k + S0) y) - (p S0 X0)/((k + S0) y)
}
and interpreting the fact that S>>k
implies S+k->S
along with the fact that since the time index in the provided data is below 2.5
, the value of a
is inferred to be zero (see question)
q = sep[lin[{f1, f2}, X, S], X, S] /. {k + S0 -> S0, k -> 0, a -> 0} // Simplify
returns
{{0, p, 0}, {0, -(p/y), 0}}
which can be shown to be equal to the derived rhs of the system; indeed
Total[{1, X[t], S[t]} #] & /@ q
returns
{p X[t], -((p X[t])/y)}