# Computing Pi as an Area 3

## Problem 1.

Below is a pseudoprogram for computing the area of the upper-right quadrant of the unit circle. Pi is four times this area. The idea behind the pseudoprogram is to approximate the quarter-circle by a union of rectangular strips. If we use n strips of equal width, then the width of each strip is 1/n. The left endpoint of the ith strip is at x = 1/n. Using the equation x^2 + y^2 = 1 for the circle we find the height of the strip, and hence its area. The sum of all these areas is an approximation to the area of the quarter-circle, which is what we need to compute the area.

In your write-up include (a) statement of the problem, (b) a picture which illustrates what is going on, (c) the text of the C program, (d) its output for n = 10, 100, 1000, where n is the number of subdivisions, per the discussion in class. Use your result to give approximate values of pi. Contrast and compare these with your previous method for computing pi. Finally, discuss the precision of your results.

```PSEUDOPROGRAM:

Given: n, the number of subdivisions and f, a function
Compute: the area under the graph of f between a and b

A <- 0                  # initialize the area to zero
a <- 0                  # left end point
b <- 1                  # right end point
x <- a                  # starting value of x
dx <- (b-a)/n           # the size of the subintervals
for i from 1 to n       # the loop (heart of this program)
A <- A + f(x)dx     # accumulate areas of strips in A
x <- x + dx         # advance x
```

## Problem 2

Modify your program to compute an approximate value of the integral of the cube root of 1 - x^2 on the interval [0,1]. Can you integrate this by standard analytical methods, e.g., the ones you learned in first-year calculus?

## Notes

You will need to use the sqrt function which is contained in the library <math.h>. To compile a program which uses the math library, imititate this example:
```  % gcc -o area area.c -lm
```
The option -lm stands for ``load math'' library. Below is an example of a simple (and silly) C program which uses <math.lib> and which must be compiled with the -lm option.
```#include <stdio.h>
#include <math.h>

main() {
float a = 2.0;
float b = sqrt(a);
printf(" result = %f\n", b );
b = exp(a);
printf(" result = %f\n", b );
b = log(a);
printf(" result = %f\n", b );
b = exp(log(a));
printf(" result = %f\n", b );
}
```

Back to syllabus
Back to Department of Mathematics, University of Utah