In [1]:
x = ones(3)


Out[1]:
3-element Array{Float64,1}:
 1.0
 1.0
 1.0

In [2]:
norm(x)


Out[2]:
1.7320508075688772

In [3]:
A = eye(3)


Out[3]:
3×3 Array{Float64,2}:
 1.0  0.0  0.0
 0.0  1.0  0.0
 0.0  0.0  1.0

In [7]:
A = [1.0 2.0; 3.0 4.0]


Out[7]:
2×2 Array{Float64,2}:
 1.0  2.0
 3.0  4.0

In [8]:
det(A)


Out[8]:
-2.0

In [9]:
Ainv = inv(A)


Out[9]:
2×2 Array{Float64,2}:
 -2.0   1.0
  1.5  -0.5

In [10]:
A* Ainv


Out[10]:
2×2 Array{Float64,2}:
 1.0          0.0
 8.88178e-16  1.0

In [11]:
y = ones(2,1)


Out[11]:
2×1 Array{Float64,2}:
 1.0
 1.0

In [13]:
x = Ainv * y


Out[13]:
2×1 Array{Float64,2}:
 -1.0
  1.0

In [14]:
x = A /y


DimensionMismatch("left hand side has 1 rows, but right hand side has 2 rows")

 in \(::Base.LinAlg.QRPivoted{Float64,Array{Float64,2}}, ::Array{Float64,2}) at ./linalg/qr.jl:654
 in \(::Array{Float64,2}, ::Array{Float64,2}) at ./linalg/generic.jl:363
 in /(::Array{Float64,2}, ::Array{Float64,2}) at ./linalg/generic.jl:367
 in include_string(::String, ::String) at ./loading.jl:441

In [15]:
evals, evecs = eig(A)


Out[15]:
([-0.372281,5.37228],
[-0.824565 -0.415974; 0.565767 -0.909377])

In [18]:
#here we try and miplement gram schmidt orthogonalisation for fun and testing

#params: X - an nxk array with linearly idnependent columns
#return U: an nxk array with orthonormal columns

function gram_schmidt(X)
    n,k = size(X)
    #we create our array to put everything in
    U = Array{Float64}(n,k)
    I = eye(n)
    
    #first col of u is just normalised first col of x
    v1 = X[:,1]
    U[:,1] = v1/norm(v1)
    
    #okay, now we begin the proper loop
    for i in 2:k
        #set up
        b = X[:i] #get the col we want
        Z = X[:, 1:i-1] # te first i-1 columns of X - i.e. the ones we've already sorted
        
        #we project onto orthogonal complement of the col span of Z
        M = I - Z *inv(Z' *Z)*Z' # this is the standard forumal
        u = M*b
        #and normalize
        U[:,i] = u/norm(u)
    end
    return U
end

#not THAT difficult of a function. and it doesn't need any crazy numpy stuff to go 
# fast either,  don't think. so that's very good indeed.


Out[18]:
gram_schmidt (generic function with 1 method)

In [19]:
#now some testing
y = [1 3 -3]'
X = [1 0; 0 -6; 2 2]

Py1 = X*inv(X'X)*X' *y

#gram schmidt
U = gram_schmidt(X)


indexing Array{Int64,2} with types Tuple{Symbol} is not supported

 in gram_schmidt(::Array{Int64,2}) at ./In[18]:19
 in include_string(::String, ::String) at ./loading.jl:441

In [20]:
Q, R = qr(X)


Out[20]:
(
[-0.447214 -0.131876; 0.0 -0.989071; -0.894427 0.065938],

[-2.23607 -1.78885; 0.0 6.0663])

In [ ]: