Your job in this project: write a set of routines for finding the root of a function, and compare them in action.
You may not use Scilab's built-in functions for finding roots -- instead, please implement two different algorithms yourself. You will need to write two functions for this project, one for each of the following methods:
You'll need to create two different Scilab source code files this week:
Your two functions should look like this:
function root = root_bisect(start_range, end_range, epsilon, func) function root = root_newton(start_range, end_range, epsilon, func, deriv)where
root is the output argument. The function should return a single floating point value, which is a root of the given 'function' start_range is the start of the interval in which to search end_range is the end of the interval in which to search epsilon is the fractional relative error to use as a termination criterion func is the name of a function to evalulate deriv is the name of another routine, which is the derivative of the 'func' (this is needed only for Newton's method)
Use each of the 2 methods on the following problems. Note that the trigonometric functions take arguments in RADIANS, not degrees.
Please note that the goal is to find roots which lie within the given intervals. Beware Newton's method: even if you start somewhere inside the interval, the method may pick a next guess which is somewhere outside the interval...
In each case, make a table which shows
fractional estimated error in root value (epsilon) = 10^(-6)
You should include a limit on the maximum number of iterations which any method can use; try setting a limit of 1,000,000 iterations. If, after that number of iterations, the method doesn't converge within the termination criterion, cause the function to call the error routine.
Make sure that you don't divide by zero.
Your functions will also be evaluated on their performance in finding the roots of OTHER functions, not listed above. You might want to do some extra tests yourself.
Bells and Whistles
This page maintained by Michael Richmond. Last modified March 27, 2007.
Copyright © Michael Richmond. This work is licensed under a Creative Commons License.