I am a newbie to this forum. I am trying to use NDsolve to solve some ODEs involving the interpolation function. Then, I will compare the fitted curve and data to determine the ODE coefficients.
Basically, I measure the Voltage(V) and Current(I) for a circuit. Then I want to use these V and I to determine the value of electric components in the circuit.
First, I make a interpolation function out of the waveform V data:
dataIndex = Range[2, 10001];
myVoltData = Transpose[{rawData[[dataIndex, 1]], rawData[[dataIndex, 4]]}];
myCurrData = Transpose[{rawData[[dataIndex, 1]], rawData[[dataIndex, 2]]}];
voltageFunc = Interpolation[myVoltData, InterpolationOrder -> 2];
Second, use NDSolve to solve the ODE, then use the solution to calculate the chi-sq. In the following code, the ODE parameters to be fit are r0Fit, r1Fit, c1Fit, currOffset, and the function fitFunc will eventually return the chi-sq:
fitFunc[r0Fit_?NumberQ, r1Fit_?NumberQ, c1Fit_?NumberQ, currOffsetFit_?NumberQ] :=
Block[ {sol, curr00, curr11},
sol = NDSolve[ {voltageFunc[t] == curr00[t]*r0Fit + curr11[t]*r1Fit ,
curr00[t] == (curr11[t] + r1Fit*c1Fit/10^6*curr11'[t]),
curr00[t0fit] == curr11[t0fit] == (voltageFunc[t0fit])/(r0Fit + r1Fit)},
{curr00, curr11}, {t, t0fit, t1fit}, AccuracyGoal -> 7][[1]];
Apply[Plus,
((myCurrData[[fitDataRange, 2]] + 50*currOffsetFit/10^6
- 50*Flatten[curr00[t] /. sol /.t -> myCurrData[[fitDataRange, 1]]])
/myCurrDataErr[[fitDataRange, 2]])^2/dataPnts]
]
Finally, use NMinimize find the fitting result with chi-sq minimum:
Timing[fitResult = NMinimize[ {fitFunc[r0f, r1f, c1f, iOffset],
130 < r0f < 170, 3000 < r1f < 3200, 650 < c1f < 750, 60 < iOffset < 100},
{r0f, r1f, c1f, iOffset},AccuracyGoal -> 0, Method -> "DifferentialEvolution"]]
My first problem is, since voltageFunc[t] is the interpolation function from data, it severely procrastinates the NDSolve command, as a result, the NMinimize is consuming vast amount of time(>20 mins). I wonder, why does interpolation function of ODE delay NDSolve so much? Is there any optimization method to make the NMinimize and NDSolve faster?
Secondly, NMinimize occasionally fails to find the global minimum. Any suggestions to improve the fitting result's reliability.
Any suggestion is appreciated. Thank you all.