Integration by Parts Logarithms and More Riemann Sums! James K. Peterson Department of Biological Sciences and Department of Mathematical Sciences Clemson University September 16, 2013
Outline 1 IbyP with logarithms 2 Graphing Riemann Sums 3 Uniform Partition Riemann Sums
Abstract This lecture is going to talk about the new method of integration Integration by Parts again. Then we go back and talk about Riemann sums in Matlab again so we can learn how to draw a picture that represents the Riemann sum.
IbyP with logarithms We can use IbyP to handle ( some polynomial of t ) ln(t) dt. Example: (2t 2 + 4) ln(t)dt. We can complicate it a bit by letting the argument inside the ln be linear. Example: (2t 2 + 4) ln(5t)dt. And we can spin out more cases, but easier to see how it plays out with some examples.
IbyP with logarithms Example Evaluate ln(t) dt Solution Let u(t) = ln(t) and dv = dt. Then du = 1 t dt and v = dt = t. For the antiderivative v don t add an arbitrary constant C as we will add one at the end. Applying IbyP, ln(t) dt = udv = uv vdu = ln(t) t t 1 t dt = ln(t) t dt = t ln(t) t + C
IbyP with logarithms Example Evaluate t ln(3t) dt Solution Let u(t) = ln(3t) and dv = tdt. Then du = 3 3t dt = 1 t dt and v = tdt = t 2 /2. Using IbyP t ln(3t) dt = udv = uv vdu = ln(3t) t 2 /2 = t2 2 ln(3t) t 2 2 t/2 dt = t2 2 ln(3t) t2 4 + C 1 t dt
IbyP with logarithms Example Evaluate t 3 ln(8t) dt Solution Let u(t) = ln(8t) and dv = t 3 dt. Then du = 8 8t dt = 1 t dt and v = t 3 dt = t 4 /4. Applying Integration by Parts, we have t 3 ln(8t) dt = udv = uv vdu = ln(8t) t 4 /4 t 4 /4 1 t dt = t4 4 ln(8t) t 3 /4 dt = t2 2 ln(8t) t4 16 + C
IbyP with logarithms Example Evaluate (t 4 + 5t 2 + 8t + 9) ln(4t) dt Solution Let u(t) = ln(4t) and dv = (t 4 + 5t 2 + 8t + 9)dt. Then du = 4 4t dt = 1 t dt and v = (t 4 + 5t 2 + 8t + 9)dt = t 5 /5 + (5/3)t 3 + (8/2)t 2 + 9t. Applying Integration by Parts, we have (t 4 + 5t 2 + 8t + 9) ln(4t) dt = ln(4t)(t 5 /5 + (5/3)t 3 + (8/2)t 2 + 9t) (t 5 /5 + (5/3)t 3 + (8/2)t 2 + 9t) 1 t dt = ln(4t)(t 5 /5 + (5/3)t 3 + (8/2)t 2 + 9t) (t 4 /5 + (5/3)t 2 + (8/2)t + 9) dt = ln(4t)(t 5 /5 + (5/3)t 3 + (8/2)t 2 + 9t) (t 5 /25 + (5/9)t 3 + (8/4)t 2 + 9t) + C
IbyP with logarithms Homework 26 26.1 Evaluate ln(5t) dt 26.2 Evaluate 2t ln(t 2 ) dt 26.3 Evaluate (t 4 + 5t 8) ln(7t) dt 26.4 Evaluate 5 2 (t2 + 5t + 3) ln(t) dt
Graphing Riemann Sums If we want to graph the Riemann sums, we need to graph those rectangles we draw by hand. To graph a rectangle, we graph 4 lines. The MatLab command plot([x1 x2], [y1 y2]) plots a line from the pair (x1, y1) to (x2, y2). So the command plot([x(i) x(i+1)],[f(s(i)) f(s(i))]); plots the horizontal line which is the top of our rectangle.
Graphing Riemann Sums If we want to graph the Riemann sums, we need to graph those rectangles we draw by hand. To graph a rectangle, we graph 4 lines. The MatLab command plot([x1 x2], [y1 y2]) plots a line from the pair (x1, y1) to (x2, y2). So the command plot([x(i) x(i+1)],[f(s(i)) f(s(i))]); plots the horizontal line which is the top of our rectangle. The command plot([x(i) x(i)], [0 f(s(i))]); plots a vertical line that starts on the x axis at x i and ends at the function value f (s i ).
Graphing Riemann Sums The command plot([x(i+1) x(i+1)], [0 f(s(i))]); plots a vertical line that starts on the x axis at x i+1 and ends at the function value f (s i ).
Graphing Riemann Sums The command plot([x(i+1) x(i+1)], [0 f(s(i))]); plots a vertical line that starts on the x axis at x i+1 and ends at the function value f (s i ). To plot rectangle, for the first pair of partition points, first we set the axis of our plot so we will be able to see it. We use the axis command in Matlab look it up using help! If the two x points are x1 and x2 and the y value is f (s1) where s1 is the first evaluation point, we expand the x axis to [x1 1, x2 + 1] and expand the y axis to [0, f (s1)]. This allows our rectangle to be seen. The command is axis([x1-1 x2+1 0 f((s1))+1]);.
Graphing Riemann Sums The code so far Putting this all together, we plot the first rectangle like this: >> h o l d on % s e t a x i s so we can s e e r e c t a n g l e >> a x i s ( [ P( 1 ) 1 P( 2 )+1 0 f ( E ( 1 ) ) +1]) % p l o t top, LHS, RHS and bottom o f r e c t a n g l e >> p l o t ( [ P( 1 ) P( 2 ) ], [ f ( E ( 1 ) ) f ( E ( 1 ) ) ] ) ; >> p l o t ( [ P( 1 ) P( 1 ) ], [ 0 f ( E ( 1 ) ) ] ) ; >> p l o t ( [ P( 2 ) P( 2 ) ], [ 0 f ( E ( 1 ) ) ] ) ; >> p l o t ( [ P( 1 ) P( 2 ) ], [ 0 0 ] ) ; >> h o l d o f f We have to force Matlab to plot repeatedly without erasing the previous plot. We use hold on and hold off to do this. We start with hold on and then all plots are kept until the hold off is used.
Graphing Riemann Sums This generates the rectange we see below: Figure: Simple Rectangle
Graphing Riemann Sums To show the Riemann sum approximation as rectangles, we use a for loop in MatLab To put this all together, h o l d on % s e t h o l d to on f o r i = 1 : 4 % graph r e c t a n g l e s bottom = 0 ; top = f (E( i ) ) ; p l o t ( [ P( i ) P( i +1) ], [ f ( E ( i ) ) f ( E( i ) ) ] ) ; p l o t ( [ P( i ) P( i ) ], [ bottom top ] ) ; p l o t ( [ E( i ) E ( i ) ], [ bottom top ], r ) ; p l o t ( [ P( i +1) P( i +1) ], [ bottom top ] ) ; p l o t ( [ P( i ) P( i +1) ], [ 0 0 ] ) ; end h o l d o f f % s e t h o l d o f f
Graphing Riemann Sums Of course, we don t know if f can be negative, so we need to adjust our thinking as some of the rectangles might need to point down. We do that by setting the bottom and top of the rectangles using an if test.
Graphing Riemann Sums Of course, we don t know if f can be negative, so we need to adjust our thinking as some of the rectangles might need to point down. We do that by setting the bottom and top of the rectangles using an if test. bottom = 0 ; top = f (E( i ) ) ; i f f (E( i ) ) < 0 top = 0 ; bottom = f ( E ( i ) ) ; end
Graphing Riemann Sums All together, we have h o l d on % s e t h o l d to on [ s i z e P,m] = s i z e (P) ; f o r i = 1 : s i z e P 1 % graph a l l t h e r e c t a n g l e s bottom = 0 ; top = f (E( i ) ) ; i f f (E( i ) ) < 0 top = 0 ; bottom = f ( E ( i ) ) ; end p l o t ( [ P( i ) P( i +1) ], [ f ( E ( i ) ) f ( E( i ) ) ] ) ; p l o t ( [ P( i ) P( i ) ], [ bottom top ] ) ; p l o t ( [ E( i ) E ( i ) ], [ bottom top ], r ) ; p l o t ( [ P( i +1) P( i +1) ], [ bottom top ] ) ; p l o t ( [ P( i ) P( i +1) ], [ 0 0 ] ) ; end h o l d o f f ; We also want to place the plot of f over these rectangles.
Graphing Riemann Sums h o l d on % s e t h o l d to on [ s i z e P,m] = s i z e (P) ; f o r i = 1 : s i z e P 1 % graph a l l t h e r e c t a n g l e s bottom = 0 ; top = f (E( i ) ) ; i f f (E( i ) ) < 0 top = 0 ; bottom = f ( E ( i ) ) ; end p l o t ( [ P( i ) P( i +1) ], [ f ( E ( i ) ) f ( E( i ) ) ] ) ; p l o t ( [ P( i ) P( i ) ], [ bottom top ] ) ; p l o t ( [ E( i ) E ( i ) ], [ bottom top ], r ) ; p l o t ( [ P( i +1) P( i +1) ], [ bottom top ] ) ; p l o t ( [ P( i ) P( i +1) ], [ 0 0 ] ) ; end y = l i n s p a c e (P( 1 ),P( s i z e P ), 101) ; p l o t ( y, f ( y ) ) ; x l a b e l ( x a x i s ) ; y l a b e l ( y a x i s ) ; t i t l e ( Riemann Sum w i t h f u n c t i o n o v e r l a i d ) ; h o l d o f f ;
Graphing Riemann Sums We generate this figure: Figure: Riemann Sum for f (x) = x 2 for Partition {1, 1.5, 2.1, 2.8, 3.0}
Uniform Partition Riemann Sums To save typing, let s learn to use a Matlab function. In Matlab s file menu, choose create a new Matlab function which gives f u n c t i o n [ v a l u e 1, v a l u e 2,... ] = MyFunction ( arg1, arg2,... ) % s t u f f i n h e r e end MyFunction is the name of the function. This function must be stored in the file MyFunction.m.
Uniform Partition Riemann Sums To save typing, let s learn to use a Matlab function. In Matlab s file menu, choose create a new Matlab function which gives f u n c t i o n [ v a l u e 1, v a l u e 2,... ] = MyFunction ( arg1, arg2,... ) % s t u f f i n h e r e end [value1, value2,...] are returned values the function calculates that we want to save. MyFunction is the name of the function. This function must be stored in the file MyFunction.m.
Uniform Partition Riemann Sums To save typing, let s learn to use a Matlab function. In Matlab s file menu, choose create a new Matlab function which gives f u n c t i o n [ v a l u e 1, v a l u e 2,... ] = MyFunction ( arg1, arg2,... ) % s t u f f i n h e r e end [value1, value2,...] are returned values the function calculates that we want to save. (arg1, arg2,...) are things the function needs to do the calculations. They are called the arguments to the function. MyFunction is the name of the function. This function must be stored in the file MyFunction.m.
Uniform Partition Riemann Sums Our function returns the Riemann sum, RS, and use the arguments: our function f, the partition P and the Evaluation set E. Since only one value returned [RS] can be RS. f u n c t i o n RS = RiemannSum ( f, P, E ) % comments alway b e g i n w i t h a % matlab l i n e s h e r e end The name for the function RiemannSum must be used as the file name: i.e. we must use RiemannSum.m as the file name.
Uniform Partition Riemann Sums The Riemann sum function: 1 f u n c t i o n RS = RiemannSum ( f, P, E ) % f i n d Riemann sum dx = d i f f (P) ; RS = sum ( f ( E). dx ) ; [ s i z e P,m] = s i z e (P) ; %g e t s i z e o f P a r t i t i o n 6 c l f ; % c l e a r t h e o l d graph h o l d on % s e t h o l d to on f o r i = 1 : s i z e (P) 1 % graph r e c t a n g l e s % p l o t r e c t a n g l e code... end 11 % p l o t f u n c t i o n code... y = l i n s p a c e (P( 1 ),P( s i z e P ), 101) ; h o l d o f f ; end
Uniform Partition Riemann Sums Now to see graphically how the Riemann sums converge to a finite number, let s write a new function: Riemann sums using uniform partitions and midpoint evaluation sets. 1 f u n c t i o n RS = RiemannUniformSum ( f, a, b, n ) % s e t up a u n i f o r m p a r t i t i o n w i t h n+1 p o i n t s d e l t a x = ( b a ) /n ; P = [ a : d e l t a x : b ] ; % makes a row v e c t o r f o r i =1:n 6 s t a r t = a+( i 1) d e l t a x ; s t o p = a+i d e l t a x ; E ( i ) = 0. 5 ( s t a r t+s t o p ) ; end % send i n t r a n s p o s e o f P and E so we use column v e c t o r s 11 % b e c a u s e o r i g i n a l RiemannSum f u n c t i o n u s e s columns RS = RiemannSum ( f, P, E ) ; end
Uniform Partition Riemann Sums We can then generate a sequence of Riemann sums for different values of n. We generate a sequence of figures which converge to a fixed value. >> f = @( x ) s i n ( 3 x ) ; >> RS = RiemannSumTwo ( f, 1,4, 10) ; >> RS= RiemannSumTwo ( f, 1,4, 20) ; >> RS = RiemannSumTwo ( f, 1,4, 30) ; >> RS= RiemannSumTwo ( f, 1,4, 40) ;
Uniform Partition Riemann Sums Figure: The Riemann sum with a uniform partition P 10 of [ 1, 4] for n = 10. The function is sin(3x) and the Riemann sum is 0.6726.
Uniform Partition Riemann Sums Figure: Riemann sum with a uniform partition P 20 of [ 1, 4] for n = 20. The function is sin(3x) and the Riemann sum is 0.6258.
Uniform Partition Riemann Sums Figure: Riemann sum with a uniform partition P 40 of [ 1, 4] for n = 40. The function is sin(3x) and the Riemann sum is 0.6149.
Uniform Partition Riemann Sums Figure: Riemann sum with a uniform partition P 80 of [ 1, 4] for n = 80. The function is sin(3x) and the Riemann sum is 0.6122.
Uniform Partition Riemann Sums Homework 27 For the given function f, interval [a, b] and choice of n, you ll calculate the corresponding uniform partition Riemann sum using the functions RiemannSum in file RiemannSum.m and RiemannUniformSum in file RiemannUniformSum.m. You can download these functions as files from the class web site. Save them in your personal class directory. Create a new word document in single space with matlab fragments in bold font. The document starts with your name, MTHSC 111, Section, HW number and the date.
Uniform Partition Riemann Sums Homework 27 Continued Create a new word document for this homework. Do the document in single space. Do matlab fragments in bold font. The document starts with your name, MTHSC 111, Section Number, Date and Homework number. For each value of n, do a save as and save the figure with a filename like HW#Problem#a[ ].png where [ ] is where you put the number of the graph. Something like HW17a.png, HW#Problem#b.png etc. Insert this picture into the doc resizing as needed to make it look good. Explain in the doc what the picture shows.
Uniform Partition Riemann Sums Homework 27 Continued Something like this: Jim Peterson MTHSC 111, Section Number today s date and HW Number, Problem 1: Let f (t) = sin(5t) on the interval [1, 3] with P = {1, 1.5, 2.0, 2.5, 3.0} and E = {1.2, 1.8, 2.3, 2.8}. % add e x p l a n a t i o n h e r e >> f = @( x ) s i n ( 5 x ) ; % add e x p l a n a t i o n h e r e >> RS = RiemannUniformSum ( f, 1,4,10) % add e x p l a n a t i o n h e r e >> RS = RiemannUniformSum ( f, 1,4,20) % add e x p l a n a t i o n h e r e >> RS = RiemannUniformSum ( f, 1,4,40) % add e x p l a n a t i o n h e r e >> RS = RiemannUniformSum ( f, 1,4,80)
Uniform Partition Riemann Sums Homework 26 Continued 26.1 Let f (t) = t 2 2t + 3 on the interval [ 2, 3] with n = 8, 16, 32 and 48. 26.2 Let f (t) = sin(2t) on the interval [ 1, 5] with n = 10, 40, 60 and 80. 26.3 Let f (t) = t 2 + 8t + 5 on the interval [ 2, 3] with n = 4, 12, 30 and 50.