21.1 - 21.2) function [L R T] = myints(f,a,b,n) % Math 344...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
21.2) function [L R T] = myints(f,a,b,n) % Math 344 % Homework Problem 21.2 % Written by Astrom and Elbert % % Calculates the area under a function curve (integration) % using the Left and Right endpoint rules and the Trapezoid Rule % % inputs f, a, b and n % f is the function % a is the start point of integration % b is the end point of integration % n is number of intervals % The intervals have a start and end point which will % require n+1 points to make n intervals L = 0; % Set L to begin integration at 0 R = 0; % Set R to begin integration at 0 T = 0; % Set T to begin integration at 0 delta = (b-a)/n; % Width of interval x = linspace(a,b,n+1); % Vector of n+1 points y = f(x); % Set function to variable y for i = 1:n % Loop to calculate area L=L+y(i)*delta; % Calculate using Left point R=R+y(i+1)*delta; % Calculate using Right point T=T+(y(i)+y(i+1))/2*delta; % Calculate using Trapezoid end % End calculation loop >> f = inline('sqrt(x)','x'); >> a = 1; >> b = 2; >> n = 4; >> [L R T] = myints(f,a,b,n)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/15/2011 for the course MATH 345 taught by Professor Staff during the Spring '08 term at Ohio State.

Page1 / 3

21.1 - 21.2) function [L R T] = myints(f,a,b,n) % Math 344...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online