![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
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) Thanks guys. |
|
|
|
|
|
#2 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Central Florida, USA
Posts: 7,541
|
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 |
|
|
|
|
|
#3 | |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
Quote:
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/viewtop...c=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 ] |
|
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
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. |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Mar 2002
Location: Chicago, IL USA
Posts: 2,042
|
http://groups.google.com/groups?hl=e...40kprztm-w1171
http://www.stfx.ca/people/bliengme/ExcelTips http://groups.google.com/groups?hl=e...oswest.msn.net http://groups.google.com/groups?hl=e...40tkmsftngxa07 http://groups.google.com/groups?hl=e...2.news.aol.com http://groups.google.com/groups?q=gr...chester.rr.com HTH, Jay |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|