[SciPy-user] using linalg.lstsq
Mitchell Timin
zenguyuno at yahoo.com
Thu May 11 00:00:45 EDT 2006
--- Bill Baxter <wbaxter at gmail.com> wrote:
> Try this:
>
> # x y
> A = array([[ 0., 0.],
> [ 0., 1.],
> [ 1., 0.],
> [ 1., 1.]])
> A = hstack( (A, ones((A.shape[0],1)) ))
> z = array([.5,.6,.4,.55])
> c = scipy.linalg.lstsq(A,z)[0]
<snip>
That seems to work. I made it into this program:
----------------------------------------------
from scipy import *
A = array([[ 0., 0.],
[ 0., 1.],
[ 1., 0.],
[ 1., 1.]])
A = hstack( (A, ones((A.shape[0],1)) ))
z = array([.5,.6,.4,.55])
print "A"
print A
print
print "z"
print z
print
(X, resids, rank, s) = linalg.lstsq(A,z)
print "X"
print X
print
print "resids"
print resids
print
print "rank"
print rank
print
print "s"
print s
print
print "calculate z at original points:"
print X[0]
print X[0] + X[1]
print X[0] + X[2]
print X[0] + X[1] + X[2]
----------------------------------------------
and it produced this result:
----------------------------------------------
A
[[ 0. 0. 1.]
[ 0. 1. 1.]
[ 1. 0. 1.]
[ 1. 1. 1.]]
z
[ 0.5 0.6 0.4 0.55]
X
[-0.075 0.125 0.4875]
resids
0.000625
rank
3
s
[ 2.5243378 1. 0.79228699]
calculate z at original points:
-0.075
0.05
0.4125
0.5375
----------------------------------------------
I can't tell if that answer is correct. I will create a better test case to
make it obvious.
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