The most compact algorithm for Simpson's rule??
12-12-2015, 04:24 PM (This post was last modified: 12-12-2015 10:58 PM by Namir.)
Post: #1
 Namir Senior Member Posts: 745 Joined: Dec 2013
The most compact algorithm for Simpson's rule??
Here is a (corrected, based on feedback from site members) pseudo code for what I hope to be the most compact way to implement Simpson's rule:

Code:
 Given function f(x), integration interval [A, B] and N divisions, where N is even. To calculate the integral of f(x) for X=A to x=B using Simpson's Rule h=(B-A)/N Sum=f(A)-f(B) CHS=1 A=A+h Do   Sum = Sum + (3+CHS)*f(A)   CHS=-CHS   A=A+h   N=N-1 Loop Until N=0 Area=h/3*Sum

Many implementations use two summations--one for odd terms and one for even terms. In addition these implementations use two loops with slightly different ranges. The above pseudo-coode implements a simple version that uses one loop and a few simple computational tricks.

Namir
 « Next Oldest | Next Newest »

 Messages In This Thread The most compact algorithm for Simpson's rule?? - Namir - 12-12-2015 04:24 PM RE: The most compact algorithm for Simpson's rule?? - Thomas Klemm - 12-12-2015, 05:44 PM RE: The most compact algorithm for Simpson's rule?? - Namir - 12-12-2015, 08:29 PM RE: The most compact algorithm for Simpson's rule?? - Dieter - 12-12-2015, 09:16 PM RE: The most compact algorithm for Simpson's rule?? - Dieter - 12-12-2015, 09:44 PM RE: The most compact algorithm for Simpson's rule?? - Namir - 12-12-2015, 08:28 PM RE: The most compact algorithm for Simpson's rule?? - Dieter - 12-12-2015, 09:05 PM RE: The most compact algorithm for Simpson's rule?? - Namir - 12-12-2015, 10:54 PM RE: The most compact algorithm for Simpson's rule?? - Namir - 12-12-2015, 11:02 PM RE: The most compact algorithm for Simpson's rule?? - Dieter - 12-14-2015, 09:04 PM RE: The most compact algorithm for Simpson's rule?? - Namir - 12-15-2015, 12:09 AM RE: The most compact algorithm for Simpson's rule?? - Dieter - 12-15-2015, 07:12 AM RE: The most compact algorithm for Simpson's rule?? - Namir - 12-13-2015, 01:52 AM RE: The most compact algorithm for Simpson's rule?? - Dieter - 12-13-2015, 01:27 PM RE: The most compact algorithm for Simpson's rule?? - Namir - 12-16-2015, 12:57 AM RE: The most compact algorithm for Simpson's rule?? - Dieter - 12-16-2015, 01:25 PM RE: The most compact algorithm for Simpson's rule?? - Namir - 12-16-2015, 01:54 PM

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