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.

6.2 <strong>Programming</strong> with Plotting Library Functions • 223examples of ribbonplot. For this you can create an auxiliary procedure,extend, which uses of the unapply command.> extend := proc(f)> local x,y;> unapply(f(x), x, y);> end proc:For example, the extend procedure converts the R → R functionx ↦→ cos(2x) to a R 2 → R function.> p := x -> cos(2*x):> q := extend(p);q := (x, y) → cos(2 x)Example 2The following gives the new ribbonplot code.> ribbonplot := proc( Flist, r1::{range, name=range} )> local i, m, p, n, opts, newFlist;> opts := [ args[3..nargs] ];> if type(r1, range) then> # Functional input.> if not hasoption( opts, ’numpoints’, ’n’, ’opts’ )> then n := 25 # default numpoints> end if;> m := nops( Flist );> # change plot3d for functional input> p := seq( plot3d( extend( Flist[i] ), r1, (i-1)..i,> grid=[n,2], op(opts) ),> i=1..m );> plots[display]( p );> else> # Expressions. Convert each to a function of lhs(r1).> newFlist := map( unapply, Flist, lhs(r1) );> # Use lhs(r1) as the default x-axis label.> opts := [ ’labels’=[lhs(r1), "", "" ],> args[3..nargs] ];> ribbonplot( newFlist, rhs(r1), op(opts) )> end if> end proc:Here is a ribbon plot of three functions.> ribbonplot( [cos, sin, cos + sin], -Pi..Pi );

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

Saved successfully!

Ooh no, something went wrong!