FindFit with parameters which are simultaneously in initial conditions

I have RLC circuit. I would like to find R and L by using FindFit, but L is in initial condition and I have problem with it. Could you help me ?

c = 116*10^(-6); U = 16000. ;

data =
{
{0, 0}, {0.25*10^(-6), 132000}, {0.5*10^(-6), 330000}, {1*10^(-6), 462000},
{2*10^(-6), 600000}, {3*10^(-6), 462000}, {4*10^(-6), 330000}, {5*10^(-6), 66000},
{6*10^(-6), -198000}, {7*10^(-6), -264000}, {8*10^(-6), -198000}, {9*10^(-6), -132000}
};

lp = ListPlot[data, PlotRange -> All]

fit =
FindFit[data,
First[i /.
NDSolve[{i''[t] + R/L * i'[t] + 1/(c L)*i[t] == 0, i[0] == 0, i'[0] == U/L},
i, {t, 0, 9*10^(-6)}]],
{{R, 10*10^(-3)}, {L, 20*10^(-9)}},
i,
PrecisionGoal -> 4,
AccuracyGoal -> 4]


1 Answer

Your set up:

c = 116*10^(-6); U = 16000;

data = {{0, 0}, {0.25*10^(-6), 132000}, {0.5*10^(-6),
330000}, {1*10^(-6), 462000}, {2*10^(-6), 600000}, {3*10^(-6),
462000}, {4*10^(-6), 330000}, {5*10^(-6),
66000}, {6*10^(-6), -198000}, {7*10^(-6), -264000}, {8*10^(-6), \
-198000}, {9*10^(-6), -132000}};


Use analytic not numerical form DSolve:

model = (i /.
DSolve[{i''[t] + R/L*i'[t] + 1/(c L)*i[t] == 0, i[0] == 0,
i'[0] == U/L}, i, {t, 0, 9*10^(-6)}])[[1, 2]];
model // TraditionalForm


Find a fit:

fit = NonlinearModelFit[data, model, {{R, 10*10^(-3)}, {L, 20*10^(-9)}}, t];
fit["BestFitParameters"]


{R -> 0.0109553, L -> 2.15996*10^-8}

Show[ListPlot[data],
Plot[fit[x], {x, 0, 9 10^-6}, PlotStyle -> Directive[Red, Thick]],
Frame -> True, PlotRange -> All]


• Thank you very much for help. What if we treat equation as without analytical solution ? – Krzysiek Aug 25 '14 at 10:33
• @Krzysiek In such case I would try using ParametricNDSolve - look through the examples HERE to grasp the scope. – Vitaliy Kaurov Aug 25 '14 at 18:51