Mathematica - FindFit with complex numbers

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 11K views
NeoDevin
Messages
334
Reaction score
2
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.
 
Physics news on Phys.org
Have exactly the same problem here...

With the same error...
 
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?
 
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...
 
Hepth said:
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]

NeoDevin said:
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