|
-
Jan 25th, 2002, 11:03 AM
#1
Thread Starter
Hyperactive Member
ò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:
Private Sub Form_Load()
Dim Pi As Double
Pi = 4 * Atn(1)
'MsgBox Simpson(Pi / 2, 0, 100) ---> Error
MsgBox Simpson(Pi/4, 0, 100) '--> works
End Sub
'------ > Function Definition
Private Function F(x As Double) As Double
F = 1 / Sqr(1 - (Sin(x) ^ 2))
End Function
Private Function Simpson(U As Double, L As Double, N As Double) As Double
'U Upper Limit
'L Lower Limit
'N Number of Intervals
'H Interval
H = (U - L) / N
Total = F(L)
For i = 1 To (N / 2) - 1
Total = Total + 4 * F(L + ((2 * i) - 1) * H) + 2 * F(L + (2 * i * H))
Next
Total = Total + F(U)
Simpson = (H / 3) * Total
End Function
Last edited by thinktank2; Jan 26th, 2002 at 01:44 AM.
-
Jan 25th, 2002, 11:38 AM
#2
Thread Starter
Hyperactive Member
Note: N should be a multiple of 2 for the Simpson function to work
-
Jan 25th, 2002, 12:14 PM
#3
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|