11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

62 • Chapter 3: <strong>Programming</strong> with Modules> end if> elif type( expr, ’‘*‘’ ) then> a, b := op( 1, expr ), subsop( 1 = 1, expr );> procname( a, var ) * b + a * procname( b, var )> elif type( expr, ’function’ ) and nops( expr ) = 1 then> # functions of a single variable; chain rule> b := op( 0, expr ); # the name of the function> a := op( 1, expr ); # the argument> if b = ’sin’ then> cos( a ) * procname( a, var )> elif b = ’cos’ then> -sin( a ) * procname( a, var )> elif b = ’exp’ then> exp( a ) * procname( a, var )> elif b = ’ln’ then> ( 1 / a ) * procname( a, var )> else> ’procname( args )’> end if> else> ’procname( args )’> end if> end proc:This uses the chain rule to compute the derivatives of calls to knownfunctions.> differentiate( sin( x ) + cos( exp( x ) ), x );cos(x) − sin(e x ) e x> differentiate( sin( x^2 ) + cos( x^2 ), x );2 cos(x 2 ) x − 2 sin(x 2 ) x> differentiate( sin( x )^2 + cos( x )^3, x );2 sin(x) cos(x) − 3 cos(x) 2 sin(x)At the same time, this has also improved the handling of expressionsindependent of the variable of differentiation.> differentiate( a*x^2 + b*x + c, x );2 a x + b

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!