clc clear all disp('ABSTRACT') disp(' Example showing the trapezoidal rule') % Example showing how to use loops to find the area under a curve disp(' ') % INPUTS disp('INPUTS') g=inline('x^2'); a=3.0; b=4.9; m=350; fprintf(' The function to be integrated is y=%s\n',char(g)) fprintf(' The lower limit is %g, and the upper limit is %g\n',a,b) fprintf(' The number of segments to use is %g\n\n',m) % CODE val=trapezoidal_rule(g,a,b,m); % OUTPUTS disp('OUTPUTS') syms x valexact=eval(int(char(g),x,a,b)); fprintf(' The exact value is %g, the approximate value is %g\n',val,valexact)