evalf - Maple Programming Help

Online Help

All Products    Maple    MapleSim


Home : Support : Online Help : Mathematics : Group Theory : Numbers : Numerical Functions : evalf : evalf/details

evalf

evaluate using floating-point arithmetic

 

Calling Sequence

Parameters

Basic Information

Description

Output

Constants and Mathematical Functions

Examples

Calling Sequence

evalf(expression)

evalf[n](expression)

Parameters

expression

-

expression to be evaluated

n

-

(optional) posint; specifies number of digits

Basic Information

• 

This help page contains complete information about the evalf command. For basic information on the evalf command, see the evalf help page.

Description

• 

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.

Output

• 

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

Constants and Mathematical Functions

• 

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.

Examples

evalfπ

3.141592654

(1)

evalf[15]5ⅇ2+3Isinπ43

0.157898022493763+0.0225078172647505I

(2)

evalfcos1+sin1I

0.5403023059+0.8414709848I

(3)

evalf3x24+1x32

0.7500000000x2+0.3333333333x1.414213562

(4)

Numeric Integration

  

To compute a numeric approximation to an unevaluated integral returned by the Int or int command, use the evalf command.

∫01ⅇx3ⅆx

∫01ⅇx3ⅆx

(5)

evalf

1.341904418

(6)

evalf∫0π4tanxⅆx

0.3465735903

(7)

Numeric Summation

  

To compute a numeric approximation to an unevaluated sum returned by the Sum or sum command, use the evalf command.

x=RootOf_Z5+_Z+1ⅇx

x=RootOf_Z5+_Z+1ⅇx

(8)

evalf

4.791792042+0.I

(9)

evalfx=110001x

61.80100877

(10)

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.

limn→∞n1313+1n

19

(11)

limn→∞nevalf1313+1n

Float∞

(12)

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.

sin3.5+4.5I

15.7901983642.14337074I

(13)
  

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.

evalfNewFunctionπ

6.283185308

(14)

`evalf/NewFunction`π

6.314601235

(15)

evalf'NewFunction'π

6.314601235

(16)

NewFunction3

6

(17)

NewFunction3.0

6.030

(18)

See Also

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

Was this information helpful?



Please add your Comment (Optional)
E-mail Address (Optional)
What is ? This question helps us to combat spam