{ "metadata": { "kernelspec": { "codemirror_mode": { "name": "ipython", "version": 2 }, "display_name": "IPython (Python 2)", "language": "python", "name": "python2" }, "language": "Julia", "name": "", "signature": "sha256:be80c8cb39f94627c7d42bf36d7e20788fe426b17ec2d2e7a1ef3b376c54bf0c" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 3, "metadata": {}, "source": [ "Let A be the matrix below" ] }, { "cell_type": "code", "collapsed": false, "input": [ "A=[5 9 -4 3 4;\n", " -2 -6 0 -9 -4;\n", " 1 2 -2 -8 -7;\n", " 2 -5 -8 5 -7;\n", " -6 -7 1 -3 -3]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 1 }, { "cell_type": "markdown", "metadata": {}, "source": [ "1. Consider the following functions
\n", "f(x) = exp(x)
\n", "f(x) = 2/x + 3 + 5x^3
\n", "f(x) = x*exp(x)

\n", "\n", "For each function compute a matrix that has the same eigenvectors as A, but\n", "whose eigenvalues are f(lambda) where lambda is an eigenvalues of A. Verify\n", "that the eigenvalues are as you expect. Make sure you understand what is going\n", "on. Note that in Julia and MATLAB, expm is the matrix exponential, while exp\n", "is the element-wise exponential.\n", "\n", "Turn in your eigenvalue computation and the function applied to the eigenvalues:
\n", "\n", "\n", "2. The third function f(x) = x*exp(x) is the derivative of exp(tx) with respect to t, at t=1.
\n", "What is the corresponding matrix derivative? Do a simple finite difference to compute the matrix\n", "derivative that is accurate to three or four places." ] }, { "cell_type": "code", "collapsed": false, "input": [ "\u03bb=eigvals(A) # Note: You can type \\lambda for the character \u03bb" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "s=v->sort(v,by=real) # create a simple sort_by_real_part function" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "#1. f(x)=exp(x)\n", "[eigvals(expm(A)) exp(\u03bb)]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "#sorting by real part makes it easier to see\n", "[s(eigvals(expm(A))) s(exp(\u03bb))]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "#2. f(x) = 2/x + 3 + 5x^3 \n", "[s(eigvals(2*inv(A) + 3*I + 5*A^3)) s(2./\u03bb+3+5*\u03bb.^3)]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "#3. f(x)= x*exp(x) \n", "[s(eigvals(A*expm(A))) s(\u03bb.*exp(\u03bb))]" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "A*expm(A)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "#Finite Difference Approximation to d/dt exp(At) at t=1\n", "h=.000001\n", "t=1\n", "(expm(A*t*(1+h))-expm(A*t))/h" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }