[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: C Program confused me



That's a kludgy version of the MacLaurin Series for arctan x= sum (n=0
to infinity) of (-1)^n *x^(2n+1)/2n+1 where x=4 to solve for Pi.  Most any
Calculus text should have an explanation of it in its section of Power
Series, or at least in its Index under Maclaurin series or Taylor series
(a more general classification).  


On Fri, 12 Mar 1999, Bal K. Paudyal wrote:

> Hello Friends,
> 
> I encountered following program in one of the Linux Howtos. This calculates
> the value of pai. But how does it do this? I am not asking the programming
> details, but on what theory the formula is based on. Can anybody help? Is
> there any better place to look for help?
> 
> 
>  
> ---------------------------------------
> #include <stdlib.h>;
>  #include <stdio.h>;
> 
>   main(int argc, char **argv)
>   {
>     register double width, sum;
>     register int intervals, i;
> 
>     /* get the number of intervals */
>     intervals = atoi(argv[1]);
>     width = 1.0 / intervals;
> 
>     /* do the computation */
>     sum = 0;
>     for (i=0; i<intervals; ++i) {
>       register double x = (i + 0.5) * width;
>       sum += 4.0 / (1.0 + x * x);
>     }
>     sum *= width;
> 
>     printf("Estimation of pi is %f\n", sum);
> 
>     return(0);
>   }
> --------------------------------
> 
> 
> -- 
> Unsubscribe?  mail -s unsubscribe debian-user-request@lists.debian.org < /dev/null
> 

Pardon me, but you have obviously mistaken me for someone who gives a
damn.
email galt@inconnu.isu.edu


Reply to: