(3) Numerical Calculations
Before examining this topic, please make sure that you have read: (1) Working Through the New User's Tour .
Use the restart command to clear Maple's internal memory and get started with this topic of the tour.
> restart;
Computations with Integers
At its most basic level, you can use Maple as a very powerful calculator.
To calculate (32)(
), you would enter the following:
> 32*12^13;
Maple recognizes many special operators, including factorial, greatest common divisor, least common multiple, and computation over the integers modulo m . The following line is an example of the factorial operator in use.
> 200!;
You can easily include the previous expansion of
in any subsequent calculation without having to type it. The ditto operator, represented by a percent sign (
%
), refers to the last expression computed by Maple. (For more information on the ditto operator, see the help page for ditto.) The command
ifactor
factors the previous result into its prime factors.
> ifactor(%);
The next command calculates the product again, which is precisely the value of 200!.
> expand(%);
Floating-point Arithmetic
A principal strength of Maple is its ability to do exact arithmetic. Fractions and radicals during computation are not converted to their decimal equivalent, thereby avoiding round-off errors. When you do need to use decimal equivalents, Maple has a command that approximates the value of the expression in a floating-point form.
Consider the expression
, which is entered on the Maple command line as follows:
> (2^30/3^20)*sqrt(3);
Use the evalf command to generate an approximation in the form of a floating-point value.
> evalf(%);
Finite and Infinite Sums and Products
You can calculate both finite and infinite sums.
Consider the finite sum
. You calculate its value as follows:
> sum( (1+i)/(1+i^4), i=1..10 );
Consider the infinite sum
. To calculate its value, enter:
> sum( 1/k^2, k=1..infinity );
Maple also calculates both finite and infinite products.
To evaluate the finite product
, you would enter the following Maple command:
> product( ((i^2+3*i-11)/(i+3)), i=0..10 );
You can do arithmetic with fl oating-point numbers to any desired precision. In fact, Maple handles numbers up to hundreds of thousands of digits of precision on most operating systems. The following command calculates a 50-digit floating-point approximation of the fraction in the previous calculation.
> evalf( % , 50 );
Complex Numbers and Special Functions
Maple also performs calculations using complex numbers. Type the complex unit as a capital I .
> (3+5*I)/(7+4*I);
To easily convert a complex number to its polar-coordinate form, use the
convert
function. Maple represents the expression in the form polar(
), where
r
is the modulus and
is the argument of the complex value of the expression.
> convert( % , polar );
You can compute numeric values for the elementary functions and many special functions and constants. For example, compute
, the base of the natural logarithm, to 40 digits.
> evalf( exp(1.0), 40 );
Consider an example of the Gamma function
:
> evalf( GAMMA(2.5) );
Finally, suppose that you want to evaluate
to 500 digits:
> evalf( Pi, 500 );