Contents Previous Next Index

4 Basic Computations


This chapter discusses key concepts related to performing basic computations with Maple. It discusses important features that are relevant to all Maple users. After learning about these concepts, you will learn how to use Maple to solve problems in specific mathematical disciplines in the following chapter.

4.1 In This Chapter


Section

Topics

Symbolic and Numeric Computation An overview of exact and floatingpoint computation

•

FloatingPoint Computations

•

Converting Exact Quantities to FloatingPoint Values


Integer Operations  How to perform integer computations

•

Important Integer Commands

•

Finite Rings and Fields


Solving Equations  How to solve standard mathematical equations

•

Equations and Inequations

•

Ordinary Differential Equations

•

Partial Differential Equations

•

Integer Equations in a Finite Field


Units, Scientific Constants, and Uncertainty  How to construct and compute with expressions that have units, scientific constants, or uncertainty

Units
•

Applying Units to an Expression

•

Performing Computations with Units

•

Changing the Current System of Units

Scientific Constants
•

Element and Isotope Properties

•

Value, Units, and Uncertainty

•

Performing Computations

•

Modification and Extensibility

Uncertainty Propagation
•

Quantities with Uncertainty

•

Performing Computations with Quantities with Uncertainty


Restricting the Domain  How to restrict the domain for computations

•

Assumptions on Variables






4.2 Symbolic and Numeric Computation


Symbolic computation is the mathematical manipulation of expressions involving symbolic or abstract quantities, such as variables, functions, and operators; and exact numbers, such as integers, rationals, π, and The goal of such manipulations may be to transform an expression to a simpler form or to relate the expression to other, better understood formulas.
Numeric computation is the manipulation of expressions in the context of finiteprecision arithmetic. Expressions involving exact numbers, for example, are replaced by close approximations using floatingpoint numbers, for example 1.41421. These computations generally involve some error. Understanding and controlling this error is often of as much importance as the computed result.
In Maple, numeric computation is normally performed if you use floatingpoint numbers (numbers containing a decimal point) or the evalf command. The plot command (see Plots and Animations) uses numeric computation, while commands such as int, limit, and gcd (see Integer Operations and Mathematical Problem Solving) generally use only symbolic computation to achieve their results.

Exact Computations


In Maple, integers, rational numbers, mathematical constants such as π and ∞, and mathematical structures such as matrices with these as entries are treated as exact quantities. Names, such as and mathematical functions, such as and are symbolic objects. Names can be assigned exact quantities as their values, and functions can be evaluated at symbolic or exact arguments.
>


Important: Unless requested to do otherwise (see the following section), Maple evaluates expressions containing exact quantities to exact results, as you would do if you were performing the calculation by hand, and not to numeric approximations, as you normally obtain from a standard handheld calculator.
>


>


>




FloatingPoint Computations


In some situations, a numeric approximation of an exact quantity is required. For example, the plot command requires the expression it is plotting to evaluate to numeric values that can be rendered on the screen: π cannot be so rendered, but can be. Maple distinguishes approximate from exact quantities by the presence or absence of a decimal point: is approximate, while is exact.
Note: An alternative representation of floatingpoint numbers, called enotation, may not include an explicit decimal point: 1e5 , 3e2 .
In the presence of a floatingpoint (approximate) quantity in an expression, Maple generally computes using numeric approximations. Arithmetic involving mixed exact and floatingpoint quantities results in a floatingpoint result.
>


If a mathematical function is passed a floatingpoint argument, it normally attempts to produce a floatingpoint approximation of the result.
>




Converting Exact Quantities to FloatingPoint Values


To convert an exact quantity to a numeric approximation of that quantity, use the evalf command or the Approximate context menu operation (see Approximating the Value of an Expression).
>


By default, Maple computes such approximations using 10 digit arithmetic. You can modify this in one of two ways:
•

Locally, you can pass the precision as an index to the evalf call.

>


•

Globally, you can set the value of the Digits environment variable.

>


>


Note: When appropriate, Maple performs floatingpoint computations directly using your computer's underlying hardware.


