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.

72 • Chapter 3: <strong>Programming</strong> with Modulesz := module()export re, i, j, k;option record ;end moduleIn this example, z represents the quaternion 2 + 3i + 2j + √ 5k (wherei, j, and k are the nonreal quaternion basis units). The quaternion recordscan now be manipulated as single quantities. The following procedure acceptsa quaternion record as its sole argument and computes the Euclideanlength of the quaternion that the record represents.> qnorm := proc( q )> use re = q:-re, i = q:-i, j = q:-j, k = q:-k in> sqrt( re * re + i * i + j * j + k * k )> end use> end proc:> qnorm( z );√22A Maple type for quaternions can be introduced as a structured recordtype.> ‘type/quaternion‘ := ’record( re, i, j, k )’:> type( z, ’quaternion’ );true3.3 PackagesModules are ideal for writing Maple packages. They provide facilities forlarge software projects that are better than table and procedure basedmethods.What Is a PackageA package is a collection of procedures and other data, that can be treatedas a whole. Packages typically gather a number of procedures that enableyou to perform computations in some well-defined problem domain. Packagesmay contain data other than procedures, and may even contain otherpackages (subpackages).

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

Saved successfully!

Ooh no, something went wrong!