Re: 3D fitting of data points

• To: mathgroup at smc.vnet.net
• Subject: [mg48465] Re: 3D fitting of data points
• From: "Peter Pein" <petsie at arcor.de>
• Date: Mon, 31 May 2004 00:13:54 -0400 (EDT)
• References: <c99dmp\$k62\$1@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```"Tolonen, Ellen N" <entolonen at utep.edu> schrieb im Newsbeitrag
news:c99dmp\$k62\$1 at smc.vnet.net...
>
> Hello all,
>
> I am trying to fit a set of 3D data points to a polynomial function
> (a(1)x^2 + a(2)y^2+a(3)z^2 + a(4)xy + a(5)xz + a(6)yz + a(7)x + a(8)y +
> a(9)z  - 1 = 0).   Is there a way to do three-dimensional fitting with
> NonLinearFit?  And, if so, how?
>
> Thanks,
>
> Ellen
> entolonen at utep.edu
>
Ellen,
since you are looking for a function f with f(x,y,z)=0, append a zero to
each of your data points and

In[1]:=
<< "Statistics`NonlinearFit`"
In[2]:= data = Flatten[Table[{x, y, 0.1*Random[] - 1.05 + x + y, 0},
{x, -1, 1, 0.1}, {y, -1, 1, 0.1}], 1];
In[3]:= nlf = NonlinearFit[data, a[1]*x^2 + a[2]*y^2 + a[3]*z^2 + a[4]*x*y +
a[5]*x*z + a[6]*y*z + a[7]*x + a[8]*y + a[9]*z - 1, {x, y, z},
a /@ Range[9]]
Out[3]=
-1 + 2.002429552188529*x - 1.0014153336389238*x^2 + 2.000989498625759*y -
2.001875889645282*x*y - 1.0001513532494144*y^2 - 2.0045177528948868*z +
2.0053912122120092*x*z + 2.004072399157397*y*z - 1.0037967040802886*z^2
In[4]:= (* test the fit: *)
(Tr[Abs[#1]] & )[Function[{x, y, z}, Evaluate[nlf]] @@@ data]/Length[data]
Out[4]=
0.000614644

does the job
--
Peter Pein, Berlin
to write to me, start the subject with [

```

• Prev by Date: Re: Date format in Excel
• Next by Date: Re: PlotRange
• Previous by thread: 3D fitting of data points
• Next by thread: Removing non-numeric characters from a list