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.

274 • Chapter 6: <strong>Programming</strong> with Maple GraphicsMethods for Creating AnimationsThe Maple library provides three methods for creating animations: theanimate and animate3d commands in the plots package, and thedisplay command with the insequence = true option set. For example,you can show how a Fourier series approximates a function,f, on an interval [a, b] by visualizing the function and successive approximationsas the number of terms increase with each frame. Youcan derive the nth partial sum of the Fourier series by using f n (x) =c 0 /2 + ∑ nk=1 c k cos( 2πb−a kx) + s k sin( 2πb−akx), whereandc k = 2b − as k = 2b − a∫ ba∫ ba( ) 2πf(x) cosb − a kx dx( ) 2πf(x) sinb − a kx dx.Example The fourierPicture procedure first calculates and plots thekth Fourier approximation for k up to n. Then fourierPicture generatesan animation of these plots, and finally it adds a plot of the function asa backdrop.> fourierPicture :=> proc( func, xrange::name=range, n::posint)> local x, a, b, l, k, j, p, q, partsum;>> a := lhs( rhs(xrange) );> b := rhs( rhs(xrange) );> l := b - a;> x := 2 * Pi * lhs(xrange) / l;>> partsum := 1/l * evalf( Int( func, xrange) );> for k from 1 to n do> # Generate the terms of the Fourier series of func.

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

Saved successfully!

Ooh no, something went wrong!