Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #9820 > unrolled thread

NonlinearModelFit and Complex Data

Started byMaria <rouelli@gmail.com>
First post2012-04-26 09:37 +0000
Last post2013-11-26 04:30 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  NonlinearModelFit and Complex Data Maria <rouelli@gmail.com> - 2012-04-26 09:37 +0000
    Re: NonlinearModelFit and Complex Data Maria <rouelli@gmail.com> - 2013-11-25 08:01 +0000
    Re: NonlinearModelFit and Complex Data Peter Klamser <klamser@gmail.com> - 2013-11-26 04:30 +0000

#9820 — NonlinearModelFit and Complex Data

FromMaria <rouelli@gmail.com>
Date2012-04-26 09:37 +0000
SubjectNonlinearModelFit and Complex Data
Message-ID<jnb50m$5m8$1@smc.vnet.net>
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

[toc] | [next] | [standalone]


#16268

FromMaria <rouelli@gmail.com>
Date2013-11-25 08:01 +0000
Message-ID<l6v05m$6p3$1@smc.vnet.net>
In reply to#9820
Update

The solution here worked for me:
http://forums.wolfram.com/mathgroup/archive/2010/Apr/msg00280.html

On Thursday, 26 April 2012 17:37:26 UTC+8, Maria  wrote:
> 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

[toc] | [prev] | [next] | [standalone]


#16270

FromPeter Klamser <klamser@gmail.com>
Date2013-11-26 04:30 +0000
Message-ID<l7185r$bo0$1@smc.vnet.net>
In reply to#9820
I can not read Data!

says Peter

2013/11/25 Maria <rouelli@gmail.com>:
> Update
>
> The solution here worked for me:
> http://forums.wolfram.com/mathgroup/archive/2010/Apr/msg00280.html
>
> On Thursday, 26 April 2012 17:37:26 UTC+8, Maria  wrote:
>> 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
>
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web