The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 795 - File: showthread.php PHP 7.4.33 (FreeBSD)
File Line Function
/showthread.php 795 errorHandler->error





Post Reply 
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
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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
The most compact algorithm for Simpson's rule?? - Namir - 12-12-2015 04:24 PM



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