Sources of Error


By its nature, floatingpoint computation normally involves some error. Controlling the effect of this error is the subject of active research in Numerical Analysis. Some sources of error are:
•

An exact quantity may not be exactly representable in decimal form: and are examples.

•

Small errors can accumulate after many arithmetic operations.

•

Subtraction of nearly equal quantities can result in essentially no useful information. For example, consider the computation for

>


No correct digits remain. If, however, you use Maple to analyze this expression, and replace this form with a representation that is more accurate for small values of a fully accurate 10digit result can be obtained.
>


>


For information on evaluating an expression at a point, see Substituting a Value for a Subexpression. For information on creating a series approximation, see Series. For more information on floatingpoint numbers, refer to the float and type/float help pages.



4.3 Integer Operations


In addition to the basic arithmetic operators, Maple has many specialized commands for performing more complicated integer computations, such as factoring an integer, testing whether an integer is a prime number, and determining the greatest common divisor (GCD) of a pair of integers.
Note: Many integer operations are available as task templates (Tools→Tasks→Browse, under Integers).
You can quickly perform many integer operations using context menus. Selecting an integer, and then rightclicking (for Macintosh, Controlclicking) displays a context menu with integer commands. For example, the context menu item Integer Factors applies the ifactor command to compute the prime factorization of the given integer. See Figure 4.1.

Figure 4.1: Context Menu for an Integer



The result of applying Integer Factors is shown:
>


 (4.1) 
>


 (4.2) 
Maple inserts the command ifactor, using an equation label reference to the integer 946929. For more information on equation labels, see Equation Labels.
For more information on using context menus in Worksheet mode, see Context Menus. For information on using context menus in Document mode, see Context Menus.
Maple has many other integer commands, including those listed in Table 4.1.
Table 4.1: Select Integer Commands 

>


>


>


>


For information on finding integer solutions to equations, see Integer Equations.

NonBase 10 Numbers and Other Number Systems


Maple supports:
•

Finite ring and field arithmetic


NonBase 10 Numbers


To represent an expression in another base, use the convert command.
>


>


