+ Reply to Thread
Results 1 to 2 of 2

Integration of a function over some interval

Hybrid View

  1. #1
    Registered User
    Join Date
    10-13-2008
    Location
    CPH
    Posts
    1

    Integration of a function over some interval

    Is there a function in excel which makes it possible to get the value of a function integrated over a defined interval?

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689
    There are various functions that are integrated for particular purposes (like the probability mass function to get thec cumulative distribution), but unless you need a particular one, you're on your own.

    Here's a simple Simpson integrator:
    Function SimpsonInt(a As Double, b As Double, ByVal n As Long) As Double
        ' Returns the integral of Func (below) from a to b _
          using Composite Simpson's Rule over n intervals
    
        Dim i       As Double  ' index
        Dim dH      As Double  ' step size
        Dim dOdd    As Double  ' sum of Func(i), i = 1, 3, 5, 7, ... n-1, i.e., n/2 values
        Dim dEvn    As Double  ' sum of Func(i), i =   2, 4, 6,  ... n-2  i.e., n/2 - 1 values
        ' 1 + (n/2) + (n/2 - 1) + 1 = n+1 function evaluations
    
        If n < 1 Then Exit Function
        If n And 1 Then n = n + 1 ' n must be even
        dH = (b - a) / n
    
        For i = 1 To n - 1 Step 2
            dOdd = dOdd + Func(a + i * dH)
        Next
    
        For i = 2 To n - 2 Step 2
            dEvn = dEvn + Func(a + i * dH)
        Next
    
        SimpsonInt = (Func(a) + 4# * dOdd + 2# * dEvn + Func(b)) * dH / 3#    ' weighted sum
    End Function
    
    Function Func(x As Double) As Double
        ' replace this function with the function to be integrated
        Func = Sin(x)
    End Function
    Entia non sunt multiplicanda sine necessitate

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How does this code output the coefficients of a trendline?
    By gshock in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-13-2010, 05:54 PM
  2. Excel 2007 error when adding custom help file to user defined function
    By sabotuer99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-04-2009, 01:10 AM
  3. Modify a Function to add an extra condition
    By King_Quake in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-03-2008, 04:32 PM
  4. Link together different cells in specific order?
    By Sandman4432 in forum Excel Formulas & Functions
    Replies: 19
    Last Post: 01-03-2008, 05:01 AM
  5. Analysis Toolpak Function XIRR and VBA - XL 2007
    By rvExcelNewTip in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-02-2007, 04:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1