evalf
evaluate using floating-point arithmetic
Calling Sequence
Parameters
Basic Information
Description
Output
Constants and Mathematical Functions
Examples
evalf(expression)
evalf[n](expression)
expression
-
expression to be evaluated
n
(optional) posint; specifies number of digits
This help page contains complete information about the evalf command. For basic information on the evalf command, see the evalf help page.
The evalf command numerically evaluates expressions (or subexpressions) involving constants (for example, Pi, exp(1), and gamma) and mathematical functions (for example, exp, ln, sin, arctan, cosh, GAMMA, and erf.
To perform numerical integration, use the evalf command in conjunction with the Int or int command. For more information, see the evalf/Int help page.
To perform numerical summation, use the evalf command in conjunction with the Sum or sum command. For more information, see the evalf/Sum help page.
The evalf command returns a floating-point or complex floating-point number or expression.
Numeric Precision
You can control the precision of all numeric computations using the environment variable Digits. By default, Digits is assigned the value 10, so the evalf command uses 10-digit floating-point arithmetic.
You can assign any positive integer that does not exceed the kernelopts(maxdigits) value to Digits. For more information, see kernelopts.
To specify the numeric precision for an evalf computation without changing the value of Digits, use the optional index in the calling sequence, that is, evalf[n](expression).
You can extend the evalf command interface to evaluate new constants and functions.
To define a new constant K, you must define a procedure `evalf/constant/K`. Then the calling sequence evalf(K) and more general evalf(expression) calling sequences, in which expression contains K, invoke `evalf/constant/K`().
If you define a procedure `evalf/f`, the calling sequence evalf(`f`(arguments)) and more general evalf(expression) calling sequences, in which expression contains `f`(arguments), invoke `evalf/f`(arguments).
Note: To call `evalf/f`(arguments) if floating-point arguments are specified (without requiring the use of unevaluation (right) quotes), use type checking. For an example, see the Examples section.
Most initially known mathematics functions automatically invoke the corresponding evalf subfunction if they are passed a floating-point argument.
evalf⁡π
3.141592654
evalf15⁡53⁢exp⁡−2+3⁢I⁢sin⁡π4
−0.157898022493763+0.0225078172647505⁢I
evalf⁡cos⁡1+sin⁡1⁢I
0.5403023059+0.8414709848⁢I
evalf⁡34⁢x2+13⁢x−sqrt⁡2
0.7500000000⁢x2+0.3333333333⁢x−1.414213562
Numeric Integration
To compute a numeric approximation to an unevaluated integral returned by the Int or int command, use the evalf command.
int⁡exp⁡x3,x=0..1
∫01ⅇx3ⅆx
evalf⁡
1.341904418
evalf⁡Int⁡tan⁡x,x=0..π4
0.3465735903
Numeric Summation
To compute a numeric approximation to an unevaluated sum returned by the Sum or sum command, use the evalf command.
sum⁡exp⁡x,x=RootOf⁡_Z5+_Z2+1
∑x=RootOf⁡_Z5+_Z2+1⁡ⅇx
4.462691252+0.⁢I
evalf⁡Sum⁡1sqrt⁡x,x=1..1000
61.80100877
When not to use evalf
There are times when using the evalf command causes problems mathematically. For example, the rounding error in floating-point values can give incorrect solutions to further computations. The following example does not work if you evaluate to a floating-point value too early in the computation.
limit⁡n⁢13−13+1n,n=∞
19
limit⁡n⁢evalf⁡13−13+1n,n=∞
Float⁡-∞
Adding a New Function and evalf Subroutine
When you specify floating-point arguments in a call to the sin function, it automatically returns a floating-point result.
sin⁡3.5+4.5⁢I
−15.79019836−42.14337074⁢I
You can define a new function and corresponding evalf subroutine such that the evalf subroutine is called if the arguments are of floating-point type. To clearly show which code Maple uses, in the following example, the mathematical function returns 2 times the argument for non-floating-point input and 2.01 times the argument for floating-point input.
NewFunction := proc(x) local s; if type(x,'complex'('float')) then s := evalf('NewFunction'(x)); if type(s,'complex'('float')) then return s; end if; end if; return 2*x; end proc:
`evalf/NewFunction` := proc(xx) local x; x := evalf(xx); if not type(x, 'complex'('float')) then return 'NewFunction'(x); end if; return 2.01*x; end proc:
You can always use the evalf subroutine by directly calling it or placing unevaluation quotes around instances of the function name.
evalf⁡NewFunction⁡π
6.283185308
`evalf/NewFunction`⁡π
6.314601235
NewFunction⁡3
6
NewFunction⁡3.0
6.030
See Also
constant
Digits
evalf/Int
evalf/Sum
Extension Mechanisms
fdiff
float
fsolve
hypergeom
initialconstants
initialfunctions
kernelopts
Maple_floats
Numeric Computation in Maple
Numerical approximation to derivative at a point
Unevaluated Expressions
Download Help Document