[Santa Clara University]
Department of Mathematics
and Computer Science

Machine Problem 2

CS/Math 166 -- Winter, 2018
D. C. Smolarski, S.J.

              
20 points
DUE: noon: Friday, Jan 26, 2018

This is a program designed to teach you how to deal with a "black box" input, i.e., a function for which you may not know the analytic (algebraic) form, but for which you can get an output value, after giving it an input value.

Because of the different platforms on which people work, and the different programming language backgrounds, a "black box" (e.g., pre-compiled) version of a function will not be provided.

Please use Matlab/Octave and make use of the following Matlab/Octave code:


%file: f1.m
 function [out] = f1(x)
   out = (x-0.98543)*(x-pi)*(x-exp(1))*(x+7.0);
 return;

Pretend you do not know what the roots of this function are!

Assume you are told that function f1 has between 2 and 5 roots between -10 and 10. (You can view the function at this link and save it locally.)

You are to use the secant method to find the all the roots of f1. You may want to use the algorithm presented in the notes on page 3-9 or in Burden/Faires on page 71.

SUGGESTIONS:

First: Run a short code evaluating the function f1 at evenly spaced x-values (e.g., every .5 units) in the given range (i.e., from -10 to 10). Then, by "eye-balling" the output determine intervals that include a root (i.e., intervals over which the function value changes sign).

Second: Run the secant method code as many times as needed to determine the exact roots using as initial values the interval end-points determined via the previous step.

NOTE: Some people may want, in fact, to write one piece of code that incorporates both steps, i.e., a scanning phase that determines when the function changes sign, at which time, the secant solver is called to determine the exact root, and afterwards the scanning phase continues.

The main point of this program is to make use of the secant method to find roots! The program codes should have good style -- with indentation and comments -- and the output should be commented, but I am primarily looking to see if you can code the secant method correctly and find multiple roots rather than a "clever" and highly polished program.

Your program may be turned in to my office, O'Connor 7, or to my mailbox in O'Connor 31. Please staple the pages yourself and do not turn in disconnected pages!


This page is maintained by Dennis C. Smolarski, S.J. Email: dsmolarski at scu.edu
Last changed: 3 November 2017.