Simpson's Rule or General Integration

Mark O'Brien

MrExcel MVP
Joined
Feb 15, 2002
Messages
3,530
I have to integrate some data and I'm going to use Simpson's Rule.

Now, my question is this:

Will I better served to write a VBA function for this or is it fairly straightforward and painless to use builtin functions for this?

If someone, like Jay Petrulis has some VBA I can borrow, I would very much appreciate this.

If someone, like Mr W, Mr A or any spreadsheet gurus have a suggestion for a non-VBA solution, I'd muchly appreciate this. (hopefully there shall be no posts with INDIRECT in them) :biggrin:

Thanks guys.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Mark,
This is an old basic set for a to b integration using simpson's rule. You may be able to convert it? JSW

'SIMPSON'S RULE FOR INTEGRAL OF F(X) OVER interval [A,B]
'ENTER THE FUNCTION F(X) IN THE NEXT LINE
110 DEF FN F(X) = SQR(1 - X ^ 2)
120:
130 INPUT "FROM X= "; A
140 INPUT " TO X= "; B
150 INPUT "NUMBER OF SUBINTERVALS (EVEN) "; N
160:
170 H = (B - A) / N
200:
210 Sum = FNF(A): C = 2
220 For K = 1 To N - 1
230 C = 6 - C: Rem GENERATES COEFFICIENTS 4,2,4,2,...
240 XK = A + K * H
250 Sum = Sum + C * FNF(XK)
260 Next K
270 Sum = Sum + FNF(B)
280:
290 INTEGRAL = (H / 3) * Sum
300:
310 Print "NUMERICAL INTEGRATION 0F F(X) OVER [A,B] = "; INTEGRAL
400 End
 
Upvote 0
On 2002-05-24 08:37, Mark O'Brien wrote:
I have to integrate some data and I'm going to use Simpson's Rule.

Now, my question is this:

Will I better served to write a VBA function for this or is it fairly straightforward and painless to use builtin functions for this?

If someone, like Jay Petrulis has some VBA I can borrow, I would very much appreciate this.

If someone, like Mr W, Mr A or any spreadsheet gurus have a suggestion for a non-VBA solution, I'd muchly appreciate this. (hopefully there shall be no posts with INDIRECT in them) :biggrin:

Thanks guys.

Hi Mark,

I posted code that will allow you to write an equation on a worksheet like

x^(x^2+2^x-cos(x^3))

or whatever and it will integrate between endpoints of your choice.

http://www.mrexcel.com/board/viewtopic.php?topic=6575&forum=2

I can send you a working file as well. E-mail me at john.petrulis@notes.ntrs.com. Nico Sterk took the code and put it up on his webpage http://members.lycos.nl/excelsoftware/

If you want Cublic spline or Romberg integration routines, search google.com with Dave Braden as the author. Also, if you want Gaussian Quadrature, search google for a post by me with subject "Integration and Differentiation" and look for Alexander Chachin's responses. He has done double integration with symbolic inputs, although I haven't fully translated his code yet.

Eero Tibar and Harlan Grove posted worksheet solutions to Trapezoidal integration if you only have the data points and not an equation (Dave's cubic splines works the same way, I think). I will try to find the links and repost.

BTW, I have a better differentiation algorithm, so I might throw it in soon.

Note that my routines don't handle singularities or unbounded endpoints.

Bye,
Jay
This message was edited by Jay Petrulis on 2002-05-24 08:57
 
Upvote 0
Thanks guys.

Yeah, I've only got data points, so I may have a look for Harlan's stuff. I may get some inspiration for Simpson's rule from there.
 
Upvote 0

Forum statistics

Threads
1,214,919
Messages
6,122,259
Members
449,075
Latest member
staticfluids

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top