« View all new features in
Mathematica
9
◄
previous
|
next
►
New in
Mathematica
9
›
Parametric Differential Equations
Parameter Fitting
Find the parameter
that gives the best fit for given data to the Van der Pol equation.
In[1]:=
X
peqns = {x''[t] - \[Mu] (1 - x[t]^2) x'[t] + x[t] == 0, x[0] == 2, x'[0] == 0}; data = NDSolveValue[peqns /. \[Mu] -> 1., Table[{t, x[t] + RandomReal[{-.3, .3}]}, {t, 0, 10, .2}], {t, 10}];
In[2]:=
X
ListPlot[data, PlotRange -> All, PlotStyle -> Red, ImageSize -> Medium]
Out[2]=
Create a
ParametricFunction
object and use it in
FindFit
.
In[3]:=
X
pfun = ParametricNDSolveValue[{x''[t] - \[Mu] (1 - x[t]^2) x'[t] + x[t] == 0, x[0] == 2, x'[0] == 0}, x, {t, 0, 10}, {\[Mu]}];
In[4]:=
X
fit = FindFit[data, pfun[\[Mu]][t], {{\[Mu], 2}}, t]
Out[4]=
In[5]:=
X
Show[ListPlot[data, PlotStyle -> Red], Plot[pfun[\[Mu]][t] /. fit, {t, 0, 10}], ImageSize -> Medium]
Out[5]=