Thanks
-----Original Message-----
From: dh [mailto:d...@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
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:
> 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:d...@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:d...@metrohm.com>
Internet:<http://www.metrohm.com>
It looks like Mathematica already can do this:
In[673]:=
data = Table[{y = RandomComplex[],
RandomReal[{0.9, 1.1}] y^2 + RandomReal[{0.9, 1.1}] y + 1 +
I}, {20}];
In[672]:= Fit[data, {1, x, x^2}, x]
Out[672]= (0.988738 +
0.984148 I) + (1.0509 - 0.0357287 I) x + (1.0156 + 0.0497595 I) x^2
Cheers -- Sjoerd