CS 221 Lab 9 Fall 2011: Root-finding

Out: 9 November 2011
Due: 17 November 2011

Note Well: The purpose of lab exercises is for you to learn how to solve problems using these tools. It is not for you to type something into MATLAB. As you go through the steps of each exercise, think about what you are doing and what the program is doing, and try to predict what you will see. If you don't understand something, ask your instructor -- that's what he's there for.


Part 1: General Problem-Solving

Your cousin Ella's 8th grade algebra class played a Halloween trick on Ms. Grundy. Ms. Grundy struck back with a trick of her own. For homework, along with equations like "x2 + 2 = 3x", she gave them this one:

Find all values of x for which 2x > x8. Also, graph the resulting inequality, 2x - x8 > 0.

Ella is fearful that this will ruin her life by destroying her perfect middle school grade point average. She is hoping that, as a bright engineering major at UK, you can help her. Don't let Ella down. Use MATLAB and/or Excel to help Ella solve this problem and convince Ms. Grundy that her solution is correct.

(Do this by solving the problem yourself and convincing your TA by showing him your files and graph and explaining the approach you took and why it gives a correct result. Make sure you fully explore the inequality to make sure you have found all the values of x that satisfy it. When your TA is convinced, zip your files together and upload them to CS Portal.)


Part 2: Implementing the Bisection Method

Write a function named bisection() that takes four arguments:

  1. A function handle (call it fun).
  2. A lower bound (call it lower).
  3. An upper bound (call it upper).
  4. Desired absolute allowable error bound (call it ebound).

The function should return a value (call it root) that is the estimated root of the function fun; the difference between the returned root and the actual root must be less than ebound.

Note the following:

To test your bisection function, create a function called equation():
function f = equation(x)
   f = 7*x-6;
end

Call your bisection function as follows: bisection(@equation, 0, 1, 0.0001).

(You should also test it with other functions, of course.)

Upload your function bisection.m to the submission portal as "Lab Ex 9, Part 2".