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 floating-point computation
Exact Computations
Floating-Point Computations
Converting Exact Quantities to Floating-Point Values
Sources of Error
Integer Operations - How to perform integer computations
Important Integer Commands
Non-Base 10 Numbers
Finite Rings and Fields
Gaussian Integers
Solving Equations - How to solve standard mathematical equations
Equations and Inequations
Ordinary Differential Equations
Partial Differential Equations
Integer Equations
Integer Equations in a Finite Field
Linear Systems
Recurrence Relations
Units, Scientific Constants, and Uncertainty - How to construct and compute with expressions that have units, scientific constants, or uncertainty
Units
Conversions
Applying Units to an Expression
Performing Computations with Units
Changing the Current System of Units
Extensibility
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
Real Number Domain
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 ⅇ2. 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 finite-precision arithmetic. Expressions involving exact numbers, for example, 2,are replaced by close approximations using floating-point 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 floating-point 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.
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 x,y,my_variable,and mathematical functions, such as sinx and LambertWk,z,are symbolic objects. Names can be assigned exact quantities as their values, and functions can be evaluated at symbolic or exact arguments.
32⁢+⁢13,⁢1⁢+⁢π2
116,1+π2
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 hand-held calculator.
sin⁡1,⁢sin⁡π,⁢sin⁡x
sin⁡1,0,sin⁡x
∫tan⁡tⅆt
−ln⁡cos⁡t
32
4⁢2
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 3.14159 can be. Maple distinguishes approximate from exact quantities by the presence or absence of a decimal point: 1.9 is approximate, while 1910 is exact.
Note: An alternative representation of floating-point numbers, called e-notation, may not include an explicit decimal point: 1e5 =⁢100000., 3e-2 =⁢.03.
In the presence of a floating-point (approximate) quantity in an expression, Maple generally computes using numeric approximations. Arithmetic involving mixed exact and floating-point quantities results in a floating-point result.
1.5⁢+⁢23,1 +0.5⋅π
2.166666667,2.570796327
If a mathematical function is passed a floating-point argument, it normally attempts to produce a floating-point approximation of the result.
sin⁡1.5,⁢∫0.01.0ⅇxⅆx
0.9974949866,1.718281828
To convert an exact quantity to a numeric approximation of that quantity, use the evalf command or the Approximate context panel operation (see Approximating the Value of an Expression).
evalf⁡π,⁢evalf⁡sin⁡3,⁢evalf⁡32+13
3.141592654,0.1411200081,1.833333333
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.
evalf20exp⁡2,⁢evalf⁡Γ⁡23
7.3890560989306502272,1.354117939
Globally, you can set the value of the Digits environment variable.
Digits⁢≔ 25:
evalf⁡tan⁡π3
1.732050807568877293527446
Set the value back to the default Digits level:
Digits≔10:
Note: When appropriate, Maple performs floating-point computations directly using your computer's underlying hardware.
By its nature, floating-point 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: 13 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 x⁢−⁢sin⁡x for x⁢≈0.⁢
x−sin⁡xx=0|f(x)x=.00001
0.
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 x,a fully accurate 10-digit result can be obtained.
t⁢:=⁢taylor⁡x−sin⁡x,⁢x
t≔16⁢x3−1120⁢x5+O⁡x7
tx=a|f(x)x=0.00001
1.666666667×10−16
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 floating-point 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 the context panel. Clicking on an integer displays the context panel with integer commands. For example, the context-sensitive operation Integer Factors applies the ifactor command to compute the prime factorization of the given integer. See Figure 4.1.
Figure 4.1: Context Panel for an Integer
The result of applying Integer Factors is shown:
9469629
ifactor()
34⁢13⁢17⁢232
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-sensitive operations in Worksheet mode, see The Context Panel. For information on using context-sensitive operations in Document mode, see Computing with the Context Panel.
Maple has many other integer commands, including those listed in Table 4.1.
Command
Description
abs
absolute value (displays in 2-D math as a)
factorial
factorial (displays in 2-D math as a!)
ifactor
prime factorization
igcd
greatest common divisor
iquo
quotient of integer division
irem
remainder of integer division
iroot
integer approximation of nth root
isprime
test primality
isqrt
integer approximation of square root
max, min
maximum and minimum of a set
mod
modular arithmetic (See Finite Rings and Fields.)
NumberTheory[Divisors]
set of positive divisors
iquo⁡209,⁢17
12
irem⁡209,⁢17
5
igcd(2024,4862)
22
iroot(982523,4)
31
For information on finding integer solutions to equations, see Integer Equations.
Non-Base 10 Numbers and Other Number Systems
Maple supports:
Non-base 10 numbers
Finite ring and field arithmetic
Gaussian integers
To represent an expression in another base, use the convert command.
convert(6000,⁢'binary')
1011101110000
convert(34271,⁢'hex')
85DF
For information on enclosing keywords in right single quotes ('), see Delaying Evaluation.
You can also use the convert/base command.
convert(34271,⁢'base',16)
15,13,5,8
Note: The convert/base command returns a list of digit values in order of increasing significance.
Maple supports computations over the integers modulo m.
The mod operator evaluates an expression over the integers modulo m.
27mod4⁢
3
By default, the mod operator uses positive representation (modp command). Symmetric representation is available using the mods command.
modp(27,4)
mods(27,4)
−1
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.
Operation
Operator
Example
Addition
+
7⁢+⁢6⁢mod 5
Subtraction
-
mods(3−16,11)
−2
Multiplication (displays in 2-D Math as ⋅)
13⋅5⁢mod⁢3
2
Multiplicative inverse (displays in 2-D Math as a superscript)
^(-1)
3−1mod⁢5
Division (displays in 2-D Math as ab )
/
23⁢mod⁢5
4
Exponentiation1
&^
100&^100mod⁢7⁢
1To enter a caret (^) in 2-D 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 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.
GaussIntGIfactor173+16⁢ⅈ
1+2⁢I⁢41−66⁢I
In Maple, complex numbers are represented as a+b I, where the uppercase I represents the imaginary unit −1.
You can also enter the imaginary unit using the following two methods.
In the Common Symbols palette, click the I, ⅈ or ȷ item. See Palettes.
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 −1. 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.
GaussIntGIsqrt9−5⁢ȷ
3−I
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.
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 the context panel 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 the context panel:
Click the equation.
From the context panel, select Solve (or Solve Numerically). See Figure 4.2.
Figure 4.2: Context Panel 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.
7⁢x23⁢−⁢x⁢=⁢12
73⁢x2−x=12
solve⁡⁢⁢
x=314+3⁢11314,x=314−3⁢11314
If you select Solve Numerically, Maple computes floating-point solutions.
7⁢x23⁢−⁢x⁢=12
fsolve⁡⁢⁢
x=−2.063602674,x=2.492174103
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.
solvex2+3 x +14=0
−32+I⁢472,−32−I⁢472
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 ([ ]).
solve⁡x2⁢+⁢x⁢=⁢256⁢y,⁢x
−12+1+1024⁢y2,−12−1+1024⁢y2
Expressions: You can specify expressions instead of equations. The solve command automatically equates them to zero.
solveⅇz+z
−LambertW⁡1
(In this case, the solution involves the LambertW function.)
Multiple Equations: To solve multiple equations or inequations, specify them as a list or set. For an introduction to both lists and sets, see Creating and Using Data Structures.
solve⁡x⁢y2⁢−⁢y⁢=⁢5,⁢x⁢>⁢0
x=y+5y2,−5<y,y<0,x=y+5y2,0<y
solve⁡x⁢y2⁢−⁢y⁢=⁢5,⁢x⁢<⁢0
x=y+5y2,y<−5
Solving for Specific Unknowns: By default, the solve command returns solutions for all unknowns. You can specify the unknowns for which to solve.
solve(q2−r⁢s+qr=5,q)
−1+4⁢r3⁢s+20⁢r2+12⁢r,−1+4⁢r3⁢s+20⁢r2+12⁢r
To solve for multiple unknowns, specify them as a list.
solve⁡qs⁢−⁢rs⁢+1⁢+⁢qr⁢=⁢5,⁢r⁢s⁢=⁢1,q,⁢r
q=5⁢s2+5⁢s+1s3+s2+s+1,r=1s
Transcendental Equations: In general, the solve command returns one solution to transcendental equations.
equation1≔sinx=cosx:
solveequation1
π4
To produce all solutions, use the allsolutions option.
solve⁡equation1,allsolutions=true
14⁢π+π⁢_Z1~
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.
[solve(x5−2⁢x4+3⁢x3−2)]
1,RootOf⁡_Z4−_Z3+2⁢_Z2+2⁢_Z+2,index=1,RootOf⁡_Z4−_Z3+2⁢_Z2+2⁢_Z+2,index=2,RootOf⁡_Z4−_Z3+2⁢_Z2+2⁢_Z+2,index=3,RootOf⁡_Z4−_Z3+2⁢_Z2+2⁢_Z+2,index=4
These RootOf structures are placeholders for the roots of the equation z4−z3+2⁢z2+2⁢z+2. The index parameter numbers and orders the four solutions.
Like any symbolic expression, you can convert RootOf structures to a floating-point value using the evalf command.
evalf⁡
1.,0.9840010519+1.526590834⁢I,−0.4840010519+0.6099471405⁢I,−0.4840010519−0.6099471405⁢I,0.9840010519−1.526590834⁢I
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.
equation2⁢:=⁢z⁢cos(z)=2:
fsolve⁡equation2
23.64662473
Note: You can also numerically solve equations using the context panel. 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.
fsolve⁡lnx⁢=⁢y2⁢+⁢1,⁢x⁢y⁢=⁢ⅇy
x=3.396618823,y=0.4719962637
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.
equation3⁢:=⁢y4−3⁢y2−2⁢y+1:
fsolveequation3,y
0.3365322739,1.940392664
Controlling the Number of Solutions: To limit the number of roots returned, specify the maxsols option.
fsolveequation3,y,'maxsols'=1
0.3365322739
To find additional solutions to a general equation, use the avoid option to ignore known solutions.
fsolve⁡equation2,⁢z,⁢'avoid'⁢=⁢z⁢=⁢
−2.498755763
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.
fsolve⁡equation3,⁢y,⁢'complex'
−1.13846246879373−0.485062494059435⁢I,−1.13846246879373+0.485062494059435⁢I,0.336532273926790,1.94039266366067
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.
fsolve⁡equation2,⁢z,⁢z⁢=⁢100..200
199.5011587
The syntax for specifying a region in the complex plane is lower-left point..upper-right point.
fsolve⁡equation3,⁢y,⁢y⁢=⁢−2−I..0,⁢'complex';
−1.13846246879373−0.485062494059435⁢I
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.
fsolve⁡equation2,⁢z⁢=⁢100
z=98.98037599
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.
equation4⁢:=⁢sin⁡x⁢=⁢&uminus0;cos⁡x:
solve⁡equation4
−π4
eval⁡equation4,⁢x=
−22=−22
equation5⁢:=⁢cos⁡z⁢=⁢2z:
fsolve⁡equation5
eval⁡equation5,⁢z=
−0.8003983544=−0.8003983540
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, you can use the assign command, which can turn an equation such as the numeric solution in (4.9), , into an assignment.
assign⁡
z
98.98037599
A word of caution, if you do this, z now has a value so you cannot afterwards treat it as an unknown unless you unassign it. The way to do that is
z≔'z':
For more information on unassigning names, see Unassigning Names.
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 q2−r⁢s+qr=5.
solutions:=solveq2−r⁢s+qr=5,q
solutions≔−1+4⁢r3⁢s+20⁢r2+12⁢r,−1+4⁢r3⁢s+20⁢r2+12⁢r
f:=unapply⁡solutions1,r,s
f≔r,s↦−1+4⁢r3⁢s+20⁢r2+12⁢r
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.
f(x,y)
−1+4⁢x~3⁢y+20⁢x~2+12⁢x~
f⁡12,1
2⁢−1+2+112
f⁡5.7,2.1
4.032680521587978641060188
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)
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 point-and-click interface to the Maple ODE solving routines.
To open the ODE Analyzer:
From the Tools menu, select Tutors, Differential Equations, 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 ⅆfⅆx, and diff(x(t), t, t) corresponds to ⅆ2fⅆx2. 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:
Ensure that the conditions guarantee uniqueness of the solution.
Ensure that all parameters have fixed values.
Click the Solve Numerically button.
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.
To compute solution values at a point, click the Solve button.
Figure 4.4: ODE Analyzer Assistant: Solve Numerically Dialog
To solve a system symbolically using the ODE Analyzer Assistant:
Click the Solve Symbolically button.
In the Solve Symbolically window (Figure 4.5), you can specify the method and relevant method-specific options to use for solving the problem.
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 drop-down 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 point-and-click interface to the Maple dsolve command.
For ODEs or systems of ODEs, the dsolve command can find:
Closed form solutions
Numerical solutions
Series solutions
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.
restart:
x ∂∂yfx,y−y ∂∂xfx,y=0
x⁢∂∂yf⁡x,y−y⁢∂∂xf⁡x,y=0
pdsolve⁡
f⁡x,y=f__1⁡x2+y2
The solution is an arbitrary univariate function applied to x2+y2.
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.
infolevelpdsolve:=5:
pdsolve
Checking arguments ...
First set of solution methods (general or quasi general solution)
-> trying characteristic strip method for first order PDEs
<- characteristic strip method for first order PDEs successful
<- First set of solution methods successful
<- Returning a *general* solution
For more information on solving PDEs, including numeric solutions and solving PDE systems, refer to the pdsolve help page.
To find only integer solutions to an equation, use the isolve command. The isolve command finds solutions for all variables.
isolve({x2+y=13})
x=_Z1,y=−_Z12+13
To solve an equation modulo an integer, use the msolve command. The msolve command finds solutions for all variables.
msolve({x2=1},13)
x=1,x=12
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.
linearsystem⁢:=⁢[591044251721100121075331006150982110310721782523912511078625]:
LinearAlgebraLinearSolvelinearsystem
3175344104741858667400169918062398371733480−14892662171674346696262603866209293337
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.
rsolve({f(n)=f(n-1)+f(n-2),f(0)=1,f(1)=1},{f(n)})
f⁡n=12+510⁢12+52n+12−510⁢12−52n
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.
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 the context panel.
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 mass⋅lengthtime2.
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.
Dimension
Base Dimensions
Example Units
Time
time
second, minute, hour, day, week, month, year, millennium, blink, lune
Energy
length2⋅masstime2
joule, electron volt, erg, watt hour, calorie, Calorie, British thermal unit
Electric potential
length2⋅masstime3⋅electric current
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 foot-pound-second (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 Converter.
From the Tools→Assistants menu, select Units Converter.
The Units Converter application (Figure 4.6) opens.
Figure 4.6: Units Converter Assistant
To perform a conversion:
In the Convert text field, enter the numeric value to convert.
In the Dimension drop-down list, select the dimensions of the unit.
In the From and To drop-down lists, select the original unit and the unit to which to convert.
Click Perform Unit Conversion.
The same conversion can be done with the convert/units command.
convert(1.0,'units','lbf⁢ft(radius)','N⁢m(radius)')
1.355817948
Using the Units Converter, you can convert temperatures and temperature changes.
To perform a temperature conversion, in the Dimension drop-down list, select temperature(absolute).
To perform a temperature change conversion, in the Dimension drop-down list, select temperature(relative).
To convert temperature changes, the Units Converter uses the convert/units command. For example, an increase of 32 degrees Fahrenheit corresponds to an increase of almost 18 degrees Celsius.
convert(32.0,'units','degF','degC')
17.77777778
To convert absolute temperatures, the Unit Converter uses the convert/temperature command. For example, 32 degrees Fahrenheit corresponds to 0 degrees Celsius.
convert(32,'temperature','degF','degC')
0
To insert a unit, use the Units palette . See Figure 4.7.
Figure 4.7: Units Palette
To insert a unit:
In the Units palette, select a unit dimension, then click the desired unit symbol.
3ft
3⁢ft
To insert a unit that is unavailable in the palettes:
In the Units palette, click the unit symbol . Maple inserts a Unit object with the placeholder selected.
In the placeholder, enter the unit name (or symbol). Note that you see double brackets around the unit when you are editing it.
For example, to enter 0.01 standard (the default context) miles, you can specify the unit name, mile, or symbol, mi. As you edit, the unit is enclosed in double brackets:
0.01mile
0.01⁢mi
The context of a unit is displayed only if it is not the default context.
Alternative ways to enter units:
Enter Unit, and then press the symbol completion key (see Symbol Names) and then enter the unit.
Use the shortcut key Ctrl + Shift + U (Command + Shift + U, on Mac) and then enter the unit.
Use the Unit command. Note that to write a quantity with a unit using this command, write multiplication between them; this is especially evident in 1-D math:
Important: In 1-D Math input, the quantity and unit (entered using the top-level Unit command) are a product, not a single entity. The following calling sequences define different expressions.
1 Unit(m)/(2 Unit(s));
12⁢s⁢m
1 Unit(m)/2 Unit(s);
12⁢m⁢s
Some units support prefixes. For example, SI units support prefixes to names and symbols. You can specify 1000 meters using kilometer or km.
1.5⁢⟦kmSI⟧
1.5⁢km
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: Simple, Standard, or Natural. It is recommended that you use the Simple environment, and that environment is loaded by default when you load the Units package:
withUnits:
Automatically loading the Units[Simple] subpackage
In the Simple Units environment, commands that support expressions with units return results with the correct units.
area:=⁢3ft⁢⋅⁢18mile
area≔38⁢ft⁢mi
−12⁢sin⁡x+x2ms
−12⁢sin⁡x+x2⁢ms
int⁡,⁢x
x33+12⁢cos⁡x⁢ms
diff⁡,⁢xs
−12⁢sin⁡x+x2⁢ms2
For information on differentiation and integration, see Calculus.
If a computation includes multiple units, all units are expressed using units from the current system of units.
132.25mile
132.25⁢mi
By default, Maple uses the SI system of units, in which length is measured in meters and time is measured in seconds.
3hour
19.70701333⁢ms
To view the name of the default system of units, use the Units[UsingSystem] command or view the current selection for Choose System, under the Convert Output Units section of the context panel.
with⁡Units:
UsingSystem⁡
SI
To change the system of units, use the Units[UseSystem] command or click the output and then select the desired system of units in the Choose System list, under the Convert Output Units section of the context panel.
UseSystem⁡FPS:⁢
⋅3m⋅1.1kg
1.666720741×107⁢ft2⁢lb
You can extend the set of:
Base dimensions and units
Complex dimensions
Complex units
Systems of units
For more information, refer to the Units[AddBaseUnit], Units[AddDimension], Units[AddUnit], and Units[AddSystem] help pages.
For more information about units, refer to the Units help page.
Scientific Constants and Element Properties
Computations often require not only units (see Units), but also the values of scientific constants, including properties of elements and their isotopes. Maple supports computations with scientific constants. You can use the built-in constants and add custom constants.
Overview of Scientific Constants and Element Properties
The ScientificConstants package provides the values of constant physical quantities, for example, the velocity of light and the atomic weight of sodium. The ScientificConstants package also provides the units for the constant values, allowing for greater understanding of the equation as well as unit-matching for error checking of the solution.
The quantities available in the ScientificConstants package are divided into two distinct categories.
Physical constants
Chemical element (and isotope) properties
List of Scientific Constants
You have access to scientific constants important in engineering, physics, chemistry, and other fields. Table 4.5 lists some of the supported constants. For a complete list of scientific constants, refer to the ScientificConstants/PhysicalConstants help page.
Name
Symbol
Newtonian_constant_of_gravitation
G
Planck_constant
h
elementary_charge
e
Bohr_radius
a[0]
deuteron_magnetic_moment
mu[d]
Avogadro_constant
N[A]
Faraday_constant
F
You can specify a constant using either its name or symbol.
Accessing Constant Definition
The GetConstant command in the ScientificConstants package returns the complete definition of a constant.
To view the definition of the Newtonian gravitational constant, specify the symbol G (or its name) in a call to the GetConstant command.
with(ScientificConstants):
GetConstant'G'
Newtonian_constant_of_gravitation,symbol=G,value=6.67408×10−11,uncertainty=3.1×10−15,units=m3kg⁢s2
For information on accessing a constant's value, units, or uncertainty, see Value, Units, and Uncertainty.
Element Properties
Maple also contains element properties and isotope properties.
Elements
Maple supports all 117 elements of the periodic table. Each element has a unique name, atomic number, and chemical symbol. You can specify an element using any of these labels. For a complete list of supported elements, refer to the ScientificConstants/elements help page.
Maple supports key element properties, including atomic weight (atomicweight), electron affinity (electronaffinity), and density. For a complete list of element properties, refer to the ScientificConstants/properties help page.
Isotopes
Isotopes, variant forms of an element that contain the same number of protons but a different number of neutrons, exist for many elements.
To see the list of supported isotopes for an element, use the GetIsotopes command.
GetIsotopes'element' = 'Li'
Li4,Li5,Li6,Li7,Li8,Li9,Li10,Li11,Li12
Maple supports isotopes and has a distinct set of properties for isotopes, including abundance, binding energy (bindingenergy), and mass excess (massexcess). For a complete list of isotope properties, refer to the ScientificConstants/properties help page.
Accessing an Element or Isotope Property Definition
The GetElement command in the ScientificConstants package returns the complete definition of an element or isotope.
GetElement('Li')
3,symbol=Li,name=lithium,names=lithium,density=value=0.534,uncertainty=undefined,units=gcm3,electronaffinity=value=0.6180,uncertainty=0.0005,units=eV,boilingpoint=value=1615.,uncertainty=undefined,units=K,electronegativity=value=0.98,uncertainty=undefined,units=1,ionizationenergy=value=5.3917,uncertainty=undefined,units=eV,atomicweight=value=6.941,uncertainty=0.002,units=amu,meltingpoint=value=453.65,uncertainty=undefined,units=K
GetElement('Li4')
Li4,massexcess=value=25320.173,uncertainty=212.132,units=keV,bindingenergy=value=4618.058,uncertainty=212.132,units=keV,atomicmass=value=4.027182329×106,uncertainty=227.733,units=μamu
To use constants or element properties, you must first construct a ScientificConstants object.
To construct a scientific constant, use the Constant command.
G:=Constant'G':
To construct an element (or isotope) property, use the Element command.
LiAtomicWeight:=Element'Li', atomicweight
LiAtomicWeight≔Element⁡Li,atomicweight
Value
To obtain the value of a ScientificConstants object, use the evalf command.
evalf(G)
1.069085060×10−9
evalf(LiAtomicWeight)
2.541006042×10−26
Note: The value returned depends on the current system of units.
To obtain the units for a ScientificConstants object, use the GetUnit command.
GetUnit(G)
ft3lb⁢s2
GetUnit⁡(LiAtomicWeight)
lb
For information on changing the default system of units, for example, from SI to foot-pound-second, see Changing the Current System of Units.
Value and Units
If you are performing computations with units, you can access the value and units for a ScientificConstants object by specifying the units option when constructing the object, and then evaluating the object.
evalfConstant'G',units
1.069085060×10−9⁢ft3lb⁢s2
evalf⁡Element⁡'Li5',⁢atomicmass,⁢units
1.835022162×10−26⁢lb
Uncertainty
The value of a constant is often determined by direct measurement or derived from measured values. Hence, it has an associated uncertainty. To obtain the uncertainty in the value of a ScientificConstants object, use the GetError command.
GetError(G)
4.965723646×10−14
implicitploteq,x=−0.5..0.5,y=−0.5..0.5,numpoints=100000,thickness=3
7.321728978×10−30
You can use constant values in any computation. To use constant values with units, use a Units environment as described in Performing Computations with Units. For information on computing with quantities that have an uncertainty, see the following section.
You can change the definition of a scientific constant or element (or isotope) property.
For more information, refer to the ScientificConstants[ModifyConstant] and ScientificConstants[ModifyElement] help pages.
Constants
Elements (and isotopes)
Element (or isotope) properties
For more information, refer to the ScientificConstants[AddConstant], ScientificConstants[AddElement], and ScientificConstants[AddProperty] help pages.
For more information about constants, refer to the ScientificConstants help page.
Some computations involve uncertainties (or errors). Using the ScientificErrorAnalysis package, you can propagate the uncertainty in these values through the computation to indicate the possible error in the final result.
The ScientificErrorAnalysis package does not perform interval arithmetic. That is, the error of an object does not represent an interval in which possible values must be contained. (To perform interval arithmetic, use the Tolerances package..) The quantities represent unknown values with a central tendency. For more information on central tendency, refer to any text on error analysis for the physical sciences or engineering.
Creating: To construct quantities with uncertainty, use the Quantity command. You must specify the value and uncertainty. The uncertainty can be defined absolutely, relatively, or in units of the last digit. For more information on uncertainty specification, refer to the ScientificErrorAnalysis[Quantity] help page.
The output displays the value and uncertainty of the quantity.
with(ScientificConstants):⁢with(ScientificErrorAnalysis):
Quantity(105,1.2)
Quantity⁡105,1.2
Quantity(105,0.03,⁢'relative')
Quantity⁡105,3.15
To specify the error in units of the last digit, the value must be of floating-point type.
Quantity(105.0,12,⁢'uld')
Quantity⁡105.0,1.2
To access the value and uncertainty of a quantity with uncertainty, use the evalf and ScientificErrorAnalysis[GetError] commands.
105.
GetError⁡
3.15
Rounding: To round the error of a quantity with uncertainty, use the ApplyRule command. For a description of the predefined rounding rules, refer to the ScientificErrorAnalysis/rules help page.
GetErrorApplyRule,⁢ 'round2'
3.2
Units: Quantities with errors can have units. For example, the scientific constants and element (and isotope) properties in the ScientificConstants packages are quantities with errors and units.
To construct a new quantity with units and an uncertainty, include units in the Quantity calling sequence.
For an absolute error, you must specify the units in both the value and error.
withUnitsStandard:withScientificErrorAnalysis:
Quantity3.5 m,0.1 m
Quantity⁡3.5⁢m,0.1⁢m
For a relative error, you can specify the units in only the value.
Quantity⁡3.5m,⁢0.1,⁢'relative'
Quantity⁡3.5⁢m,0.35⁢m
For information on the correlation between, variance of, and covariance between quantities with uncertainty, refer to the ScientificErrorAnalysis help page.
Many Maple commands support quantities with uncertainty.
q1⁢:=⁢Quantity(31.,2.):
q2⁢:=⁢Quantity(20.,1.):
Compute the value of the derivative of q1⋅x2⁢+⁢sin⁡q2⋅x at x⁢=⁢sinπ/4.
d1⁢:=⁢diff⁡q1⋅x2+sin⁡q2⋅x,x
d1≔2⁢x⁢Quantity⁡31.,2.+Quantity⁡20.,1.⁢cos⁡x⁢Quantity⁡20.,1.
d2⁢:=⁢eval⁡d1,⁢x⁢=⁢sin⁡π4:
To convert the solution to a single quantity with uncertainty, use the combine/errors command.
result⁢:=⁢combine⁡d2,⁢'errors':
The value of the result is:
evalf⁡result
43.74124725
The uncertainty of the result is:
GetError⁡result
14.42690612
Additional Information
For information on topics including:
Creating new rounding rules,
Setting the default rounding rule, and
Creating a new interface to quantities with uncertainty,
refer to the ScientificErrorAnalysis help page.
4.6 Restricting the Domain
By default, Maple computes in the complex number system. Most computations are performed without any restrictions or assumptions on the variables. Maple often returns results that are extraneous or unsimplified when computing in the field of complex numbers. Using restrictions, you can more easily and efficiently perform computations in a smaller domain.
Maple has facilities for performing computations in the real number system and for applying assumptions to variables.
To force Maple to perform computations in the field of real numbers, use the RealDomain package.
The RealDomain package contains a small subset of Maple commands related to basic precalculus and calculus mathematics, for example, arccos, limit, and log, and the symbolic manipulation of expressions and formulae, for example, expand, eval, and solve. For a complete list of commands, refer to the RealDomain help page.
After you load the RealDomain package, Maple assumes that all variables are real. Commands return simplified results appropriate to the field of real numbers.
Without Loading RealDomain
After Loading RealDomain
In Maple's default environment, without loading RealDomain, the answers are correct for the entire complex field.
simplifyx2
csgn⁡x⁢x
lnⅇx
ln⁡ⅇx
−3215
After loading RealDomain, the answers are simplified.
withRealDomain:
x
solve(x2=−1)
I,−I
arcsin(ⅇ2)
arcsin⁡ⅇ2
Complex return values are excluded or replaced by undefined.
undefined
After loading the RealDomain package, you can also use the context-sensitive items for simplify and solve to perform computations in the field of real numbers. For example, using the context panel item Simplify > Simplify,
x2= simplify x
To simplify problem solving, it is recommended that you always apply any known assumptions to variables. You can impose assumptions using the assume command. To apply assumptions for a single computation, use the assuming command.
Note: The assume and assuming commands are not supported by the RealDomain package.
The assume Command
You can use the assume command to set variable properties, for example, x::real, and relationships between variables, for example, x < 0 or x < y. For information on valid properties, refer to the assume help page. For information on the double colon (::) operator, refer to the type help page.
The assume command allows improved simplification of symbolic expressions, especially multiple-valued functions, for example, computing the square root.
To assume that x is a positive real number, use the following calling sequence. Then compute the square root of x2.
assume(0<x):⁢x2
x~2
The trailing tilde (~) on the name x indicates that it carries assumptions.
When you use the assume command to place another assumption on x, all previous assumptions are removed.
assume(x<0):⁢x2
Displaying Assumptions: To view the assumptions on an expression, use the about command.
aboutx
Originally x, renamed x~: is assumed to be: RealRange(-infinity,Open(0))
Imposing Multiple Assumptions: To simultaneously impose multiple conditions on an expression, specify multiple arguments in the assume calling sequence.
assume(0<x,x<2)
To specify additional assumptions without replacing previous assumptions, use the additionally command. The syntax of the additionally calling sequence is the same as that of the assume command.
additionally(x::integer):⁢aboutx
Originally x, renamed x~: is assumed to be: 1
The only integer in the open interval (0, 2) is 1.
Testing Properties: To test whether an expression always satisfies a condition, use the is command.
assume(15<x,7<y):⁢is(100<x⁢y)
true
The following test returns false because there are values of x and y (x = 0, y = 10) that satisfy the assumptions, but do not satisfy the relation in the is calling sequence.
assume(x::nonnegint,10≤y):⁢is(10<x+y)
false
To test whether an expression can satisfy a condition, use the coulditbe command.
coulditbe(10<x+y)
Removing Assumptions: To remove all assumptions on a variable, unassign its name.
x≔'x':y≔'y':
For more information, see Unassigning Names.
For more information on the assume command, refer to the assume help page.
The assuming Command
To perform a single evaluation under assumptions on the names in an expression, use the assuming command.
The syntax of the assuming command is <expression> assuming <property or relation>. Properties and relations are introduced in The assume Command.
The frac command returns the fractional part of an expression.
fracx⁢assuming x∷integer
Using the assuming command is equivalent to imposing assumptions with the assume command, evaluating the expression, and then removing the assumptions.
x: nothing known about this object
If you do not specify the names to which to apply a property, it is applied to all names.
ab2assuming positive
a2b2
Assumptions placed on names using the assume command are ignored by the assuming command, unless you include the additionally option.
assume(x<1)
is1−x2>0⁢assuming⁢x> −1
is1−x2>0⁢assuming additionally,x>−1
The assuming command does not affect variables inside procedures. (For information on procedures, see Procedures.) You must use the assume command.
f := proc(x) sqrt(a^2) + x end proc;
f≔procxUnits:-Standard:-`+`⁡RealDomain:-sqrt⁡RealDomain:-`^`⁡a,2,xend proc
f1⁢assuming a>0
a2+1
assume(a>0):⁢f(1)
a~2+1
For more information on the assuming command, refer to the assuming help page.
Download Help Document