CS561 - Project

# CS561 Project 1

## 1. Project Description

Write the following 2 C++ functions that together will find the zero of a function f(x) in the interval (a, b):

• The main() function that reads in the interval points a and b, and invokes double Solve(f, a, b, eps) to determine a zero between a and b with precision eps.

The main() function must solve two different equations f1(x) = 0 and f2(x) = 0, by reading in two different pairs of values a and b, one pair used for f1(x) = 0 and the other pair for f2(x) = 0

The main() function must be in a file "main.C" by itself

• The function double Solve(double f(double), double a, double b, double eps) that determine a zero between a and b with precision eps.

The double Solve(f, a, b, eps) function uses the bisection method to find a root of an equation.

The Solve() function must also be in a file "solve.C" by itself

I have written two functions in two separate files and your main program must solve the following two functions using the Solve (bisection method):

You must not change any of these function files; simply save a copy of these files in your project directory (cs561) and use the multi-file compilation technique discussed in class to link them into your program.

(The simplest command that will link all the files together is:

```   CC -o main main.C solve.C pj1f1.C pj1f2.C
```
but that is not the most efficient way since it will recompile all files. You may use this for now, until we learn to use Makefiles...)

Before you can test your program, you must first figure out what initial interval you need to use in each function...

## 2. Bisection Method

The bisection method ensures that the sign of the function values at the end points of the solution interval are opposite (the value at one end is negative while the value at the other is positive).

The function value at middle of the interval is computed and the next solution interval is either the "left" interval or the "right" interval, depending on the sign of the function value at the midpoint:

The bisection method terminsates when the length of the solution interval is less than a prescribed precision eps. The value returned is the middle of the current solution interval.

To test if the sign of f(a) and f(b) are different, you can use:

 ``` f(a) * f(b) < 0 ```

## 3. Turn in

• Turn in the "main.C" file with the main function in using the command:
```     /home/cs561000/turnin main.C pj1
```

• Turn in the "solve.C" file with the Solve function in using the command:
```     /home/cs561000/turnin solve.C pj1a
```