For my experiment, I have to simultaneously fit the real part and imaginary part of cavity reflection data which is given here
column 1: frequency, column 2: reflection magnitude, column 3: phase
I followed the similar approach which is shown by one of the user Rob Sewell,here
da1 = Transpose[{data[[All, 1]], data[[All, 2]]*Cos[data[[All, 3]]]}];
da2 = Transpose[{data[[All, 1]], (data[[All, 2]]*
Sin[data[[All, 3]]])}];
Repart[x_, y_, f_, f0_, A_] := A + (x y - 4 (f - f0)^2)/(4 (f - f0)^2 + y^2);
Impart[x_, y_, f_, f0_, B_] := B + ((f - f0) (x + y))/((f - f0)^2 + x^2);
Clear[A, B, x, y, f, f0, set]
dat = Join[da1 /. {x_, y_} -> {1, x, y}, da2 /. {x_, y_} -> {2, x, y}];
fitmodel[set_, x_, y_, f_, f0_, A_, B_] :=
Which[set == 1, Evaluate@Repart[x, y, f, f0, A], set == 2,
Evaluate@Impart[x, y, f, f0, B]]
fit = NonlinearModelFit[dat,fitmodel[set, x, y, f, f0], {{x, 0.0001},
{y,0.0001}, {f0, 10.10},A, B}, {f, set}, MaxIterations -> Infinity];
fitparams = fit["BestFitParameters"]
The code always gives out error, Am I missing something here?I have already checked real part and imaginary part separately , that works perfectly fine; but I need to simultaneously plot this,
A complex plot might also helps , I guess.