Exercise 1

Come up with a function that solves the following problem:

Suppose you want to plot a function in Matlab, but you want to do so with as few points as possible. Unfortunately, what may happen is that you may miss something interest such as a maximum or a minimum. Thus, what we want is a function that first plots a function f (given by the user) using 10 points on a specified interval. Calculate the width of the range by subtracting the minimum range value from the maximum range value.

Next, use twice as many points and, again, find the width of the range and see whether or not the width has increased by at least 1 %.

If it has not increased by more than 1 %, plot the function and return.

Otherwise, continue doubling the number of points for a maximum of N times, each time checking whether or not the width of the range has increased by more than or less than 1 %. After N iterations, just plot the function with the last set of points.

Be sure to give the function a reasonable name, determine the parameters that are necessary, and come up with a few test cases.