next up previous
Next: The fixed-point iteration method Up: tutorial3 Previous: The test function

Graphing the test function


\bgroup\color{red}\framebox{\em ADD CODE TO FILE}\egroup \bgroup\color{black}$\phantom{0}$\egroup Include two MATLAB input statements in the file iteration.m, e.g.

a= input(' enter the value of the lh end of the interval: ');

to enter the the end-points of the plotting interval for the problem above from the keyboard and store them in MATLAB variables a and b. For our first case these will take the values 0 and \bgroup\color{black}$\pi$\egroup respectively.

In the editor, save the file iteration.m and then run this MATLAB script by typing

>> iteration

at the MATLAB prompt ( >>) . The script should ask you to enter values for a and b. Make sure you do this.

\bgroup\color{red}\framebox{\em ADD CODE TO FILE}\egroup \bgroup\color{black}$\phantom{0}$\egroupCreate a MATLAB vector x running from a to b in steps of 0.01 (MATLAB vectors ) .

\bgroup\color{red}\framebox{\em ADD CODE TO FILE}\egroup \bgroup\color{black}$\phantom{0}$\egroupUse the MATLAB plot command (see plotting ) to plot the function \bgroup\color{black}$f(x)=\cos x-x$\egroup above as a function of \bgroup\color{black}$x$\egroup. Use a blue line for the plot.

In the editor, save the file iteration.m and then type iteration at the MATLAB prompt.

Your graph should appear as Figure 1. Use the zoom command in the figure (click the magnifying glass) and then hold down the left mouse key near the root \bgroup\color{black}$x_0$\egroup, drag the mouse and release the key to allow you to estimate the value of \bgroup\color{black}$x_0$\egroup.

\bgroup\color{red}\framebox{\em ADD CODE TO FILE}\egroup \bgroup\color{black}$\phantom{0}$\egroupAdd the commands zoom on and grid on just after the plot command, then save and re-run iteration.m. You can now estimate the root \bgroup\color{black}$x_0$\egroup as accurately as you wish.

\bgroup\color{blue}\framebox{\em CHECKPOINT: submit solution}\egroup \bgroup\color{black}$\phantom{0}$\egroup \bgroup\color{red}\framebox{ 1.}\egroup Record your estimate of the root to exactly four significant figures.


next up previous
Next: The fixed-point iteration method Up: tutorial3 Previous: The test function
Charlie Macaskill 2004-07-26