Bob Homework 6

Bob Homework 6 - Homework 6 Lectures 21-24 Math 344 Ohio...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Homework 6 Lectures 21-24 Math 344 Ohio University Spring Quarter 09-10 Bob Benjamin Astrom Elbert Note: In the problems represented in this homework the percent error has values that are negative. The percent error is always positive however for some of the problems it is required to examine which direction (positive or negative) the error is. For this reason the absolute value has been removed from the percent error. 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) L = 1.166413628918445 R = 1.269967019511719 T = 1.218190324215082 >> n = 100; >> [L R T] = myints(f,a,b,n) L = 1.216879128301471 R = 1.221021263925201 T = 1.218950196113336 The percent error was calculated by adding a few extra lines of code on to the program. The extra code uses symbolic variables to calculate the definite integral with bounds a and b and then the percent error was calculated using the definite integral as the accepted value. function [L R T] = myintslong(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 % as well as the percent error associated with each method % 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 format long 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 syms x y % Allow x and y to be symbolic true = int(f(x),x,a,b); % Definite integral true answer...
View Full 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 / 17

Bob Homework 6 - Homework 6 Lectures 21-24 Math 344 Ohio...

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

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