For information on enclosing keywords in right single quotes ('), see Delaying Evaluation .
You can also use the convert/base command.
>


Note: The convert/base command returns a list of digit values in order of increasing significance.


Finite Rings and Fields


Maple supports computations over the integers modulo m.
The mod operator evaluates an expression over the integers modulo m.
>


By default, the mod operator uses positive representation (modp command). Symmetric representation is available using the mods command.
>


>


For information on setting symmetric representation as the default, refer to the mod help page.
The modular arithmetic operators are listed in Table 4.2.
Table 4.2: Modular Arithmetic Operators 
Operation

Operator

Example

Addition

+

>



Subtraction



>



Multiplication (displays in 2D Math as )

*

>



Multiplicative inverse (displays in 2D Math as a superscript)

^(1)

>



Division (displays in 2D Math as )

/

>



Exponentiation^{1}

&^

>



^{1}To enter a caret (^) in 2D Math, enter a backslash character followed by a caret, that is, \^.


For information on solving an equation modulo an integer, see Integer Equations in a Finite Field.
The mod operator also supports polynomial and matrix arithmetic over finite rings and fields. For more information, refer to the mod help page.


Gaussian Integers


Gaussian integers are complex numbers in which the real and imaginary parts are integers.
The GaussInt package contains commands that perform Gaussian integer operations.
The GIfactor command returns the Gaussian integer factorization.
>


In Maple, complex numbers are represented as a+b*I, where the uppercase I represents the imaginary unit .
You can also enter the imaginary unit using the following two methods.
•

Enter i or j, and then press the symbol completion key. See Symbol Names.

Note that the output will still be displayed with I, no matter what symbol was used for input. You can customize Maple's settings to use a different symbol for . For more information on entering complex numbers, including how to customize this setting, refer to the HowDoI/EnterAComplexNumber help page.
The GIsqrt command approximates the square root in the Gaussian integers.
>


For more information on Gaussian integers including a list of GaussInt package commands, refer to the GaussInt help page.




4.4 Solving Equations


You can solve a variety of equation types, including those described in Table 4.3.
Table 4.3: Overview of Solution Methods for Important Equation Types 
Equation Type

Solution Method

Equations and inequations

solve and fsolve commands

Ordinary differential equations

ODE Analyzer Assistant (and dsolve command)

Partial differential equations

pdsolve command

Integer equations

isolve command

Integer equations in a finite field

msolve command

Linear integral equations

intsolve command

Linear systems

LinearAlgebra[LinearSolve] command

Recurrence relations

rsolve command


Note: Many solve operations are available in context menus and as task templates (Tools→Tasks→Browse). Most of this section focuses on other methods.

Solving Equations and Inequations


Using Maple, you can symbolically solve equations and inequations. You can also solve equations numerically.
To solve an equation or set of equations using context menus:
1.

Rightclick (for Macintosh, Controlclick) the equations.

2.

From the context menu, select Solve (or Solve Numerically). See Figure 4.2.


Figure 4.2: Context Menu for an Equation



In Worksheet mode, Maple inserts a calling sequence that solves the equation followed by the solutions.
If you select Solve, Maple computes exact solutions.
>


 (4.3) 
>


 (4.4) 
If you select Solve Numerically, Maple computes floatingpoint solutions.
>


 (4.5) 
>


 (4.6) 
For information on solving equations and inequations symbolically using the solve command, see the following section. For information on solving equations numerically using the fsolve command, see Numerically Solving Equations.

Symbolically Solving Equations and Inequations


The solve command is a general solver that determines exact symbolic solutions to equations or inequations. The solutions to a single equation or inequation are returned as an expression sequence. For details, see Creating and Using Data Structures. If Maple does not find any solutions, the solve command returns the empty expression sequence.
>


In general, solve computes solutions in the field of complex numbers. To restrict the problem to only real solutions, see Restricting the Domain.
It is recommended that you verify the solutions returned by the solve command. For details, see Working with Solutions.
To return the solutions as a list, enclose the calling sequence in brackets ([ ]).
>


Expressions: You can specify expressions instead of equations. The solve command automatically equates them to zero.
>


Multiple Equations: To solve multiple equations or inequations, specify them as a Creating and Using Data Structures.
>


>


Solving for Specific Unknowns: By default, the solve command returns solutions for all unknowns. You can specify the unknowns for which to solve.
>


To solve for multiple unknowns, specify them as a list.
>


Transcendental Equations: In general, the solve command returns one solution to transcendental equations.
>


>


To produce all solutions, use the allsolutions option.
>


Maple uses variables of the form _ZN~, where N is a positive integer, to represent arbitrary integers. The tilde (~) indicates that it is a quantity with an assumption. For information about names with assumptions, see Assumptions on Variables .
RootOf Structure: The solve command may return solutions, for example, to higher order polynomial equations, in an implicit form using RootOf structures.
>


 (4.7) 
These RootOf structures are placeholders for the roots of the equation The index parameter numbers and orders the four solutions.
Like any symbolic expression, you can convert RootOf structures to a floatingpoint value using the evalf command.
>


Some equations are difficult to solve symbolically. For example, polynomial equations of order five and greater do not in general have a solution in terms of radicals. If the solve command does not find any solutions, it is recommended that you use the Maple numerical solver, fsolve. For information, see the following section, Numerically Solving Equations.
For more information on the solve command, including how to solve equations defined as procedures and how to find parametric solutions, refer to the solve/details help page.
For information on verifying and using solutions returned by the solve command, see Working with Solutions.


Numerically Solving Equations


The fsolve command solves equations numerically. The behavior of the fsolve command is similar to that of the solve command.
>


>


 (4.8) 
Note: You can also numerically solve equations using the context menus. See Solving Equations and Inequations.
It is recommended that you verify the solutions returned by the fsolve command. For details, see Working with Solutions.
Multiple Equations: To solve multiple equations, specify them as a set. For more information, see Creating and Using Data Structures. The fsolve command solves for all unknowns.
>


Univariate Polynomial Equations: In general, the fsolve command finds one real solution. However, for a univariate polynomial equation, the fsolve command returns all real roots.
>


>


Controlling the Number of Solutions: To limit the number of roots returned, specify the maxsols option.
>


To find additional solutions to a general equation, use the avoid option to ignore known solutions.
>


Complex Solutions: To search for a complex solution or find all complex and real roots for a univariate polynomial, specify the complex option for the fsolve command.
>


If the fsolve command does not find any solutions, it is recommended that you specify a range in which to search for solutions, or specify an initial value.
Range: To search for a solution in a range, specify the range in the calling sequence. The range can be real or complex.
>


The syntax for specifying a region in the complex plane is lowerleft point..upperright point.
>


Initial Values: You can specify a value for each unknown. The fsolve command uses these as initial values for the unknowns in the numerical method.
>


 (4.9) 
For more information and examples, refer to the fsolve/details help page.
For information on verifying and using solutions returned by the fsolve command, see the following section, Working with Solutions.


Working with Solutions


Verifying: It is recommended that you always verify solutions (that the solve and fsolve commands return) using the eval command.
>


>


 (4.10) 
>


 (4.11) 
>


>


 (4.12) 
>


 (4.13) 
For more information, see Substituting a Value for a Subexpression.
Assigning the Value of a Solution to a Variable: To assign the value of a solution to the corresponding variable as an expression, use theassign command.
For example, consider the numeric solution in (4.9), , found using the starting value .
>


>


Creating a Function from a Solution: The assign command assigns a value as an expression to a name. It does not define a function. To convert a solution to a function, use the unapply command.
Consider one of the solutions for q to the equation .
>


>


Here, solutions[1] selects the first element of the list of solutions. For more information on selecting elements, see Accessing Elements.
You can evaluate this function at symbolic or numeric values.
>


>


>


For more information on defining and using functions, see Functional Operators.



Other Specialized Solvers


In addition to equations and inequations, Maple can solve other equations including:
•

Ordinary differential equations (ODEs)

•

Partial differential equations (PDEs)

•

Integer equations in a finite field


Ordinary Differential Equations (ODEs)


Maple can solve ODEs and ODE systems, including initial value and boundary value problems, symbolically and numerically.
ODE Analyzer Assistant The ODE Analyzer Assistant is a pointandclick interface to the Maple ODE solving routines.
To open the ODE Analyzer:
•

From the Tools menu, select Assistants, and then ODE Analyzer.

Maple inserts the dsolve[interactive]() calling sequence in the document. The ODE Analyzer Assistant (Figure 4.3) is displayed.

Figure 4.3: ODE Analyzer Assistant



In the main ODE Analyzer Assistant window, you can define ODEs, initial or boundary value conditions, and parameters. To define derivatives, use the diff command. For example, diff(x(t), t) corresponds to and diff(x(t), t, t) corresponds to For more information on the diff command, see The diff Command.
After defining an ODE, you can solve it numerically or symbolically.
To solve a system numerically using the ODE Analyzer Assistant:
1.

Ensure that the conditions guarantee uniqueness of the solution.

2.

Ensure that all parameters have fixed values.

3.

Click the Solve Numerically button.

4.

In the Solve Numerically window (Figure 4.4), you can specify the numeric method and relevant parameters and error tolerances to use for solving the problem.

5.

To compute solution values at a point, click the Solve button.

x

Figure 4.4: ODE Analyzer Assistant: Solve Numerically Dialog



To solve a system symbolically using the ODE Analyzer Assistant:
1.

Click the Solve Symbolically button.

2.

In the Solve Symbolically window (Figure 4.5), you can specify the method and relevant methodspecific options to use for solving the problem.

3.

To compute the solution, click the Solve button.


Figure 4.5: ODE Analyzer Assistant: Solve Symbolically Dialog



When solving numerically or symbolically, you can view a plot of the solution by clicking the Plot button.
•

To plot the solution to a symbolic problem, all conditions and parameters must be set.

•

To customize the plot, click the Plot Options button to open the Plot Options window.

To view the corresponding Maple commands as you solve the problem or plot the solution, select the Show Maple commands check box.
You can control the return value of the ODE Analyzer using the On Quit, Return dropdown list. You can select to return nothing, the displayed plot, the computed numeric procedure (for numeric solutions), the solution (for symbolic solutions), or the Maple commands needed to produce the solution values and the displayed plot.
For more information, refer to the ODEAnalyzer help page.
The dsolve Command
The ODE Analyzer provides a pointandclick interface to the Maple dsolve command.
For ODEs or systems of ODEs, the dsolve command can find:
In addition, the dsolve command can find:
•

Formal power series solutions to linear ODEs with polynomial coefficients

•

Formal solutions to linear ODEs with polynomial coefficients

To access all available functionality, use the dsolve command directly. For more information, refer to the dsolve help page.


Partial Differential Equations (PDEs)


To solve a PDE or PDE system symbolically or numerically, use the pdsolve command. PDE systems can contain ODEs, algebraic equations, and inequations.
For example, solve the following PDE symbolically. For help entering a partial derivative, see Example 1  Enter a Partial Derivative.
>


 (4.14) 
>


The solution is an arbitrary univariate function applied to .
Maple generally prints only the return value, errors, and warnings during a computation. To print information about the techniques Maple uses, increase the infolevel setting for the command.
To return all information, set infolevel to 5.
>


>


Checking arguments ...
First set of solution methods (general or quase general solution)
Second set of solution methods (complete solutions)
Trying methods for first order PDEs
Second set of solution methods successful
For more information on solving PDEs, including numeric solutions and solving PDE systems, refer to the pdsolve help page.


Integer Equations


To find only integer solutions to an equation, use the isolve command. The isolve command finds solutions for all variables.
>




Integer Equations in a Finite Field


To solve an equation modulo an integer, use the msolve command. The msolve command finds solutions for all variables.
>




Solving Linear Systems


To solve a linear system, use the LinearAlgebra[LinearSolve] command. The LinearSolve command returns the vector x that satisfies A . x = B.
For example, construct an augmented matrix using the Matrix palette (see Creating Matrices and Vectors ) in which the first four columns contain the entries of A and the final column contains the entries of B.
>


>


For more information on using Maple to solve linear algebra problems, see Linear Algebra.


Solving Recurrence Relations


To solve a recurrence relation, use the rsolve command. The rsolve command finds the general term of the function.
>






4.5 Units, Scientific Constants, and Uncertainty


In addition to manipulating exact symbolic and numeric quantities, Maple can perform computations with units and uncertainties.
Maple supports hundreds of units, for example, miles, coulombs, and bars, and provides facilities for adding custom units.
Maple has a library of hundreds of scientific constants with units, including element and isotope properties.
To support computations with uncertainties, Maple propagates errors through computations.

Units


The Units package in Maple provides a library of units, and facilities for using units in computations. It is fully extensible so that you can add units and unit systems as required.
Note: Some unit operations are available as task templates (see Tools→Tasks→Browse) and through context menus.

Overview of Units


A dimension is a measurable quantity, for example, length or force. The set of dimensions that are fundamental and independent are known as base dimensions.
In Maple, the base dimensions include length, mass, time, electric current, thermodynamic temperature, amount of substance, luminous intensity, information, and currency. For a complete list, enter and execute Units[GetDimensions]().
Complex dimensions (or composite dimensions) measure other quantities in terms of a combination of base dimensions. For example, the complex dimension force is a measurement of
Each dimension, base or complex, has associated units. (Base units measure a base dimension. Complex units measure a complex dimension.) Maple supports over 40 units of length, including feet, miles, meters, angstroms, microns, and astronomical units. A length must be measured in terms of a unit, for example, a length of 2 parsecs.
Table 4.4 lists some dimensions, their corresponding base dimensions, and example units.
Table 4.4: Sample Dimensions 
Dimension

Base Dimensions

Example Units

Time

time

second, minute, hour, day, week, month, year, millennium, blink, lune

Energy


joule, electron volt, erg, watt hour, calorie, Calorie, British thermal unit

Electric potential


volt, abvolt, statvolt


For the complete list of units (and their contexts and symbols) available for a dimension, refer to the corresponding help page, for example, the Units/length help page for the units of length.
Each unit has a context. The context differentiates between different definitions of the unit. For example, the standard and US survey miles are different units of length, and the second is a unit of time and of angle. You can specify the context for a unit by appending the context as an index to the unit, for example, mile[US_survey]. If you do not specify a context, Maple uses the default context.
Units are collected into systems, for example, the footpoundsecond (FPS) system and international system, or système international, (SI). Each system has a default set of units used for measurements. In the FPS system, the foot, pound, and second are used to measure the dimensions of length, mass, and time. The unit of speed is the foot/second. In SI, the meter, kilogram, and second are used to measure the dimensions of length, mass, and time. The units of speed, magnetic flux, and power are the meter/second, weber, and watt, respectively.


Unit Conversions


To convert a value measured in a unit to the corresponding value in a different unit, use the Units Calculator.
•

From the Tools→Assistants menu, select Units Calculator.

The Units Calculator application (Figure 4.6) opens.

Figure 4.6: Units Calculator Assistant



To perform a conversion:
1.

In the Convert text field, enter the numeric value to convert.

2.

In the Dimension dropdown list, select the dimensions of the unit.

3.

In the From and To dropdown lists, select the original unit and the unit to which to convert.

4.

Click Perform Unit Conversion.

The same conversion can be done with the convert/units command.
>


Using the Units Calculator, you can convert temperatures and temperature changes.
•

To perform a temperature conversion, in the Dimension dropdown list, select temperature(absolute).

•

To perform a temperature change conversion, in the Dimension dropdown list, select temperature(relative).

To convert temperature changes, the Units Calculator uses the convert/units command. For example, an increase of 32 degrees Fahrenheit corresponds to an increase of almost 18 degrees Celsius.
>


To convert absolute temperatures, the Unit Converter uses the convert/temperature command. For example, 32 degrees Fahrenheit corresponds to 0 degrees Celsius.
>




Applying Units to an Expression


To insert a unit, use the Units palettes. The Units (FPS) palette (Figure 4.7) contains important units from the footpoundsecond system of units. The Units (SI) palette (Figure 4.8) contains important units from the international system of units.

Figure 4.7: Units (FPS) Palette





Figure 4.8: Units (SI) Palette






To insert a unit:
•

In a Units palette, click a unit symbol.

>


To insert a unit that is unavailable in the palettes:
1.

In a Units palette, click the unit symbol
. Maple inserts a Unit object with the placeholder selected.

2.

In the placeholder, enter the unit name (or symbol).

For example, to enter standard (the default context) miles, you can specify the unit name, mile, or symbol, mi.
>


The context of a unit is displayed only if it is not the default context.
Important: In 1D Math input, the quantity and unit (entered using the toplevel Unit command) are a product, not a single entity. The following calling sequences define different expressions.
Some units support prefixes. For example, SI units support prefixes to names and symbols. You can specify 1000 meters using kilometer or km.
>




Performing Computations with Units


In the default Maple environment, you cannot perform computations with quantities that have units. You can perform only unit conversions. For more information about the default environment, refer to the Units/default help page.
To compute with expressions that have units, you must load a Units environment, Natural or Standard. It is recommended that you use the Standard environment.
>


In the Standard Units environment, commands that support expressions with units return results with the correct units.
>


>


 (4.15) 
>


 (4.16) 
>


For information on differentiation and integration, see Calculus.


Changing the Current System of Units


If a computation includes multiple units, all units are expressed using units from the current system of units.
>


 (4.17) 
By default, Maple uses the SI system of units, in which length is measured in meters and time is measured in seconds.
>


To view the name of the default system of units, use the Units[UsingSystem] command.
>


>


To change the system of units, use the Units[UseSystem] command.
>


>



   