Productivity Sync

February 20, 2010

Using ipython and numpy to do simple linear algebra computations

Filed under: Uncategorized — markgross @ 5:16 pm

Every once in a while I need to solve a linear equation and I spend WAY too much time farting around looking for how to do it or attempting to do it by hand. (at one time I have programmed these things but I have long forgotten the details…)

Anyway enter ipython and numpy:
run ipython and have at it:

ipython -p numeric

import numpy
M = numpy.matrix([[a11, a12],[a21,a22]]) # the aij are Floats.
b = numpy.matrix([b1,b2]).T # the bj are floats
numpy.linalg.solve(M,b)

easy peesy.

while your at it if you want to make a graph try:

x = array([float(i)*pi/200 for i in xrange(1000)])
y = array([float(i)*pi/100 for i in xrange(1000)])

plot(x,sin(x),x, sin(y))
plot(sin(x), sin(y))

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress