I’m having trouble fitting this complex data:

re={{5.0119*10^6, 4.3675}, {3.9811*10^6, 4.3315}, {3.1623*10^6,

4.339}, {2.5119*10^6, 4.359}, {1.9953*10^6, 4.409}, {1.5849*10^6,

4.4774}, {1.2589*10^6, 4.5612}, {1.*10^6, 4.6626}, {794330.,

4.7789}, {630960., 4.918}, {501190., 5.0742}, {398110.,

5.2546}, {316230., 5.4617}, {251190., 5.6974}, {199530.,

5.959}, {158490., 6.2528}, {125890., 6.5717}, {100000.,

6.9075}, {79433., 7.2528}, {63096., 7.5808}, {50119.,

7.888}, {39811., 8.1606}, {31623., 8.3909}, {25119.,

8.5776}, {19953., 8.7193}, {15849., 8.8325}, {12589.,

8.9192}, {10000., 8.9844}, {7943.3, 9.0342}, {6309.6,

9.0712}, {5011.9, 9.1005}, {3981.1, 9.122}, {3162.3,

9.1391}, {2511.9, 9.1523}, {1995.3, 9.1632}, {1584.9,

9.1721}, {1258.9, 9.1801}, {1000., 9.1878}, {794.33,

9.1963}, {630.96, 9.2063}, {501.19, 9.2195}};

im={{5.0119*10^6, 0.45799}, {3.9811*10^6, 0.48469}, {3.1623*10^6,

0.52722}, {2.5119*10^6, 0.57605}, {1.9953*10^6,

0.63945}, {1.5849*10^6, 0.70803}, {1.2589*10^6, 0.78699}, {1.*10^6,

0.87252}, {794330., 0.96831}, {630960., 1.0722}, {501190.,

1.1824}, {398110., 1.2973}, {316230., 1.4138}, {251190.,

1.5262}, {199530., 1.6272}, {158490., 1.7106}, {125890.,

1.7662}, {100000., 1.7855}, {79433., 1.7633}, {63096.,

1.7037}, {50119., 1.5987}, {39811., 1.4626}, {31623.,

1.3082}, {25119., 1.1483}, {19953., 0.99279}, {15849.,

0.84988}, {12589., 0.72337}, {10000., 0.61406}, {7943.3,

0.52231}, {6309.6, 0.44673}, {5011.9, 0.38654}, {3981.1,

0.34015}, {3162.3, 0.30672}, {2511.9, 0.28574}, {1995.3,

0.27679}, {1584.9, 0.28001}, {1258.9, 0.29629}, {1000.,

0.32664}, {794.33, 0.37281}, {630.96, 0.43729}, {501.19, 0.52332}};

I want to use the following model:

A+B/(1+C*I*x)

with A,B, and C as parameters and x as a variable.

I found an approach on web, where people tried to build their own Fit-function to be able to implement the handling with complex data

http://community.wolfram.com/groups/-/m/t/384549?p_p_auth=r2YRAB5K

but I can’t even execute the provided example (see last post).

=================

You should add more information, especially the code you used and what exactly you have problems with.

– Yves Klett

Jun 19 at 18:47

My feeling is that linked code, using compile is probably more confusing than helpful (not to mention its for pure real x). Its really quite simple: compute estimated y for each x, compute the error at each point, sum squares of errors and apply nminimize to the result.

– george2079

Jun 19 at 19:34

=================

2 Answers

2

=================

here is how to do with NMinimize, using @youngs comp

model[x_] = a + b/(1 + I x c)

s = NMinimize[ {

Total[Norm[model[#[[1]]] – #[[2]]]^2 & /@ comp ],

c < 0}, {a, b, c}]
{5.35012, {a -> 4.63194, b -> 4.38458, c -> -9.15063*10^-6}}

Show[{

ListPlot[{re, im}],

Plot[ReIm[model[x] /. s[[2]]], {x, 0, 5.0119*10^6},

PlotRange -> {0, 10}]}]

note here c comes out of the solution, although you do get a really poor result if you don’t add the constraint c<0
The guy in my link above also used Compile prior to NMinimize. What is it good for? You said it would only work for reals, but the thread title was actually referring to complex fits.
– Anton Alice
Jun 22 at 13:53
I thought your X was complex when I first read your question, but that's not the case. Compile may speed things up, but my feeling is first make it work and worry about that if you need better performance. In this case its fast enough to not bother with compile.
– george2079
Jun 22 at 17:02
How can I estimate the errors of the individual fit parmeters with this method?
– Anton Alice
Jun 26 at 14:25
that is where NonlinearModelFit is better, it reports for you a wealth of statistical data. You might pose a new question on the topic, though I think it might be more of a math/stas than mathematica related question.
– george2079
Jun 26 at 15:27
My attempt: (I re-labeled re to real and im to imag)
comp = Transpose[{real[[All, 1]], real[[All, 2]] + I imag[[All, 2]]}];
Clear[a, b, c]
c = -7*^-6;
model = a + b/(1 + I x c);
fit = NonlinearModelFit[comp, model, {a, b}, x]
Show[
ListPlot[{real, imag}],
Plot[{Re[fit[x]], Im[fit[x]]}, {x, 0, 3*^6}, PlotRange -> All]

]

I hope this helps!