{
 "metadata": {
  "name": "",
  "signature": "sha256:a09a62c5ca301d3f63e20ae1ddea45013e338af6b73280fca44334e814ae310d"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from __future__ import division\n",
      "from sympy import *\n",
      "from IPython.display import display, Math, Latex\n",
      "from IPython.core.display import display_html\n",
      "init_session(quiet=True, use_latex='mathjax')\n",
      "init_printing()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "IPython console for SymPy 0.7.6 (Python 2.7.6-32-bit) (ground types: python)\n"
       ]
      }
     ],
     "prompt_number": 1
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "x1,x2,tau,delta = symbols('x1,x2,tau,delta')\n",
      "L11 = symbols('L11', cls=Function)(x1,x2,tau,delta)\n",
      "L12 = symbols('L12', cls=Function)(x1,x2,tau,delta)\n",
      "L21 = symbols('L21', cls=Function)(x1,x2,tau,delta)\n",
      "L22 = symbols('L22', cls=Function)(x1,x2,tau,delta)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Lstar = Matrix([[L11,L12],[L21,L22]])\n",
      "L1star = Lstar.det()\n",
      "deriv1 = L1star.diff(t)\n",
      "deriv2 = (Lstar.adjugate()*Lstar.diff(t)).trace()\n",
      "\n",
      "Mstar = Matrix([[L11,L12],[Lstar.det().diff(x1),Lstar.det().diff(x2)]])\n",
      "\n",
      "deriv1 = Mstar.det().diff(tau)\n",
      "deriv2 = (Mstar.adjugate()*Mstar.diff(tau)).trace()\n",
      "simplify(deriv1-deriv2)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "latex": [
        "$$0$$"
       ],
       "metadata": {},
       "output_type": "pyout",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAAoAAAAOBAMAAADkjZCYAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEJmJdjLNVN0iZu+7\nq0QgoRR7AAAAVklEQVQIHWNgEDJRZWBgSGeQmMDAtYGBOYGB5wID+0cG/gsMfN8Z5BUY+L4wzDdg\nYP0MJeUNQCL8Cgzs3xk4DjBwfWRg2cDAlMDA0M4gHcDAIOxylQEA9FISlFfRJtkAAAAASUVORK5C\nYII=\n",
       "prompt_number": 3,
       "text": [
        "0"
       ]
      }
     ],
     "prompt_number": 3
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "Mstar = Matrix([[0.00112865, 8.76232e-006],[9.57021e-007, 7.42578e-009]])\n",
      "dMstar_dTau = Matrix([[-0.000245724,-0.00118232],[3.20921e-006, -7.171e-008]])\n",
      "adjM = Matrix([[7.42578e-009,-9.57021e-007],[-8.76232e-006, 0.00112865]])\n",
      "(adjM*dMstar_dTau).trace()\n",
      "print Mstar.adjugate()\n",
      "print adjM"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Matrix([[7.42578000000000e-9, -8.76232000000000e-6], [-9.57021000000000e-7, 0.00112865000000000]])\n",
        "Matrix([[7.42578000000000e-9, -9.57021000000000e-7], [-8.76232000000000e-6, 0.00112865000000000]])\n"
       ]
      }
     ],
     "prompt_number": 7
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "a,b,c,d = symbols('a,b,c,d')\n",
      "M = Matrix([[a,b],[c,d]])\n",
      "display(M)\n",
      "M.adjugate()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "latex": [
        "$$\\left[\\begin{matrix}a & b\\\\c & d\\end{matrix}\\right]$$"
       ],
       "metadata": {},
       "output_type": "display_data",
       "png": "iVBORw0KGgoAAAANSUhEUgAAADcAAAAyBAMAAAAKOF7GAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhAiq3bdRLtm\nmc0lg57xAAABSUlEQVQ4Ee3UPUsDMRwG8OdSr9DT1oIuouANDgoO9w0qWPdzFrlu7rp0cOhQEARB\nEHHVT2D9AIqjo4Pgpi7iVBGlDlI4E/LSZ7hmdjDLJfnxz11yD8Fi/omiJvK8jpnmRpEhbK7XMVtI\nanKiGLfmPIg3H355MBp4UBwTlne7p2poW619lLivvWhNflhQz+wV3xbDBVR7jI0U8tj0PqsDVDqM\nTwgdBj1ka4x9RHIzujKL0UBKOoRczGKCm1KL8AebtxZrnakzQYZ9XMuhXjZsL+0cMm4fyEKDPE99\nXUkT3P1HeRpjDyG6uh+PmE48eJl6cMXzTvRHKJa7/LNkyF3AUD7BO6MMuQsYghh7hCrkL27ZZ84l\nVC4rscN5KpPdQIb83KLKPjcTcnN8Q6BEmumQG3xE+EBoQm5QrN6RwYTcIMuo/xfRe6X6LuNfjWlM\nFpMM9N8AAAAASUVORK5CYII=\n",
       "text": [
        "\u23a1a  b\u23a4\n",
        "\u23a2    \u23a5\n",
        "\u23a3c  d\u23a6"
       ]
      },
      {
       "latex": [
        "$$\\left[\\begin{matrix}d & - b\\\\- c & a\\end{matrix}\\right]$$"
       ],
       "metadata": {},
       "output_type": "pyout",
       "png": "iVBORw0KGgoAAAANSUhEUgAAAFMAAAAyBAMAAADSNPrMAAAAMFBMVEX///8AAAAAAAAAAAAAAAAA\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMA74lUMhBEu5ndzSKr\ndmb+gm2XAAABbElEQVRIDWOQ//+JgTBg+v9fgEHYxZWwSgZWF2cBBhEiFIKUsCArTZfArou1cAK6\nUobP2JUycB1AV8r2FYdSfgN0pUwge7CB/ACgKIpbuRqwqQOKaYLEkZTu0fUH2YMNrLnbjKyUTZqh\nHmQPFsD6K4B/A5KpgQ8YurAoAwkxf2XgV0BS2h/AMAlNKevKmUAwy4FjAUM8slJxBtZvaEphXKB3\n8w0QprJ+YmD+wAqTRKX5HzAA7YSHAOtnBvYF1qhKYDz+BFY55BBYy/DygAJMEpXmecDegKw05pL3\n2QRUJTAea+85IBPuAJgwbnpU6WgIDLoQULrrgJZi9+h6QooHNLfuNOBagKoUVJJARNCUCjHwoBVG\nwJKkHVkpvGzALDWBuXouslKYnYwFMBacBpYkX7ApBRY3aACpJEF1K7AYYUB1K1JJgqqU4wBDhAOq\nuYiSBFUpg9K7C6gqGRAlCZpSNHUo3OGrlIRKnvimAwCJ/VUvfMvpJAAAAABJRU5ErkJggg==\n",
       "prompt_number": 11,
       "text": [
        "\u23a1d   -b\u23a4\n",
        "\u23a2      \u23a5\n",
        "\u23a3-c  a \u23a6"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}