next up previous
Next: Another case: the method Up: tutorial3 Previous: Coding the fixed-point iteration

Use a MATLAB function file for \bgroup\color{red}$g(x)$\egroup


\bgroup\color{red}\framebox{\em MAKE A NEW FILE}\egroup \bgroup\color{black}$\phantom{0}$\egroupNow make the iteration code more flexible by creating a MATLAB function file using the editor (see MATLAB functions and globals). This file will be called g.m. Calls to cos(x) in iteration.m are replaced with calls to g(x). The code should be of the form:

function [y] = g(x)
% 
%  function [y] = g(x)
%

   y = cos(x);
Note the use of comments immediately after the function header. This serves two purposes. One is the obvious documentation of the function file. The second is that the help command in MATLAB will now give information about your new function. Try help g to find out what happens.



Charlie Macaskill 2004-07-26