Add - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


MathematicalFunctions[Evalf]

  

Add

  

numerically evaluate a formula depending on a parameter n, or two of them n and m, adding from n = 0, also from m = 0 if there are two parameters, until the result converges for the current value of Digits

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

Add(formula_procedure, N)

Parameters

formula_procedure

-

procedure depending on one or two parameters - say  or  and  - such that when they assume non-negative values the formula can be numerically evaluated

N

-

(optional) range of non-negative integers, or just a non-negative integer, indicating the summation range or the upper limit of a sum that starts at , for one or the two parameters  and . The default is infinity.

Description

• 

The Add command is used to numerically add a formula, that is passed as a procedure that depends on a single non-negative integer parameter, say , a summation index, or two of them, say  and . The summation over these parameters starts at 0 and is performed until the result converges (up to Digits). If the formula does not converge, the sum is interrupted when the number of terms added reaches , in which case a WARNING message explaining the situation is displayed on the screen.

• 

When a second argument  is passed, if it is a non-negative integer, the summation, that starts at , or  and  in the case of two parameters, is performed until the result converges (up to Digits) or . This second argument can also be passed as a range, say , in which case the summation will start at  until the result converges or  terms were added.

• 

The case of two parameters  and  is handled by rewriting the double sum from 0 to  as a single sum in only one parameter  from 0 to  according to

• 

Add uses option hfloat, which means that, depending on the mathematical contents of the formula_procedure passed, the numerical evaluation will be performed using hardware floating-point values. Depending on the operations performed, this can significantly speed up the execution of the procedure.

• 

Add is mainly useful to numerically evaluate mathematical expressions or functions that can be represented as an infinite sum. In these cases, with Add you can do:

– 

a fast implementation of a numerical evaluation procedure for the expression (see the Examples section);

– 

fast experimentation with different formulas, for instance comparing their performance for numerically evaluating the expression.

Examples

  

Initialization: Load the package and set the display of special functions in output to typeset mathematical notation (textbook notation):

(1)

Basically all mathematical functions can be represented by a infinite sum. You can query about this sum form of a mathematical function using the FunctionAdvisor. As an example, consider the infinite sum representation for the spherical harmonic SphericalY function

* Partial match of "sum" against topic "sum_form".

(2)

How could we use this formula to numerically evaluate the function, for example for ? First put all the operands within the summation

(3)

Take now the summand and substitute in it the values for the function's parameters indicated

(4)

(5)

Construct a formula_procedure with this summand as a function of the summation index

(6)

You can now numerically evaluate

(7)

To transform this formula into a procedure for the numerical evaluation of SphericalY for arbitrary arguments, construct with the summand a generic formula, depending on all the parameters, and as a function of the summation index, then use the extension mechanism of evalf, so define `evalf/Y` as shown below, where Y will represent the spherical harmonics function

(8)

(9)

Note the use of :-, necessary for the replacement to happen within general_formula. Alternatively, you could also write `evalf/Y` with the contents of general_formula explicitly present and in that way avoid entirely the need of the substitution of parameters by their actual values. Now, if you have not assigned a procedure to Y, it just echoes the function on the screen (i.e. the function returns unevaluated)

(10)

But because of having assigned evalf/Y, however, you can numerically evaluate this function using evalf

(11)

A plot of the real part of Y for  from 0 to

Compare with the same plot constructed using the standard Maple SphericalY function

As an example using an optional argument to specify the upper limit of the summation, consider the sum forms for the exponential-integral Ei function

* Partial match of "sum" against topic "sum_form".

(12)

Get the summand of the last sum in one go

(13)

Construct now a general formula-procedure as a function of the summation index, then a numerical evaluation procedure as done above for the function Y representing the spherical harmonics; call EI this function representing the exponential-integral

(14)

(15)

Note that the sum form we are using requires  to be a negative integer and also that the upper summation limit is equal to . In the `evalf/EI` procedure above, however, we have not specified either of these things. So, the numerical evaluation will be performed adding terms until the result converges. To see how many, turn on the infolevel for Add

(16)

Enter now the EI function with some parameters and evaluate it numerically using evalf

(17)

    -> entering Add with: 'formula' = 24/exp(21/50-3/10*I)/k!*(21/50-3/10*I)^(-5+k)
    <- exiting Add with -654.669541617+26.4271294535*I; after adding 17 terms

(18)

We see that not just 5 but 14 terms were added and at that point the result already converged. Check the value using the Maple standard Ei function

(19)

(20)

The two results obtained are close to each other but the level of accuracy is poor. The formula, in fact, for  is valid if we add only 5 terms. Redefine now `evalf/Ei` taking into account both that it expects  to be a negative integer and also that the upper summation limit is equal to

(21)

Clear the remember table of evalf and compute the value of Ei(-4, 21/50 - 3*I/10) again, checking the number of terms used: for  we expect 5 terms added

    -> entering Add with: 'formula' = 24/exp(21/50-3/10*I)/k!*(21/50-3/10*I)^(-5+k)

    <- exiting Add with -654.806301169+26.3925836556*I; after adding 5 terms

(22)

So now only 5 terms got added, as expected, and the accuracy of the result is much better. Also, if we pass a value of  that is not a negative integer, for instance , the numerical evaluation is halted with an error message

Error, invalid input: `evalf/EI` expects its 1st argument, a, to be of type negint, but received 1

As an example of a double sum, consider the AppellF2 function

(23)

Following the same steps outlined before, get the summand and construct a formula-procedure this time depending on 2 parameters  and

(24)

(25)

from where a routine for the numerical evaluation of AppellF2, when the condition  shown in the definition is satisfied, is

(26)

where we are calling  this representation of AppellF2. Consider now for instance some numerical complex values of the parameters  and numerically evaluate this  representation at those values

(27)

    -> entering Add with: 'formula' = add(pochhammer(1/2,k+m)*pochhammer(2/7,k)*pochhammer(-1/4,m)*(1/4*I)^k*(1/4)^m/pochhammer(2,k)/pochhammer(3/2+I,m)/k!/m!,m = 0 .. k)+add(pochhammer(1/2,n+k)*pochhammer(2/7,n)*pochhammer(-1/4,k)*(1/4*I)^n*(1/4)^k/pochhammer(2,n)/pochhammer(3/2+I,k)/n!/k!,n = 0 .. k-1)

    <- exiting Add with .983152249087+.272658733829e-1*I; after adding 19 terms

(28)

Compare with the numerical value obtained using the standard Maple AppellF2 function

(29)

(30)

Compatibility

• 

The MathematicalFunctions[Evalf][Add] command was introduced in Maple 2017.

• 

For more information on Maple 2017 changes, see Updates in Maple 2017.

See Also

Ei

evalf

Evalf command

Evalf package

forget

infolevel

MathematicalFunctions

plot

remember

SphericalY

unapply

 


Download Help Document