Algorithmic Differentiation in Python with Application Examples
Algorithmic Differentiation in Python with Application Examples
Algorithmic Differentiation in Python with Application Examples
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Why not Symbolic <strong>Differentiation</strong> (cont)<br />
Compute recursively x (k) , v (k) = F(x (k−1) , v (k−1) ) as symbolic<br />
expression<br />
Use sum,product and cha<strong>in</strong>rule to compute the wanted derivative<br />
Problem: Expression swell (show live example)<br />
import p y l a b ; import numpy ; from numpy import s q r t , dot , cos , s i n , pi , l i n<br />
import sympy ; from sympy import s q r t<br />
def F ( x , v ) :<br />
””” computes next r e f l e c t i o n p o i n t x and d i r e c t i o n v ”””<br />
c = d o t ( v , v )<br />
x2 = [ x [ 0 ] + v [ 0 ] ∗ ( s q r t ( ( d o t ( x , v ) / c )∗∗2 −( d o t ( x , x ) − 1 . ) / c)− d o t ( x , v ) / c ) ,<br />
x [ 1 ] + v [ 1 ] ∗ ( s q r t ( ( d o t ( x , v ) / c )∗∗2 −( d o t ( x , x ) − 1 . ) / c)− d o t ( x , v ) / c ) ]<br />
w = x2<br />
v2 = [ ( v [ 0 ] − 2∗ w[ 0 ] ∗ d o t (w, v ) / d o t (w,w) ) ,<br />
( v [ 1 ] − 2∗ w[ 1 ] ∗ d o t (w, v ) / d o t (w,w ) ) ]<br />
return x2 , v2<br />
x1 , x2 , v1 , v2 = sympy . symbols ( ’ x1 ’ , ’ x2 ’ , ’ v1 ’ , ’ v2 ’ )<br />
x = [ x1 , x2 ] ; v = [ v1 , v2 ]<br />
x , v = F ( x , v )<br />
p r i n t ’x , v=\n ’ , x , v<br />
#x , v = F ( x , v )<br />
Sebastian # p rF. i Walter, n t ’x Humboldt-Universität , v=\n ’ , x , v zu Berl<strong>in</strong> <strong>Algorithmic</strong> () <strong>Differentiation</strong> <strong>in</strong> <strong>Python</strong> <strong>with</strong> <strong>Application</strong> <strong>Examples</strong>Wednesday, 10.07.2010 6 / 27