help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

newbie : trouble with calculating inverse of a matrix and = inf ???


From: Andy Davidson
Subject: newbie : trouble with calculating inverse of a matrix and = inf ???
Date: Tue, 23 Apr 2013 09:13:33 -0700
User-agent: Microsoft-MacOutlook/14.3.2.130206

I am trying to calculate the inverse of a matrix. I get this strange answer. Any idea what my problem is? Is there some sort of reference for these kinds of problems?

octave:15> x = [x0' x1' x2']
x =

   1   1   4
   1   2   5
   1   3   6

octave:16> inv(x' * x) 
warning: inverse: matrix singular to machine precision, rcond = 0
ans =

   Inf   Inf   Inf
   Inf   Inf   Inf
   Inf   Inf   Inf


Here is a complete diary of what I am trying to do

thanks in advance

Andy

#
# Least Sq. Regresion
# calculate the paramters for theta using closed form solution
# theta = inv(x' * x) * x' * y
#


#
# create a simple data set from the equation y = 3 + x1 + 2x2 
# to make sure we understand basic linear algebra in Octave
#

octave:2> x1 = [ 1 2 3]
x1 =

   1   2   3

octave:3> x2 = [ 4 5 6];
octave:4> y = 3 + x1 + 2*x2
y =

   12   15   18

#
# create a row vector theta. We already know the parameters of the eq.
#

octave:6> theta = [3; 1; 2]
theta =

   3
   1
   2


octave:10> x = [1 6 7]; # create a new training example
octave:11> x * theta # the expected answer should be 23
ans =  23

#
# begin closed form solution for theta
#

octave:12> x1
x1 =

   1   2   3

octave:13> x2
x2 =

   4   5   6

octave:14> x0 = [1 1 1]
x0 =

   1   1   1


octave:15> x = [x0' x1' x2']
x =

   1   1   4
   1   2   5
   1   3   6

octave:16> inv(x' * x) 
warning: inverse: matrix singular to machine precision, rcond = 0
ans =

   Inf   Inf   Inf
   Inf   Inf   Inf
   Inf   Inf   Inf

octave:17> diary off


reply via email to

[Prev in Thread] Current Thread [Next in Thread]