# Assignment 9

For this assignment you will write a Matlab function
called `trapplot`
that computes and plots a given function and its
'trapezoid' approximate. The function will take
four arguments: a function handle, the left endpoint
of the interval, the right endpoint, and the number of
subintervals.
You should also make Matlab functions to evaluate
the following mathematical functions. Use them to
test your plotting function.

- \[s(x) = x\sin\left(\frac1x\right);\ \text{and}\]
- \[b(x)=\begin{cases} 0 & x<\frac3{\sqrt{3}}\\ x & \text{otherwise}. \end{cases}\]

Figure 1. A sample plot

`x`containing the points where it should be evaluated. Make sure you use e.g. '.*' and '.^' notation to create your functions so they can take vector arguments. We emphasize that your functions

*must*accept vector arguments, and produce vectors that can be plotted from those. An example of a plot

`trapplot`will produce is shown in Figure 1. Observe the following.

- It has a title. The title tells how many subintervals were used - a number that varies with the arguments.
- The axes are labeled.
- The trapezoid segments are dashed with diamonds to show the points that determine them.
- The plot has a legend.

The assignment is turned in when the three .m files containing the scripts are received as an attachment to an email message in the instructor's inbox. If your function uses any other function file, be sure that is also attached to your message. The assignment is worth 40 points, and is due at 9:00 on Tuesday, 6 November.

Hint: The limit of \(x\sin\frac{1}{x}\) at 0 exists. We can evaluate the function there by a clever use of boolean vectors.

Assignment C is posted.

The test solution is available.