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.6 Vector Field Plots • 259> end proc:Here is an example using multiple assignments to assign the four valuesreturned to separate variables.> a, b, dx, dy := domaininfo( 0..12, 20..100, 7, 9);a, b, dx, dy := 0, 20, 2., 10.Now a, b, dx, and dy have the following values.> a, b, dx, dy;0, 20, 2., 10.Example 2 For the conversion to a grid of numerical points, you cantake advantage of the extensibility of the Maple convert command. Theprocedure ‘convert/grid‘ takes a function f as input and evaluates itover the grid which r1, r2, m, and n specify.> ‘convert/grid‘ := proc(f, r1, r2, m, n)> local a, b, i, j, dx, dy;> # obtain information about domain> a,b,dx,dy := domaininfo( r1, r2, m, n );> # output grid of function values> [ seq( [ seq( evalf( f( a + i*dx, b + j*dy ) ),> i=0..(m-1) ) ], j=0..(n-1) ) ];> end proc:Now you can evaluate the undefined function, f, on a grid as follows.> convert( f, grid, 1..2, 4..6, 3, 2 );[[f(1., 4.), f(1.500000000, 4.), f(2.000000000, 4.)],[f(1., 6.), f(1.500000000, 6.), f(2.000000000, 6.)]]Example 3 The final utility procedure determines the scalings which ensurethat the arrows do not overlap. Then generateplot calls the myarrowprocedure to draw the vectors. Note that generateplot moves the originof each arrow to center it over its grid-point.> generateplot := proc(vect1, vect2, m, n, a, b, dx, dy)> local i, j, L, xscale, yscale, mscale;>> # Determine scaling factors.> L := max( seq( seq( vect1[j][i]^2 + vect2[j][i]^2,> i=1..m ), j=1..n ) );

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

Saved successfully!

Ooh no, something went wrong!