PDA

View Full Version : Mathematica - FindFit with complex numbers


NeoDevin
Sep9-08, 09:56 AM
Is there any way to use the FindFit function with complex data/functions, but to only return real results for the parameters?

Right now I'm getting the following error:

FindFit::nrnum: The function value 62.6185+25.5493i is not a real number at {c1f,c2f} = {1.,1.}.

From the code:

FindFit[data, {model, {Im[c1f] == 0, Im[c2f] == 0}}, {c1f, c2f}, x]

Alternatively, is there any way to fit the same parameters in 2 functions to 2 different data sets simultaneously? (then I could just separate the real and imaginary parts, and fit them both)

Thanks in advance.

Littlepig
Oct16-09, 03:04 AM
Have exactly the same problem here....

With the same error...

Hepth
Oct16-09, 08:22 PM
But if the function is returning a complex result, do you just want the real part? Or only parts of the function where its is ONLY real?

NeoDevin
Oct16-09, 09:28 PM
Sorry littlepig, I never did figure it out. I would still be curious to know how to do it if anyone else here knows. Originally (the first post was over a year ago) I had wanted to fit a complex function to complex data, using 2 real parameters. I ended up using a different approach to solve my original problem. I guess you could define the chi squared function and then use minimize or nminimize...

Littlepig
Oct17-09, 02:29 AM
But if the function is returning a complex result, do you just want the real part? Or only parts of the function where its is ONLY real?

Suppose the example:

model = a^b*t^2+i a^2*b*exp[t] where (t,a,b in real)

data= {{t,x(t)+y(t) i},...} where y and x are real (data is the experimental data...numbers...)

FindFit[data,model,{a,b},t]

Sorry littlepig, I never did figure it out. I would still be curious to know how to do it if anyone else here knows. Originally (the first post was over a year ago) I had wanted to fit a complex function to complex data, using 2 real parameters. I ended up using a different approach to solve my original problem. I guess you could define the chi squared function and then use minimize or nminimize...

Thanks, it's a possible solution...:p