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.

260 • Chapter 6: <strong>Programming</strong> with Maple Graphics> xscale := evalf( dx/2/L^(1/2) );> yscale := evalf( dy/2/L^(1/2) );> mscale := max(xscale, yscale);>> # Generate plot data structure.> # Each arrow is centered over its point.> PLOT( seq( seq( myarrow(> [ a + (i-1)*dx - vect1[j][i]*xscale/2,> b + (j-1)*dy - vect2[j][i]*yscale/2 ],> [ vect1[j][i]*xscale, vect2[j][i]*yscale ],> mscale/4, mscale/2, 1/3 ), i=1..m), j=1..n) );> # Thickness of tail = mscale/4> # Thickness of head = mscale/2> end proc:Example 4 With these utility functions, you can make the first vectorfieldplotcommand by putting them all together.> vectorfieldplot := proc(F, r1, r2, m, n)> local vect1, vect2, a, b, dx, dy;>> # Generate each component over the grid of points.> vect1 := convert( F[1], grid, r1, r2 ,m, n );> vect2 := convert( F[2], grid, r1, r2 ,m, n );>> # Obtain the domain grid information from r1 and r2.> a,b,dx,dy := domaininfo(r1, r2, m, n);>> # Generate the final plot structure.> generateplot(vect1, vect2, m, n, a, b, dx, dy)> end proc:Try the procedure on the vector field (cos(xy), sin(xy)).> p := (x,y) -> cos(x*y): q := (x,y) -> sin(x*y):> vectorfieldplot( [p, q], 0..Pi, 0..Pi, 15, 20 );32.521.510.500.5 1 1.5 2 2.5 3Example 5 The vectorfieldplot code shows how to write a procedurethat generates vector field plots based on alternative descriptions of the

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

Saved successfully!

Ooh no, something went wrong!