Results 1 to 3 of 3

Thread: numerical integration

  1. #1

    Thread Starter
    Hyperactive Member thinktank2's Avatar
    Join Date
    Nov 2001
    Location
    Arctic
    Posts
    272
    òdq / Ö(1- k.Sin(q)2)

    For k = 1,

    This function doesn't seem to converge between the limits specified. But it does for 0 to Pi/4. There will be a divide by zero error for 0 to Pi/2. Since Sin(Pi/2) = 1, the denominator becomes 0.

    VB Code:
    1. Private Sub Form_Load()
    2. Dim Pi As Double
    3. Pi = 4 * Atn(1)
    4.  
    5. 'MsgBox Simpson(Pi / 2, 0, 100)  ---> Error
    6.  
    7.  MsgBox Simpson(Pi/4, 0, 100)  '--> works
    8.  
    9. End Sub
    10.  
    11. '------ > Function Definition
    12. Private Function F(x As Double) As Double
    13. F = 1 / Sqr(1 - (Sin(x) ^ 2))
    14. End Function
    15.  
    16. Private Function Simpson(U As Double, L As Double, N As Double) As Double
    17. 'U  Upper Limit
    18. 'L  Lower Limit
    19. 'N  Number of Intervals
    20. 'H  Interval
    21.  
    22. H = (U - L) / N
    23.  
    24. Total = F(L)
    25.  
    26. For i = 1 To (N / 2) - 1
    27.     Total = Total + 4 * F(L + ((2 * i) - 1) * H) + 2 * F(L + (2 * i * H))
    28. Next
    29.  
    30. Total = Total + F(U)
    31.  
    32. Simpson = (H / 3) * Total
    33.  
    34. End Function
    Last edited by thinktank2; Jan 26th, 2002 at 01:44 AM.

  2. #2

    Thread Starter
    Hyperactive Member thinktank2's Avatar
    Join Date
    Nov 2001
    Location
    Arctic
    Posts
    272
    Note: N should be a multiple of 2 for the Simpson function to work

  3. #3
    New Member
    Join Date
    Jan 2002
    Location
    Ireland
    Posts
    10

    Smile

    Thanks. I'll let you know how I get on with it, but that's a great start. Cheers

Posting Permissions

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



Click Here to Expand Forum to Full Width