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.

268 • Chapter 6: <strong>Programming</strong> with Maple Graphicsnot always possible. In the case of f, the function is undefined wheneverx = 0 or y = 0. In such cases, the procedure fnum returns the nameundefined. The Maple plot display routines recognize this special name.At the point (1, 1), the function f has the value 1/ sin(1) and so fnumreturns a numerical estimate.> fnum(1,1);1.18839510577812123However, if you instead try to evaluate this same function at (0, 0),Maple informs you that the function is undefined at these coordinates.> fnum(0,0);undefinedSummary Creating such a procedure is the first step in creating the gridof values. For reasons of efficiency, you should, when possible, computethe function values and the grid points by using hardware floating-pointarithmetic. In addition, you should do as much computation as possible ina single call to evalhf. Whenever you use hardware floating-point arithmetic,Maple must first convert the expression to a series of commandsof hardware floating-point numbers, and then convert the result of theseback to the Maple format for numbers.Example 2 The following procedure generates the coordinates of thegrid in the form of an array. Since the procedure is to plot surfaces, thearray is two-dimensional. The procedure returns an array z of functionvalues.> evalgrid := proc( F, z, a, b, c, d, m, n )> local i, j, dx, dy;>> dx := (b-a)/m; dy := (d-c)/n;> for i to m do> for j to n do> z[i, j] := F( a + (i-1)*dx, c + (j-1)*dy );> end do;> end do;> end proc:This evalgrid procedure is purely symbolic and does not handle errorconditions.

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

Saved successfully!

Ooh no, something went wrong!