11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

2.5 Extending Maple • 37Extending CommandsIf you introduce your own data structures, there are no manipulation rulesfor them. In most cases, you write special-purpose procedures that manipulatenew data structures. However, sometimes extending the capabilitiesof one or more of Maple’s built-in commands is easier than developingnew data structures and special-purpose procedures. You can extend severalMaple commands, among them expand, simplify, diff, series,and evalf.Extending the Diff Command You can represent a polynomial a n u n +a n−1 u n−1 + · · · + a 1 u + a 0 by using the data structurePOLYNOM( u, a_0, a_1, ..., a_n )You can then extend the diff command so that you can differentiatepolynomials represented in that way. If you write a procedure with aname of the form ‘diff/F‘ then diff invokes it on any unevaluatedcalls to F. Specifically, if you use diff to differentiate F(arguments)with respect to x, then diff invokes ‘diff/F‘ as follows.‘diff/F‘( arguments, x )The following procedure differentiates a polynomial in u with constantcoefficients with respect to x.> ‘diff/POLYNOM‘ := proc(u)> local i, s, x;> x := args[-1];> s := seq( i*args[i+2], i=1..nargs-3 );> ’POLYNOM’(u, s) * diff(u, x);> end proc:> diff( POLYNOM(x, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), x );POLYNOM(x, 1, 2, 3, 4, 5, 6, 7, 8, 9)> diff( POLYNOM(x*y, 34, 12, 876, 11, 76), x );POLYNOM(x y, 12, 1752, 33, 304) y

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

Saved successfully!

Ooh no, something went wrong!