Skip to content

Instantly share code, notes, and snippets.

@drvinceknight
Last active August 29, 2015 14:07
Show Gist options
  • Save drvinceknight/7d0094eeaeb4aa4508c6 to your computer and use it in GitHub Desktop.
Save drvinceknight/7d0094eeaeb4aa4508c6 to your computer and use it in GitHub Desktop.
There is a nice paper by Cleve Moler and Charles Van Loan called: "Nineteen Dubious Ways to Compute the Exponential of a Matrix" which is a return to a paper (by the same authors) called: "Nineteen Dubious Ways to Compute the Exponential of a Matrix". This interact simply looks at the Series method. The inputs allow control of the number of term…
@interact
def _(A=matrix(RDF,[[1,3,1],[5,-2,2],[3,3,4]]),n=("$n$",slider(0,100,1)),Precision=slider(0,10,1,4)):
exp_A=exp(A)
approx_exp=sum([A^i/factorial(i) for i in range(n+1)]).n(digits=Precision)
p=list_plot([(sum([A^i/factorial(i) for i in range(n+1)])-exp(A)).norm(2) for n in range(0,21)])
p.axes_labels(['$n$','$|| e^{A}-\sum_{i=0}^{n}A^{i}/{i!}||_2$'])
print "\n"
print "Value of approximation for n=%s: \n%s" % (n, approx_exp)
print "\n"
print "Exact value: \n%s" % exp(A)
show(p)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment