Improved Simpson's rule - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP-41C Software Library (/forum-11.html) +--- Thread: Improved Simpson's rule (/thread-5349.html) |
Improved Simpson's rule - Dieter - 12-16-2015 07:12 PM Recently there were some discussions regarding a compact implementation of Simpson's rule. I would like to add an improved version that calculates a new, usually more exact approximation from two Simpson approximations with n and 2n intervals. This way the user also gets an estimate for the approximation error. The following code has not seen much testing. In fact I wrote it this morning during breakfast. ;-) So take care and please report all errors you find. Code: 01 LBL"SIMP" Insert your function at LBL 99 and start "SIMP". The program returns a sequence of approximations, with the latest one in X and the previous in Y. So pressing [x<>y] switches between the current and previous approximation. Example: Integrate f(x) = 1/x from a=1 to b=2. Code: [PRGM] In a way this method is similar to the Romberg scheme in that it calculates an improved approximation from a quite good estimate of the error associated with Simpson's rule. On the other hand no matrix has to be stored and the program requires only ten data registers (R00...R09): Code: Used registers: As usual, all comments and corrections are welcome. Dieter Edit: more than two years after posting this I realized that the example does not integrate ln(x) but 1/x. #-) RE: Improved Simpson's rule - rprosperi - 12-17-2015 12:52 AM (12-16-2015 07:12 PM)Dieter Wrote: ... Wow, meals in my house and yours are quite different. I was just about to go eat dinner, but now I will feel I'm certainly being lazy, limiting my effort to dining. And maybe reading the daily mail... |