       Re: Fit[]: how to obtain the parameter values?

• To: mathgroup at smc.vnet.net
• Subject: [mg31849] Re: Fit[]: how to obtain the parameter values?
• From: "Robert Nowak" <robert.nowak at ims.co.at>
• Date: Fri, 7 Dec 2001 05:56:41 -0500 (EST)
• References: <9ul2bt\$6lu\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Hope one the following helps you
Robert

In:=
f1[x]=2;
f2[x]=3 x;

In:=
data = {{1, 2}, {2, 2.5}, {3, 3}};

In:=
Fit[data, {f1[x], f2[x]}, x]//CoefficientList[#,x]&
Out=
{1.5,0.5}
(* ?????????? wondering if the above result is correct or is it a
mathemeatica bug ??????????? *)

In:=
Fit[data, {1,x}, x]//CoefficientList[#,x]&
Out=
{1.5,0.5}
(* correct linear fit calulation but perhaps not what you want *)

In:=
<<Statistics`LinearRegression`

In:=
BestFitParameters/.Regress[data, {1,x},
x,RegressionReport->BestFitParameters]
Out=
{1.5,0.5}
(* correct linear fit calulation but perhaps not what you want *)

In:=
BestFitParameters/.Regress[data, {f1[x],f2[x]}, x,
RegressionReport->BestFitParameters]
Out=
{0.75,0.166667}
(* !!!! this should your correct solution !!!!! *)

--
---
Robert Nowak (robert.nowak at ims.co.at)
IMS Nanofabrication GmbH
A-1020 Wien, Schreygasse 3, Austria
Phone: (+43 1)2144894-32, Fax: (+43 1)2144894-99

"Peter Marzlin" <peter.marzlin at uni-konstanz.de> wrote in message
news:9ul2bt\$6lu\$1 at smc.vnet.net...
> Hi all,
>
> I am trying to use Fit to get a linear least square fit with some
> complicated functions. In principle this works fine, but I cannot
> get the parameter values.
>
> For instance, using the two functions
>
> f1[x] = 2    and    f2[x] = 3x
>
> I would like to get the parameters a1 and a2 in the fit function
>
> f[x] = a1 f1[x] + a2 f2[x]
>
> for the set of data     data = {{1, 2}, {2, 2.5}, {3, 3}}
>
>
> Using the command
>
> Fit[data, {f1[x], f2[x]}, x]
>
> I get the answer 1.5 + 0.5 x
>
>
> This is correct but not what I want. I need a1 and a2, but
> they cannot easliy be obtained because Fit merges the prefactors
> in the definition of f1 and f2 with the value of the parameters
> a1 and a2.
>
> Of course, in this simple example I can get a1 and a2 by hand, but
> I am actually interested in a much more involved problem where
> extracting
> the parameter values from the Fit output is a rather tedious if not
>
> Any help would be greatly appreciated.
>
> Peter
>

```

• Prev by Date: Re: Fit[]: how to obtain the parameter values?
• Next by Date: Re: Fourier: Execution time for real and complex arguments
• Previous by thread: Re: Fit[]: how to obtain the parameter values?
• Next by thread: Fourier: Execution time for real and complex arguments