[SciPy-user] using linalg.lstsq

Mitchell Timin zenguyuno at yahoo.com
Wed May 10 22:43:50 EDT 2006


--- Alan Isaac <aisaac at american.edu> wrote:

> On Wed, 10 May 2006, Mitchell Timin wrote: 
> > suppose I have, say, half a dozen points in 3-space.  
> > I want to find values for c1, c2 & c3 so that x3 = c1*x1 
> > + c2*x2 + c3 passes close to all the points in the least 
> > square sense. 
> > I think that linalg.lstsq will solve that problem, but I don't know how to set it
> up. 
> 
> First look at the help:
<snip>
Yes, I looked at the help.

> In your case b=x3 and A holds the other data.
> So with 10 observations, for example, to get [c1,c2,c3]
> you can do something like
> >>> c=N.ones((10,1))
> >>> A=N.hstack([x1,x2,c])
> >>> N.linalg.lstsq(A,x3)[0]

That doesn't work.  It seems I have not explained the problem clearly.  x1, x2 & x3 are
scalars, representing x, y & z.  This refers to the usual x,y plane, and z is the height
above the plane.  We are given four or more points.  Each point is an example of x, y &
z, and they might all be put into a matrix in some way. (I don't know how.) 
What we seek are values for three coefficients, call them a, b & c, so that the plane
described by z = a*x + b*y + c passes as close as possible to all of the given points.
("close as possible" meaning that the sum of the squared errors is minimized.)

thanks,



Mitchell Timin

I'm proud of http://ANNEvolve.sourceforge.net.  If you want to write software, or articles, or do testing, or research for ANNEvolve, let me know.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 




More information about the SciPy-User mailing list