Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2012

[Date Index] [Thread Index] [Author Index]

Search the Archive

NonlinearModelFit and Complex Data

  • To: mathgroup at smc.vnet.net
  • Subject: [mg126244] NonlinearModelFit and Complex Data
  • From: Maria <rouelli at gmail.com>
  • Date: Thu, 26 Apr 2012 05:33:05 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Hi,

I am trying to fit complex data to a complex function. 

Here's a snippet:

data = Import["http://apps.getcloudigniter.com/data/data.csv";];

fitData = 
  Table[{data[[i, 1]], data[[i, 2]] + I*data[[i, 3]]}, {i, 1, 
    Dimensions[data][[1]]}];

fitEqn[x_] := (aR + I aI) + ( bR + I bI)*(Abs[x - 79800.3]/
     1585.02) - (
   par1 (x - par1))/((cR + I cI)*((x - par1)^2 - 
      I par2/2 (x - par1) - 435093.75^2));

fit = NonlinearModelFit[fitData, 
  fitEqn[x] , {aR, aI, bR, bI, cR, cI, par1, par2}, x, 
  WorkingPrecision -> 100, MaxIterations -> 10000]

This gives me an error:

"The function value {....} is not a list of real numbers..."

On the other hand, FindFit gives me the same error but it works quite well by setting NormFunction -> (Norm[Abs[#^2]] &):

(* This works *)
 fit = FindFit[fitData, 
  fitEqn[x] , {aR, aI, bR, bI, cR, cI, par1, par2}, x, 
  NormFunction -> (Norm[Abs[#^2]] &), WorkingPrecision -> 100, 
  MaxIterations -> 10000]

And I get a fairly nice fit:

Show[ListPlot[
  Table[{data[[i]][[1]], data[[i]][[2]]}, {i, 1, 
    Dimensions[data][[1]]}], PlotStyle -> Red], 
 Plot [Re[fitEqn[x] /. fit], {x, data[[Dimensions[data][[1]]]][[1]], 
   data[[1, 1]]}, PlotStyle -> Blue]]

Show[ListPlot[Table[{data[[i]][[1]],data[[i]][[3]]},{i,1,Dimensions[\
data][[1]]}],PlotStyle->Red],Plot \
[Im[fitEqn[x]/.fit],{x,data[[Dimensions[data][[1]]]][[1]],data[[1,1]]}\
,PlotStyle->Blue]]

However, I can't do the same modification to NonlinearModelFit(which I prefer to use since I need the additional information on fitting, e.g. ANOVA). Any tips on making it work? 

Thanks,
Maria



  • Prev by Date: Re: Coloured strings
  • Next by Date: Re: Serious Bug in Mathematica 7 and 8.0.4.0 (latest version)
  • Previous by thread: Re: how to check for NumericQ arbitrary data structure
  • Next by thread: Distinquishing #'s in nested pure functions