Re: 3D fitting of data points
- To: mathgroup at smc.vnet.net
- Subject: [mg48499] Re: [mg48433] 3D fitting of data points
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Wed, 2 Jun 2004 04:22:12 -0400 (EDT)
- References: <200405290706.DAA20433@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Tolonen, Ellen N wrote: > 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 You are probably better off using a linear fit. THis can be done as below. We start with data points with random fluctuation from a particular polynomial in three variables. data = Table[Module[{x,y,z}, {x,y,z} = Table[Random[Real,{-5,5}],{3}]; {x,y,z,3*x^2+2*y^2-z^2+4*x*y-7*x*z-2*y*z-x+6*y+2*z-1+.05*Random[]}], {50}]; Now do the fit. vars = {x,y,z}; basis = {x^2,y^2,z^2,x*y,x*z,y*z,x,y,z,1}; ffit = Fit[data, basis, vars]; last normalize so the constant term is -1 as per specification. const = ffit /. {x->0,y->0,z->0}; Expand[-ffit/const] YOu might also use FindFit to get the results for the fit parameters in a possibly more convenient form. Daniel Lichtblau Wolfram Research