Hi all,
To do some data analyzation, I would like to fit my data with an interpolated function which I get from theoretical calculations.
That's the code: I import the theoretical data (attached) and make an interpolation. Additionally I import my data that is to be fitted (attached). I already try to move the data into the range of the fitting function:
datenFunction = Import[".../r_ 5um__G _ 0.06kPa_Int _Phase.txt", "Table", "NumberPoint" -> "."]; (*Theoretical data*)
datenExperiment = Import["...../matlab.txt", "Table", "NumberPoint" -> ","]; (*Data to be fitted*)
E0 = datenFunction[[All, 1]];
phase = datenFunction[[All, 2]];
iPhase = Interpolation[phase];
iE = Interpolation[E0];
time = ({datenExperiment[[All, 1]]} - Mean[datenExperiment[[All, 1]]])*10000 + 5;
data = datenExperiment[[All, 2]];
dataExperiment2 = MapThread[List, {time[[1]], data}];
iData = Interpolation[dataExperiment2];
Show[ListPlot[ E0], Plot[iE[t], {t, 1, length}]]
Show[ListPlot[ phase], Plot[iPhase[t], {t, 1, length}]]
Show[Plot[iData[t], {t, 2, 6}, PlotRange -> All], ListPlot[dataExperiment2]]
I define and plot the interpolated theory function using maipulate:
tFirst = dataExperiment2[[1, 1]]; (*First time value*)
tLast = dataExperiment2[[-1, 1]]; (*Last time value*)
mitte = (tFirst + tLast)/ 2 ;(*Mid point in time*)
IntFirst = Mean[dataExperiment2[[1 ;; 15, 2]]]; (*Mean intensity before cell*)
IntLast = Mean[dataExperiment2[[-15 ;; -1, 2]]] ;(*Mean intensity after cell*)
IntMean = Mean[{IntFirst, IntLast}]; (*Total mean intensity*)
IntMax = Max[dataExperiment2[[;; , 2]]] ;(*Maximal intensity*)
IntMin = Min[dataExperiment2[[;; , 2]]];
interference2[dPhase_, ERef_, t_, I0_, a_, b_, dt_, phase0_] := I0 + a*(ERef^2*Cos[phase0 + iPhase[b (t - dt)] + dPhase]^2 + iE[b (t - dt)]^2*Cos[phase0 + iPhase[b (t - dt)]]^2 + 2*ERef*iE[b (t - dt)]*Cos[phase0 + iPhase[b (t - dt)] + dPhase]* Cos[phase0 + iPhase[b (t - dt)]]);
Manipulate[Show[Plot[iData[t], {t, 2, 6}, PlotRange -> All], Plot[interference2[dPhase, ERef, t, I0, a, b, dt, phase0], {t, tFirst, tLast}, PlotRange -> All]], {{dPhase, 1.2}, 0, 2*Pi}, {{phase0, 2}, 0, 2*Pi}, {{ERef, IntMean}, 0, 1.5 IntMean}, {{I0, 0.03}, -2, 2}, {{a, -0.3}, -10, 10}, {{b, 70}, -1, 100}, {{dt, -mitte + 7.8}, tFirst, tLast}]
From this I can see, that interpolated theory function and data approximately overlap. However, I already get some errors:
InterpolatingFunction::dmval: Input value {-110.239} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
InterpolatingFunction::dmval: Input value {-110.239} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
InterpolatingFunction::dmval: Input value {-110.239} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
General::stop: Further output of InterpolatingFunction::dmval will be suppressed during this calculation. >>
If I move the sliders, the function changes correctly, but further similar erros are produced.
What I actually want to do, is to fit the data with the interpolated function:
fit = NonlinearModelFit[dataExperiment2, interference2[ERef, t, IntMean - 2 a (1 + Cos[dPhase]), dPhase, a, b, dt, phase0], {{ERef, IntMean}, {dt, -mitte + 7.8}, {dPhase, 1.2}, {a, -0.3}, {I0, 0.03}, {b, 70}, {phase0, 2}}, t];
Show[ListPlot[dataExperiment2], Plot[fit[t], {t, tFirst, tLast}, PlotRange -> All]]
fit["ParameterTable"]
InterpolatingFunction::dmval: Input value {-140.148} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
InterpolatingFunction::dmval: Input value {-140.148} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
InterpolatingFunction::dmval: Input value {-140.148} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
General::stop: Further output of InterpolatingFunction::dmval will be suppressed during this calculation. >>
InterpolatingFunction::dmval: Input value {-199.877} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
InterpolatingFunction::dmval: Input value {-199.877} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
InterpolatingFunction::dmval: Input value {-199.877} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
General::stop: Further output of InterpolatingFunction::dmval will be suppressed during this calculation. >>
InterpolatingFunction::dmval: Input value {-199.877} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
InterpolatingFunction::dmval: Input value {-199.877} lies outside the range of data in the interpolating function. Extrapolation will be used. >>
InterpolatingFunction::dmval: Input value {-199.877} lies outside the range of data in the interpolating function. Extrapolation will be used.
General::stop: Further output of InterpolatingFunction::dmval will be suppressed during this calculation. >>
Additionally, the "fit" (only some curve going somewheare through the data) and the parameter table are shown.
It seems, as if mathematica has a problem to shift the interpolated function into the range of the data to be fitted.
Does anyone has an idea what I can do in order to match the interpolated function with the data? I would be pleased for any hint.
Thanks a lot!
Attachments: