function simpleplot(a,b,n) % This is a simple Matlab routine to plot a function % on the interval [a,b] using n uniformly spaced % points. The function should be called f.m and % be located in a directory in the Matlab path. % f.m should accept an input x and give back a value % y=f(x) % % Matlab can plot sets of points with or without lines % joining the points. The basic Matlab plotting function % is plot.m. It accepts as input two arrays of the same % length, the first array holds the independent variable % and the second, dependent variable. % begin the plotting by defining the arrays hold the function information % We define a set of plot points by taking n+1 equally spaced points % between a and b. The first and last points align with a and b. delta = (b-a)/n; %this is the step size between plotting points % We use a loop to define the plotting points and the corresponding % function values. for i = 1: n+1 x(i) = a+ delta*(i-1); y(i)=f(x(i)); end % Now call the built-in Matlab plotting function plot(x,y) % we define a string that holds the title of the plot graphof=strcat('Graph of f(x)'); % tell the plot function the name of the plot title(graphof) % tell the plot function the name of the horizontal axis xlabel('x')