Mathematica - FindFit with complex numbers

In summary, the conversation discusses the use of the FindFit function with complex data and functions, and how to only return real results for the parameters. It also explores the possibility of fitting the same parameters in two different functions to two different data sets simultaneously. The conversation ends with a potential solution involving defining a chi squared function and using minimize or nminimize.
  • #1
NeoDevin
334
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
  • #2
Have exactly the same problem here...

With the same error...
 
  • #3
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?
 
  • #4
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...
 
  • #5
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
 

1. How do I use complex numbers in Mathematica's FindFit function?

To use complex numbers in FindFit, simply input them as a list of two elements, with the real and imaginary parts separated by a comma. For example, {3, 4} represents the complex number 3+4i. You can also use the built-in function Complex[a, b] to create a complex number with real part a and imaginary part b.

2. Can I fit a function with complex coefficients using FindFit?

Yes, you can fit a function with complex coefficients using FindFit. Simply input the function with the complex coefficients and use the same format for the data points as mentioned in the first question. For example, if you want to fit the function f[x] = a+bi*x to a set of data points, you would input FindFit[data, f[x], {a, b}, x].

3. How does FindFit handle complex-valued data points?

FindFit handles complex-valued data points in the same way as real-valued data points. It uses the least-squares method to find the best fit for the given function and data points. However, it is important to note that FindFit only works with functions that have real-valued outputs, so if your data points have imaginary parts, you may need to modify your function to output only real values.

4. What options are available for complex-valued fitting with FindFit?

There are several options available for complex-valued fitting with FindFit, including different methods for minimizing the sum of squares, specifying constraints on the parameters, and setting initial values for the parameters. You can also use the option "ComplexFit" to specify whether the parameters should be treated as real or complex numbers. For more information, refer to the Mathematica documentation on FindFit.

5. Are there any common pitfalls when using complex numbers in FindFit?

One common pitfall when using complex numbers in FindFit is forgetting to specify the option "ComplexFit" when fitting a function with complex coefficients. This can lead to incorrect results or errors. Another potential issue is dealing with singularities or rounding errors when using complex numbers in the fitting process. It is important to carefully consider the data and the chosen function to avoid these issues.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
257
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Classical Physics
Replies
13
Views
902
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
8K
Back
Top