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.

A := array(1..2, 1..2):> evalgrid( f, ’A’, 1, 2, 1, 2, 2, 2 ):> eval(A);⎡⎢⎣1sin(1)1 1sin( 3 2 )6.7 Generating Grids of Points • 2691 ⎤sin( 3 2 )⎥sin( 9 ⎦4 )> evalgrid( f, ’A’, 0, Pi, 0, Pi, 15, 15 ):Error, (in f) numeric exception: division by zeroExample 3 The procedure, gridpoints, uses the evalgrid procedure.The procedure accepts a function, two ranges, and the number of gridpoints to generate in each dimension. Like the procedure fnum whichMaple generated from your function f above, this routine attempts tocreate the grid using hardware floating-point arithmetic. Only if this fails,does gridpoints resort to software floating-point arithmetic.> gridpoints := proc( f, r1, r2, m, n )> local u, x, y, z, a, b, c, d;>> # Domain information:> a := lhs(r1); b := rhs(r1);> c := lhs(r2); d := rhs(r2);>> z := hfarray(1..m, 1..n);> if Digits # Try to use hardware floats> # - notice the need for var in this case.> u := traperror( evalhf( evalgrid(f, var(z),> a, b, c, d, m, n) ) );> if lasterror = u then> # Use software floats, first converting f to> # a software float function.> z := array( 1..m, 1..n );> evalgrid( convert( f, numericproc ),> z, a, b, c, d, m, n );> end if;> else> # Use software floats, first converting f to> # a software float function.> z := array( 1..m, 1..n );> evalgrid( convert(f, numericproc), z,> a, b, c, d, m, n );> end if;

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

Saved successfully!

Ooh no, something went wrong!