ò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




Reply With Quote