L015 Trapezoidal Rule and Simpson's Rule
L015 Trapezoidal Rule and Simpson's Rule
can be expressed as
Where h =
f ( x)dx
n 1 h f ( a ) + f ( b ) + 2 f (a + kh) 2 k =1
ba and n is the number of intervals into which we have partitioned [a, b]. n To prepare for the trapezoidal rule create a directory called TRAP and get into it. In the
equation writer create the expression
F ( A + kH )
k =1
N 1
Now put 5 zeros on the stack and save them in variables called F, B, A, N, and H. Your soft key menus should now be F1-H, F2-N, F3-A, F4-B, F5-F, and F6-SM. Finally, to make sure everything works the way we want it to, we must make sure the calculator is set to approximation mode and that system flag 3 is checked (Function num). We will test our trapezoidal rule with the integral exercise we will set our numeric display to FIX 2. Define the function F(X) = 3X2, save the value 4 in B, 1 in A, and 8 in N. The following sequence will compute the approximation by the trapezoidal rule: (1) F4-B F3-A - F2-N LS F1-H F6-SM EVAL 2 F4-B F5-F + F3-A F5-F + F1-H 2
4
You should now see the answer 63.21 on the stack. We know from the fundamental theorem of calculus that
to be desired. Try it again with n = 16. This time the answer is 63.05, which is a bit better. Repeating with n = 32 gives the integral as 63.01, and with n = 64 gives it as 63.00. It is not the purpose of these lessons to teach programming, but in this case a program to do the above computations is so easy and so useful that it would be a shame not to do it. Press RS (the + sign key) then repeat the sequence (1) above and press ENTER. Now store this in a variable called TRAPR. Now store 8 in N and press TRAPR, and see 63.21 for an answer. Change N to 16 and press TRAPR to get the answer 63.05, etc. There is a very important procedure that one learns in a numerical analysis course that requires several applications of the trapezoidal rule with each application having n
twice as big as the previous one. To double the value on N, one could press N 2 LS N. A program to do this would be N 2 LS N . Enter this program and save it as DBLR. Set N = 8 again and press TRAPR to get the answer 63.21. Now press DBLR followed by TRAPR to get 63.05, etc. NOTE: An equally easy program could be written to execute the algorithm given in Lesson 11 for Newtons Method. Readers who are interested in becoming proficient as program the calculator should start with An Introduction to Programming HP Graphing Calculators.
Simpsons Rule
where h =
ba and n, the number of subintervals into which [a, b] has been partitioned, n is even. To prepare for the Simpsons rule press get into the directory immediately above TRAP then create a directory called SIMP and get into it. In the equation writer create the expression expression
N 1 2 k =0
N 1 2
save them in variables called F, B, A, N, and H. Your soft key menus should now be F1H, F2-N, F3-A, F4-B, F5-F, and F6-SM4. After pressing NXT, the first menu key will be F1-SM2. Finally, to make sure everything works the way we want it to, we must make sure the calculator is set to approximation mode and that system flag 3 is checked (Function num). We will now use Simpsons rule to approximate the same integral we used above for the trapezoidal rule again with n = 8 and the display set to FIX 2. Define the function F(X) = 3X2, save the value 4 in B, 1 in A, and 8 in N. The following sequence will compute the approximation by Simpsons rule: (2) F4-B F3-A - F2-N LS F1-H NXT F1-SM2 EVAL 2 NXT F6-SM4 EVAL 4 + F4-B F5-F + F3-A F5-F + F1-H 3
We should now see the answer 63.00 on the stack. This would lead us to conclude that Simpsons rule is significantly more accurate than the trapezoidal rule. That is a correct conclusion, but for the wrong reason. It turns out that Simpsons rule will give the exact answer for the definite integral of any polynomial of degree three or less. We will return to the relative accuracy of the two approximation methods in a later. First, the reader
may wish to make a program called SIMPR from the algorithm (2) similar to TRAPR described above. One may also wish to copy DBLR from directory TRAP to SIMP, but this is not particularly recommended. Simpsons rule is not typically used the way the trapezoidal rule is used so DBLR will not be as useful in SIMP as it is in TRAP. Now, to get more convincing evidence of the increased accuracy of Simpsons rule, we will consider the integral
x e dx
2
the definite integral function of the calculator to find the value of this integral to three decimal places. Now, in both TRAP and SIMP define the function F ( X ) = e then set B = 1 and A = 0. In each of TRAP and SIMP, try to find the smallest value of N that will give the same answer as the definite integral command gave to three decimal places. HINT: For the trapezoidal rule N will have to be in the 20s, for Simpsons rule it will be less than 10. Return to List of Lessons