Post Reply 
Simpson revival
09-29-2016, 06:23 PM (This post was last modified: 09-29-2016 09:42 PM by Dieter.)
Post: #8
RE: Simpson revival
(09-29-2016 04:44 PM)Namir Wrote:  So my version 1 of my Basic code is the way to go since it does not update the older area value in W.

IMHO the way to go is the approach in my HP41 program:

You calculate the Simpson approximation for n=2, 4, 8, ... intervals. After each step the improved value is calculated from the last two approximations. This value is returned to the user. If last two improved (!) approximations agree within the stated tolerance, the iteration exits.

In the given example two "improved" steps yield a similar accuracy as three "standard" Simpson steps, so the final result is obtained faster. If only one single iteration is saved, the total execution time is reduced by 50%.

(09-29-2016 04:44 PM)Namir Wrote:  To be honest, I am a bit disappointed by your algorithm, since the general expectation for improving a calculated value in an iteration should be used in the next iteration and cause enhancing the result and/or reduce the number of iteration.

Just try it the way described above. ;-)

EDIT: Here is a short VBA program that implements the suggested method.

Code:
Function Simpson(a, b, Optional errlimit = 0.000001, Optional nmax = 2000)
   
   fab = f(a) + f(b)
   s2 = 0
   s4 = f((a + b) / 2)
   simp_new = (fab + 4 * s4) * (b - a) / 6
   improved_new = simp_new
   n = 4
Do
   h = (b - a) / n
   s2 = s2 + s4
   s4 = 0
   
   For i = 1 To n - 1 Step 2
      s4 = s4 + f(a + i * h)
   Next
   
   simp_old = simp_new
   simp_new = (fab + 2 * s2 + 4 * s4) * h / 3
   improved_old = improved_new
   improved_new = (16 * simp_new - simp_old) / 15
   n = 2 * n
Loop Until (Abs(improved_new - improved_old) <= errlimit) Or (n > nmax)

Simpson = improved_new

End Function

Function f(x)
   f = 1 / x
End Function

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Simpson revival - Pekis - 09-28-2016, 08:04 AM
RE: Simpson revival - Namir - 09-28-2016, 10:40 AM
RE: Simpson revival - Dieter - 09-28-2016, 12:25 PM
RE: Simpson revival - Namir - 09-28-2016, 02:00 PM
RE: Simpson revival - Namir - 09-28-2016, 03:50 PM
RE: Simpson revival - Dieter - 09-28-2016, 10:00 PM
RE: Simpson revival - Albert Chan - 07-31-2018, 02:57 PM
RE: Simpson revival - Namir - 09-29-2016, 04:44 PM
RE: Simpson revival - Dieter - 09-29-2016 06:23 PM
RE: Simpson revival - Namir - 09-29-2016, 10:27 PM
RE: Simpson revival - Dieter - 09-30-2016, 06:00 AM
RE: Simpson revival - Dieter - 10-02-2016, 03:29 PM
RE: Simpson revival - Namir - 10-02-2016, 04:48 PM
RE: Simpson revival - Namir - 10-09-2016, 03:14 AM
RE: Simpson revival - Albert Chan - 08-04-2018, 05:29 PM



User(s) browsing this thread: 1 Guest(s)