newuser,topic03

(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)( 12^13 ), you would enter the following:

> 32*12^13;

3423782572130304

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!;

788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...

You can easily include the previous expansion of 200! 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(%);

``(2)^197*``(3)^97*``(5)^49*``(7)^32*``(11)^19*``(1...
``(2)^197*``(3)^97*``(5)^49*``(7)^32*``(11)^19*``(1...
``(2)^197*``(3)^97*``(5)^49*``(7)^32*``(11)^19*``(1...
``(2)^197*``(3)^97*``(5)^49*``(7)^32*``(11)^19*``(1...
``(2)^197*``(3)^97*``(5)^49*``(7)^32*``(11)^19*``(1...

The next command calculates the product again, which is precisely the value of 200!.

> expand(%);

788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...
788657867364790503552363213932185062295135977687173...

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 2^30/(3^20)*sqrt(3) , which is entered on the Maple command line as follows:

> (2^30/3^20)*sqrt(3);

1073741824/3486784401*sqrt(3)

Use the evalf command to generate an approximation in the form of a floating-point value.

> evalf(%);

.5333783739

Finite and Infinite Sums and Products

You can calculate both finite and infinite sums.

Consider the finite sum sum((1+i)/(1+i^4),i = 1 .. 10) . You calculate its value as follows:

> sum( (1+i)/(1+i^4), i=1..10 );

51508056727594732913722/40626648938819200088497

Consider the infinite sum sum(1/(k^2),k = 1 .. infinity) . To calculate its value, enter:

> sum( 1/k^2, k=1..infinity );

1/6*Pi^2

Maple also calculates both finite and infinite products.

To evaluate the finite product product((i^2+3*i-11)/(i+3),i = 0 .. 10) , you would enter the following Maple command:

> product( ((i^2+3*i-11)/(i+3)), i=0..10 );

-7781706512657/40435200

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 );

-192448.8196585400838873061095283317505539727761950...

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);

41/65+23/65*I

To easily convert a complex number to its polar-coordinate form, use the convert function. Maple represents the expression in the form polar( r, theta ), where r is the modulus and theta is the argument of the complex value of the expression.

> convert( % , polar );

polar(1/65*sqrt(2210),arctan(23/41))

You can compute numeric values for the elementary functions and many special functions and constants. For example, compute exp(1) , the base of the natural logarithm, to 40 digits.

> evalf( exp(1.0), 40 );

2.718281828459045235360287471352662497757

Consider an example of the Gamma function GAMMA(2.5) :

> evalf( GAMMA(2.5) );

1.329340388

Finally, suppose that you want to evaluate Pi to 500 digits:

> evalf( Pi, 500 );

3.1415926535897932384626433832795028841971693993751...
3.1415926535897932384626433832795028841971693993751...
3.1415926535897932384626433832795028841971693993751...
3.1415926535897932384626433832795028841971693993751...
3.1415926535897932384626433832795028841971693993751...
3.1415926535897932384626433832795028841971693993751...
3.1415926535897932384626433832795028841971693993751...
3.1415926535897932384626433832795028841971693993751...
3.1415926535897932384626433832795028841971693993751...

Click here to return to the Main Menu.

© 2009 by the Rector and Visitors of the University of Virginia.

The information contained on the University of Virginia’s Department of Information Technology and Communication (ITC) website is provided as a public service with the understanding that ITC makes no representations or warranties, either expressed or implied, concerning the accuracy, completeness, reliability or suitability of the information, including warrantees of title, non-infringement of copyright or patent rights of others. These pages are expected to represent the University of Virginia community and the State of Virginia in a professional manner in accordance with the University of Virginia’s Computing Policies.