Simpson's rule in Excel

J

James Silverton

Hello, All!

There have been no responses to a previous post but forgive me
if I try again. If this is not regarded as a charting question,
please let me know. Anyway, is it possible to write a statement
evaluating the area under a graph by Simpson's rule without
using VBA or helper columns?




James Silverton
Potomac, Maryland, USA
 
B

Bernard Liengme

Please look at my screen shot of a worksheet on
http://www.stfx.ca/people/bliengme/ExcelTips/AreaUnderCurve.htm

I can generate the same result with:
=(1/3)*(A6-A5)*SUMPRODUCT(--(MOD(ROW(A5:B9),2)=1),((B5:B9)+4*(B6:B10)+B7:B11))

If you look at the screen shot you will see that my x values are in A5:A11,
y-values in B5:B11
When I use a 'helper column' I need formulas in C5, C7, C9; i.e. in odd
cells hence the MOD(ROW(),2)=1 test



Hope this helps
 
D

David J. Braden

James,
From an old post of mine ---
"Area under a curve"

To use Excel for evaluating the integral of, say, 2+3*(Ln(x))^0.6 using
Simpson's Rule (also see notes below):

1) Enter some labels:
In cell.....enter
A1 "X_1"
A2 "X_n"
A3 "NbrPanels"

2) Set some values:
In cell.....enter
B1 1
B2 2.5
B3 1000

3) Define some names:
Select A1:B3, then choose Insert->Name->Create. Make sure that only the
"Left Column" box is selected. If it isn't, you might have entered text
instead of numbers in the right column, or mis-selected the range. Press
OK.

4) Choose Insert->Names->Define
Enter each of the following names and their definitions, pressing Add
with each entry (you can copy and paste these):
EPanels =NbrPanels+MOD(NbrPanels,2)
delta =(X_n-X_1)/EPanels
Steps =ROW(INDIRECT("1:"&EPanels+1))-1
EvalPts =X_1+delta*Steps
SimpWts =IF(MOD(Steps,EPanels)=0,1,IF(MOD(Steps,2)=1,4,2))*delta/3

(optional) If interested in a trapezoidal approximation, define
TrapWts =IF(MOD(Steps,EPanels)=0,0.5*delta,delta)

5) Close the Define Names box, and in, say, cell D1, array-enter
=SUM(SimpWts*(2+3*LN(EvalPts)^0.6))
That is, type in the function, and hold ctl-shift when pressing Enter.

In general, ctrl-shift-enter =SUM(SimpWts*f(EvalPts))
where f() is a legitimate Excel expression that yields a scalar numeric
value.

To use the trapezoidal method, substitute in the above expression
TrapWts for SimpWts.

Notes:
(1) With this implementation, an odd number for NbrPanels doesn't cut it
(for Simpson's rule), so there will be no improvement moving from an odd
number to the next integer (odd ones are automatically changed to the
next even, internally).

(2) If you have "jumps" in your function, break it up at the points
where those occur, and add the pieces.

.... FWIW, consider Weddle weights instead of the Simpson ones. For a
single partition, they run [1 5 1 6 1 5 1], with the whole shebang
multiplied by (3/10). Error term is much tighter, the calc is just as fast.

HTH
Dave Braden
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top