Post Reply 
The most compact algorithm for Simpson's rule??
12-14-2015, 09:04 PM
Post: #12
RE: The most compact algorithm for Simpson's rule??
(12-12-2015 11:02 PM)Namir Wrote:  This is a slightly different version based on one of Dieter's remarks.

Code:
h=(B-A)/N
Sum=f(A)-f(B)
k=4
A=A+h
Do
  Sum = Sum + k*f(A)
  k=6-k
  A=A+h
  N=N-1
Loop Until N=0
Area=h/3*Sum

I still don't get why you want to compute f(b) twice and generate an additional function call that is not required. Why don't you do it the classic way?

Code:
h = (b - a) / n
sum = f(a) + f(b)
k = 4
Do
  a = a + h
  sum = sum + k * f(a)
  k = 6 - k
  n = n - 1
Loop Until n = 1
result = sum * h / 3

If you want to count down to n=0 simply add another n=n-1 on top of the do loop.

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


Messages In This Thread
RE: The most compact algorithm for Simpson's rule?? - Dieter - 12-14-2015 09:04 PM



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