Skip to content

Instantly share code, notes, and snippets.

@mongrelP
Created June 20, 2011 09:06
Show Gist options
  • Save mongrelP/1035343 to your computer and use it in GitHub Desktop.
Save mongrelP/1035343 to your computer and use it in GitHub Desktop.
Vector_Function
#Licence:NYSL
#http://www.kmonos.net/nysl/
#
class Matrix
def []=(i,j,x)
@rows[i][j]=x
end
end
class Vector
#Vector#normalize
def normalize
self/(self.r)
end
#test code
# v=Vector[1,2,3]
# p v
# p v.r
# p v.normalize
# p v.normalize.r #=> 1.0
#Vector#normalize!
def normalize!
self.replace(self.normalize)
end
#test code
# v=Vector[1,2,3]
# p v.normalize!
# p v.r #=> 1.0
#Vector#outer_product
def outer_product(other)
rtn=Matrix.[]
self.size.times{|i|
other.size.times{|j|
rtn[i,j]=self[i]*other[j]
}
}
return rtn
end
#test code
#(not yet)
#Vector#exterior_product
def exterior_product(other)
self.outer_product(other)-other.outer_product(self)
end
#test code
#(not yet)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment