P17_5 - fx(3))/2 f %trapsimp = (x1(2) - x1(1))*(fx(1) +...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function P17_5 f a = 0; b = 0.6; b x1 = [0 0.05 0.15 0.25 0.35 0.475 0.6]'; x fx = [2 1.8555 1.5970 1.3746 1.1831 0.9808 0.8131]'; f analytic = (-2/1.5)*exp(-1.5*b) - (-2/1.5)*exp(-1.5*a) a trap = 0; t for i = 1:6 f trap = trap + (x1(i+1) - x1(i))*(fx(i) + fx(i+1))/2; t end e trap t trapsimp = 0; t %You can use simpsons rule for the equally spaced sets of 3 and then use %the trapezoid rule for the two sets of two points that are not equally %spaced % for i = 3:2:5 f trapsimp = trapsimp + (x1(i+2) - x1(i))*(fx(i) + 4*fx(i+1) + fx(i+2))/6; t end e trapsimp = trapsimp + (x1(2) - x1(1))*(fx(1) + fx(2))/2 + (x1(3) - x1(2))*(fx(2) +
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fx(3))/2 f %trapsimp = (x1(2) - x1(1))*(fx(1) + fx(2))/2 + (x1(4) - x1(2))*(fx(2) + 4*fx(3) + (x1(5) - x1(4))*(fx(4) + fx(5))/2 + fx(4))/6 + (x1(7) - x1(5))*(fx(5) + 4*fx(6) + fx(7))/6 f simp38_25 = (x1(5) - x1(2))*(fx(2) + 3*fx(3) + 3*fx(4) + fx(5))/8 s trap_12 = (x1(2) - x1(1))*(fx(1) + fx(2))/2 t simp_57 = s trapsimp = trap_12 + simp38_25 + trap_56 + trap_67 t function new = f(x) f new = 2*exp(-1.5*x)...
View Full Document

This note was uploaded on 09/21/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

Ask a homework question - tutors are online