|
Initialization: Load the package and set the display of special functions in output to typeset mathematical notation (textbook notation):
|
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".
| |
How could we use this formula to numerically evaluate the function, for example for ? First put all the operands within the summation
Take now the summand and substitute in it the values for the function's parameters indicated
Construct a formula_procedure with this summand as a function of the summation index
You can now numerically evaluate
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
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)
But because of having assigned evalf/Y, however, you can numerically evaluate this function using evalf
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".
| |
Get the summand of the last sum in one go
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
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
Enter now the EI function with some parameters and evaluate it numerically using evalf
-> 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
| |
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
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
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
| |
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
As an example of a double sum, consider the AppellF2 function
Following the same steps outlined before, get the summand and construct a formula-procedure this time depending on 2 parameters and
from where a routine for the numerical evaluation of AppellF2, when the condition shown in the definition is satisfied, is
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
-> 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
| |
Compare with the numerical value obtained using the standard Maple AppellF2 function