       Re: complex function fitting?

• To: mathgroup at smc.vnet.net
• Subject: [mg98352] Re: complex function fitting?
• From: dh <dh at metrohm.com>
• Date: Wed, 8 Apr 2009 02:48:00 -0400 (EDT)

```Hi Ned,
what I said is still valid, by default Mathematica calculates with
complex numbers. You must have made another error. Why do you not give a
simple complete example? I can not help you without knowing the problem.
Here is my working example using NonlinearModelFit:
d = Table[{x + I y, Exp[x + y I]}, {x, 0, 1, .1}, {y, 0, 1, .1}];
d = Flatten[d, 1];
pol = NonlinearModelFit[d, {c0 + c1 x + c2 x^2}, {c0, c1, c2}, x]
yc = pol[x] /. x -> d[[All, 1]];
ListPlot[{Re[#], Im[#]} & /@ (yc - d[[All, 2]]), PlotRange -> All]
Daniel

Ned Lieb wrote:
> Just a clarification of my original question: I'm referring to a specific
> issue I'm having using the NonlinearModelFit function, which fits lists of
> data-points to functions of a type specified by the user (for example, say I
> knew that my data fit an exponential equation (it doesn't, by the way, this
> is just an example) with x as an independent variable: NonLinearModelFit
> could find the constant A in the equation A*e^x that would give the function
> that most closely approximated my data). My list of data is complex-valued
> (with non-zero imaginary components). Mathematica returned an error message
> saying I could only use real numbers. I was wondering whether there was a
> way to get around this.
>
> Thanks
>
> -----Original Message-----
> From: dh [mailto:dh at metrohm.com]
> Sent: Monday, April 06, 2009 6:48 AM
> To: Ned Lieb
> Subject: Re: complex function fitting?
>
> Hi Ned,
> Mathematica works by default with complex numbres. E.g. using "Fit":
> d = Table[{x + I y, Exp[x + y I ]}, {x, 0, 1, .1}, {y, 0, 1, .1}];
> d = Flatten[d, 1];
> pol = Fit[d, {1, x, x^2}, x]
> yc = pol /. x -> d[[All, 1]];
> ListPlot[{Re[#], Im[#]} & /@  (yc - d[[All, 2]]), PlotRange -> All]
> Daniel
>
> Ned Lieb wrote:
>> Does anyone know how I could extend the domain of Mathematica's
>> function-fitting functions so I can use complex-valued data?
>>
>>
>>
>
>
>
>
>

--

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh at metrohm.com>
Internet:<http://www.metrohm.com>

```

• Prev by Date: Re: UNDO and Mathematica - how useless is it?
• Next by Date: Palette Editor??
• Previous by thread: Re: complex function fitting?
• Next by thread: Difficulties with Re