This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Codes and outputs for HW 6 21.1) by hand, I have it with me 21.2) % Calculates the Left, Right, and Trapezoidal estimations of the %Integral % of f(x) from a to b. function [L R T] = myints(f,a,b,n) format long x = linspace(a,b,n+1); y = f(x); L = 0; R = 0; dx = (ba)/n; %since we intend for the evaluation points to be evenly %spaced for i = 1:n L = L + y(i); R = R + y(i+1); end L = L*dx; R = R*dx; T = (L+R)*.5; Results: >> [L R T] = myints(f,1,2,4) L = 1.166413628918445 R = 1.269967019511719 T = 1.218190324215082 >> [L R T] = myints(f,1,2,100) L = 1.216879128301471 R = 1.221021263925202 T = 1.218950196113336 22.1) by hand, I have this with me 22.2) % Calculates the Left, Right, and Trapezoidal estimations of the %Integral % of f(x) from a to b. function M = mymidpoint(f,a,b,n) format long x = linspace(a,b,n+1); y = f(x); M = 0; for i = 1:n M = M + ((y(i)+y(i+1))/2)*(x(i+1)  x(i)); end Results >> M = mymidpoint(f,1,2,4) M = 1.218190324215082 >> M = mymidpoint(f,1,2,100) M = 1.218950196113336 22.3) function S = mysimpson(f,a,b,n) if rem(n,2) ~= 0 error( 'n must be even' ) end x = linspace(a,b,n+1); y = f(x); S = 0; w = ones(n+1,1); for i = 2:n if rem(i,2)==0 w(i)=4; else w(i)=2; end S = S + w(i)*y(i); end S = (S + y(1) + y(n+1))*((ba)/(3*n)); Results: >> S = mysimpson(f,1,2,4) S = 1.218945156857086 >> S = mysimpson(f,1,2,100) S = 1.218951416480312 23.1) Since 3 – (3) = 6, selecting m = 60 would let h = .1 and because 2 – (2) = 4, letting n = 40 would also let k = .1; thereby producing the following image: 23.2) The following creates the coordinates for t riangles in a hexagonal region with a...
View
Full Document
 Spring '08
 Staff
 step size

Click to edit the document details