Post Reply 
New Quadratic Integration
05-30-2018, 08:17 PM (This post was last modified: 05-31-2018 03:40 AM by Namir.)
Post: #3
RE: New Quadratic Integration
Thanks Dieter I made the changes that you suggested.

My own (very limited) testing shows that the new algorithm generally yields more accurate results than Simpson's Rule. Of course this advantage comes at a computational price (I used old compact Simpson code that we had discussed a few years back on this forum). So increased accuracy comes at the cost of more CPU work. Fare enough!

Here is the updated VBA code:

Quote:Function f(ByVal X As Double) As Double
f = Exp(X) - 3 * X ^ 2
End Function

Function Area(ByVal A As Double, ByVal B As Double, ByVal N As Integer)
Dim Sum As Double
Dim Blast As Double, Fa As Double, Fb As Double, Fc As Double, Fm As Double
Dim Ca As Double, Cb As Double, Cm As Double
Dim K1 As Double, K2 As Double, K3 As Double
Dim Incr As Double, m As Double, C As Double
Dim I As Integer

Blast = B
Incr = (B - A) / N
Sum = 0
For I = 1 To N
B = A + Incr
C = (A + B) / 2
Fa = f(A)
Fb = f(B)
Fc = f(C)
Fm = (Fa + Fb) / 2

m = A * ((Fm - Fc) * (Fm - Fb)) / ((Fa - Fc) * (Fa - Fb)) + _
C * ((Fm - Fa) * (Fm - Fb)) / ((Fc - Fa) * (Fc - Fb)) + _
B * ((Fm - Fa) * (Fm - Fc)) / ((Fb - Fa) * (Fb - Fc))

Fm = f(m)

Ca = Fa / (A - m) / (A - B)
Cm = Fm / (m - A) / (m - B)
Cb = Fb / (B - A) / (B - m)

K1 = (Ca + Cm + Cb)
K2 = (Ca * (m + B) + Cm * (A + B) + Cb * (m + A))
K3 = (Ca * m * B + Cm * A * B + Cb * m * A)

Sum = Sum + Incr * (K1 / 3 * (B ^ 2 + A * B + A ^ 2) - K2 / 2 * (B + A) + K3)

A = B
Next I
Area = Sum

Namir
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
New Quadratic Integration - Namir - 05-30-2018, 01:39 PM
RE: New Quadratic Integration - Dieter - 05-30-2018, 05:53 PM
RE: New Quadratic Integration - Namir - 05-30-2018 08:17 PM
RE: New Quadratic Integration - Dieter - 05-30-2018, 09:24 PM
RE: New Quadratic Integration - ttw - 05-31-2018, 02:27 AM
RE: New Quadratic Integration - Namir - 05-31-2018, 03:46 AM
RE: New Quadratic Integration - Namir - 05-31-2018, 03:51 AM
RE: New Quadratic Integration - ttw - 05-31-2018, 03:56 AM



User(s) browsing this thread: 1 Guest(s)