function area = int_function_template(x_low,x_high,dx) % function area = int_function_template(x,dx) % Numerical integration of the function y = x.*2 % Input parameters % x_low = lower limit of the domain of x % x_high = upper limit of the domain of x % dx = spacing of x-values % Example % x_low = 0; % x_high = 10; % dx = 0.1; % area = int_function_template(x_low,x_high,dx); % Steve Martel % Date 8_26_04 % Create an array of x-vales from x_low to x_high x = ; % Determine how many values of x there are n = ; % Break the set of x-values into two sets, % one that has all values but the last, % the other that has all values but the first x_beg = ; x_end = ; % Calculate y at the values of x, x_beg, and x_end y = ; y_beg = ; y_end = ; % We don't use these values here % Sum up the area of the rectangles to get the cummulative area area = ; % Plot figures % Open up a figure window called "figure 1" figure(1) % Clear the figure clf % Plot the curve y = x.^2 on figure 1 plot(x,y) % Keep the figure window to plot another curve hold on % Plot a red stairstep approximation of the curve stairs(x,y,'r') % Add title and labels to axes title('y=x^2') xlabel('x') ylabel('y') % Open up a figure window called "figure 2" figure(2) % Clear the figure clf % Plot the analytical solution for the area plot(x,(1/3)*x.^3) % Keep the figure window to plot another curve hold on % Plot the area under the curve y = x.^2 on figure 2 plot(x_end,area,'r') % Add title and labels to axes title('Area under y=x^2 and numerical approximation (red)') xlabel('x') ylabel('y')