1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Mathematica - FindFit with complex numbers

  1. Sep 9, 2008 #1
    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.
  2. jcsd
  3. Oct 16, 2009 #2
    Have exactly the same problem here....

    With the same error...
  4. Oct 16, 2009 #3


    User Avatar
    Gold Member

    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?
  5. Oct 16, 2009 #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...
  6. Oct 17, 2009 #5
    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...)


    Thanks, it's a possible solution...:p
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Mathematica - FindFit with complex numbers