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.

222 • Chapter 6: <strong>Programming</strong> with Maple GraphicsExample 1 The ribbonplot procedure uses the display procedure fromthe plots package to display the plots. This procedure is called explicitlyusing its full name so that ribbonplot works even when the short formsof the function names in the plots package have not been loaded.The hasoption command helps you handle options. In the ribbonplotprocedure, hasoption returns false if numpoints is not among the optionslisted in opts. If opts contains a numpoints option, then hasoptionassigns the value of the numpoints option to n, and returns the remainingoptions in the fourth argument (in this case, modifying the value of thelist opts).> ribbonplot := proc( Flist, r1::name=range )> local i, m, p, y, n, opts;> opts := [ args[3..nargs] ];> if not hasoption( opts, ’numpoints’, ’n’, ’opts’ )> then n := 25 # default numpoints> end if;>> m := nops( Flist );> # op(opts) is any additional options> p := seq( plot3d( Flist[i], r1, y=(i-1)..i,> grid=[n, 2], op(opts) ),> i=1..m );> plots[display]( p );> end proc:The ribbonplot procedure uses the number of grid points you request.> ribbonplot( [cos(x), cos(2*x), sin(x), sin(2*x)],> x=-Pi..Pi, numpoints=16 );The input to ribbonplot must be a list of expressions. Extendribbonplot so that it also accepts a list of functions. One difficulty withthis extension is that you need to create two-dimensional functions fromone-dimensional functions, something that was not required in the initial

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

Saved successfully!

Ooh no, something went wrong!