Mathematica Mathematica - FindFit with complex numbers

AI Thread Summary
The discussion revolves around the challenges of using the FindFit function with complex data and functions, specifically focusing on the issue of obtaining real results. Users are encountering errors when the function returns complex values, prompting questions about whether to extract only the real parts or to restrict the function to return only real values. One participant shares their experience of initially wanting to fit a complex function to complex data using real parameters but ultimately resorted to a different approach. Suggestions include defining a chi-squared function and using minimization techniques as potential solutions. Overall, the conversation highlights the complexities of fitting models to data that involve both real and imaginary components, with participants seeking effective strategies to address these challenges.
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
 

Similar threads

Replies
5
Views
9K
Replies
1
Views
1K
Replies
2
Views
9K
Replies
2
Views
5K
Replies
13
Views
2K
Replies
5
Views
2K
Back
Top