Re: Question about Numerical Integration Message #6 Posted by Namir on 11 Nov 2011, 3:15 a.m., in response to message #5 by peacecalc
That's the kind of tricks I was looking for.
Putting it in pseudocode form in the case of integrating from A to infinity:
Given f(x), A, SmallValue, RelTolerance, and DiffTolerance
InfVal=10^6
IntegralVal1 = Integral of f(x) from A to InfVal
Do
InfVal = 10 * InfVal
IntegralVal2 = Integral of f(x) from A to InfVal
if IntegralVa2 < SmallValue then
RelativeErr = 0
DiffErr = IntegralVa2  IntegralVal1
else
RelativeErr = (IntegralVal2  IntegralVal1) / IntegralVal1
DiffErr = 0
end
IntegralVal1 = IntegralVal2
Until RelativeErr < RelTolerance OR DiffErr < DiffTolerance
Integral = IntegralVal1
Here is a perhaps more efficient version that uses integration by parts:
Given f(x), A, SmallValue, RelTolerance, and DiffTolerance
B = 10^6 // or any other different high value (10^3, 10^4, 10^5, 10^6, 10^7, etc
IntegralVal0 = Integral of f(x) from A to B // should calculate most of the final answer
InfVal= 10 * B
IntegralVal1 = Integral of f(x) from B to InfVal
Do
InfVal = 10 * InfVal
IntegralVal2 = Integral of f(x) from A to InfVal
if IntegralVa2 < SmallValue then
RelativeErr = 0
DiffErr = IntegralVa2  IntegralVal1
else
RelativeErr = (IntegralVal2  IntegralVal1) / IntegralVal1
DiffErr = 0
end
IntegralVal1 = IntegralVal2
Until RelativeErr < RelTolerance OR DiffErr < DiffTolerance
Integral = IntegralVal0 + IntegralVal1
Edited: 11 Nov 2011, 5:47 a.m.
