Now 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.