[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference rusure::math

Title:Mathematics at DEC
Moderator:RUSURE::EDP
Created:Mon Feb 03 1986
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2083
Total number of notes:14613

1008.0. "HELP - INTEGRALS & DERIVATIVES" by RAIN::ZELISKO () Thu Jan 05 1989 11:29

    
    Does anyone have a Pascal procedure/program for caculating
    Derivatives and Integrals.  I'm asking for Pascal only because
    it's my language of choice, any Fortran or "C" programs would
    also be of help. Any help would be greatly appreciated !!
    
T.RTitleUserPersonal
Name
DateLines
1008.1Need more definitionAKQJ10::YARBROUGHI prefer PiThu Jan 05 1989 15:0910
>    Does anyone have a Pascal procedure/program for caculating
>    Derivatives and Integrals.  

Of what? You haven't said what your needs are. Do you want a fast
approximation or a slow exact solution? Do you want a numerical approximation
or a symbolic result? Are your functions specified by arrays of points or by
formulas? Are you sure you want to do calculus, or would geometry or algebra
be sufficient? 

Lynn
1008.2Input and output in SymbolsRAIN::ZELISKOFri Jan 06 1989 11:525
    re .1   I would like to be able to enter the function specified
    by a formula. That is enter the function 6 * X ** 2 and obtain
    the first derivative as 12X. 
    
1008.3BEING::POSTPISCHILAlways mount a scratch monkey.Fri Jan 06 1989 12:2717
    Re .0:
    
    Not every symbollic expression can be integrated, and it's not easy to
    write a program that can integrate many of those that can be
    integrated. 
    
    Derivatives aren't too hard to compute symbollically.  There's a
    calculator that does it, the HP-28S.  What functions do you want
    besides arithmetic (addition, multiplication, exponentation)?  You
    would first need to write a parser.  I entered a simple parser in the
    VAXC conference which reads an expression and converts it to RPN.  In
    the process, it builds a tree representing the expression.  It would
    not be hard to write a function which acts upon the tree to compute the
    derivative.  I may take a look at it later today.
    
    
    				-- edp 
1008.4Try MAPLE, if that's what you REALLY needNIZIAK::YARBROUGHFri Jan 06 1989 13:078
    There are tools to do what you want - MAPLE, discussed elsewhere
    in this conference, will do all that and much more. Still, that's
    not something that you can include in a program to ship to a customer.
    So again, we could be of more help if we understood what the real
    problem is. E.g. are you trying to gun a calculus course, or build
    a new storage device?       
    
    Lynn 
1008.5small C program to do integralSTAR::ABBASIThu Dec 26 1991 12:1787
i wanted to implement Riemman-integral definition by a program,
to calculate the integral (in Riemman sense) we divide the interval [a,b]
into any partition, and take the limit as the size of the largest partition 
goes to zero of this sum

         sum_ {i=1..n} { f(y(i)) * (x(i)-x(i-1))   
         for ANY y(i) in [x(i-1),x(i)]

assuming we divide the interval into equal sized parts, then all what
we have to do is just pick the value of the function at any *arbitrary* 
point within each part of the divided intervals.

the definition of Riemman integral do not say how to select the point y(i),
it could be mid point in interval [x(i-1),x(i)] or could be near the edge
of the part.

but for numerical calculations, i find that i get the correct answer *faster*
if i choose y(i) to be mid-point of the interval. 

if i choose it near the edge, i have to divide the interval [a,b] into many
more parts to zoom into the same answer given by choosing  y(i) mid-point and
with less number of parts.

so it seems that one must select the mid point for fastest method ..
i just looked at this today. and tried it on sin(x), cos(x) only..

offcourse the definition of Riemman-integral did not say that because
as the limit of the part-size goes to zero, it does not really matter
where we pick y(i) at, but it matters for numerical integration.

any way this is the sample program:
----------------------------------------------------------------------------
/* do integration based on Riemman-definition of integration */
/* to change the function, edit, and  replace cos() below by any other  */

#include <stdio.h>
#include <math.h>

main()
{
double point;
double upper_limit,lower_limit;
double dx;
double so_far_in_main_interval;
double number_of_parts,total_fy,FY;
double dx_multiple;
int i;

printf("enter number of partitions to divide the interval to>");
scanf("%f",&number_of_parts);

printf("lower limit of interval ?>");
scanf("%f",&lower_limit);

printf("upper limit of integral ?>");
scanf("%f",&upper_limit);

/* here input .5 for fastest results */
printf("dx multiple [example .5 for mid point, .25 for 1/4 from left edge] ?>");
scanf("%f",&dx_multiple);

dx = (upper_limit-lower_limit)/(number_of_parts) ;
total_fy= 0.0;
so_far_in_main_interval = 0.0;

for(i=1; i<= (int)number_of_parts; i++)
   {
   /* calculate the point in the main interval */
   point = (double)(so_far_in_main_interval+(double)(dx_multiple*dx));

   /* move to next segment for next loop cycle */
   so_far_in_main_interval = so_far_in_main_interval + dx;
   
   FY = cos(point);

   
   total_fy = total_fy + FY;
   }

/* since division are equal, we just multiple by fy accumlator to find I */
FY= dx * total_fy;

printf("integral value = %f\n",FY);
}


    
1008.6theory versus practiceALLVAX::JROTHI know he moves along the piersThu Dec 26 1991 12:3119
    Have a look thru Davis and Rabinowitz, "Numerical Integration"
    (or some title like that), Academic Press for treatment of
    the issues around approximating integrals (versus the theoretical
    issues whether they exist or not.)  It is very important to
    choose the sample points for the function correctly, often
    to get an answer at all!

    Elementary treatments of integration, convergence of power series,
    etc. rarely if ever talk about how fast successive approximants
    converge.

    For example, consider the "root test" and "ratio test" for convergence
    of a power series.   It turns out that the ratio test converges to
    the true radius of convergence faster than the root test (if the former
    exists...)  [Actually, you can estimate radius of convergence even
    faster with roots of Hadamard polynomials - again if they exist -
    look at Henrici's NBS paper on the Quotient-Difference algorithm.]

    - Jim
1008.7math and computers..STAR::ABBASIThu Dec 26 1991 21:277
    that reminds me of a say by Knuth(?) where he said the difference
    between a mathematician and computer scientist, is that the mathematician
    dont worry how long it takes to calculate, but the computer scientist
    does....

    /nasser
    
1008.8comparing root, ratio tests for power seriesSTAR::ABBASIFri Dec 27 1991 03:1281
    ref .6 (Jim)
    
    i wanted to see if you are right (not that i ever doubted you :-) and
    this is what i came up with:
    
                                oo
                               ---         n
a power series is of the form  \     a(n) z
                               /
                               ---
                               n=1

it is a class of what is called series of variable terms, since z is
variable. to distinguish it from series with just a(i) terms, where "a"
is constant coefficient offcourse.

the root test is
-----------------

        ---    n -------
let L = lim    \/  |a(n)|
        n->oo

if L=0, series converges everywhere, i.e. ROC is everywhere
if L=+oo, series diverges everywhere except at z = 0. i.e. ROC=0
if 0<L<+oo , the radius of convergence (ROC) is 1/L, i.e. series is abs.
   converges for |z|< 1/L and diverges for |z|>1/L, when |x|=1/L we are not sure.

the above formula for L is called Cauchy-Hadamard formula. 

if the series has ROC > 0, we can say that as long as |z| within the ROC,
the value of the limit is a function of z, i.e. we can say

         +oo
         ---       n
f(z)=    \   a(n) z    , for all |z| < radius of converges
         /
         ---
        i=n

these functions are called analytic or regular, and are very important, they
are the main focus of cauchy integral formula, and residues theorems and
cauchy analytic theory etc..

actually, one definition of an analytic function is that it can be represented
by a power series..

Ratio Test
-----------

using d'Alembert's test, the variable term series converges for those
values of z which

            | a(n+1) |
     lim    | ------ | |z| < 1
     n->oo  | a(n)   |

                                             | a(n)  |
i.e. ROC is        1            =    lim     | ----  |
             --------------          n->oo   | a(n+1)|
             lim  | a(n+1) |
            n->oo | -----  |
                  | a(n)   |

and the series converges for all |z| < ROC and diverges for |z| > ROC
compare to root test
               1
       ---------------------
ROC =  lim    n  /--------
       n->oo   \/  |a(n)|

and the claim by Jim is that ratio test is faster...the root test has a 
nth root in it and division, the ratio only a division..so..it seems that
    Jim is right..

i leave hadamard polynomials for later, i could not find a ref. for it
now and i dont have that reference Jim mentioned, although i do have Knoop 
"theory and applications of infinite series"..

/nasser
    
1008.9how to find which coverges faster STAR::ABBASIFri Dec 27 1991 11:4520
    i think how i find which expression converges faster is not too accurate.
    
    one needs to find "rate of convergence", and see which test converges
    faster to the limit as n->oo ... i guess one can say
    
    if Ratio_test/Root_test > 1 for all n after some N, then Ratio_test
    will aproach limt L faster... right?
    
    i.e  
    
          | a(n)   |     ----------
          | ------ | n  / |a(n)|
          | a(n+1) |  \/
    
    if we can find N such that for all n>= N the above is > 1, then the
    ratio test converges faster the the root test..
    just what intution tells me, and befor having my morning coffe too..so
    that is my execuse if iam wrong..:-)
    
    /nasser