Question about Numerical Integration Namir Posting Freak Posts: 2,247 Threads: 200 Joined: Jun 2005 11-10-2011, 05:53 PM The Integrate function in several HP calculators calculates the integral between two values, say A and B. Are there any tricks to use the same method when integrating between A and infinity, minus infinity and A, and minus infinity and plus infinity? I know there are special types of Gaussian quadrature methods that can handle the above cases. My question is directed at working with the algorithms for finite integrals. Namir Valentin Albillo Posting Freak Posts: 1,755 Threads: 112 Joined: Jan 2005 11-10-2011, 06:10 PM Quote: The Integrate function in several HP calculators calculates the integral between two values, say A and B. Are there any tricks to use the same method when integrating between A and infinity, minus infinity and A, and minus infinity and plus infinity? I know there are special types of Gaussian quadrature methods that can handle the above cases. My question is directed at working with the algorithms for finite integrals. Namir The usual trick is to first perform a simple change of variable which will reduce any interval, including infinities at one or both extremes, to any finite interval you care for such as [0,1] or [-1,1]. Best regards from V. Lyuka Member Posts: 169 Threads: 12 Joined: Aug 2007 11-10-2011, 06:41 PM Many RF engineers would like the conversion below, s = (z - 1) / (z + 1) that is used to plot various impedance in a Smith chart. Lyuka Namir Posting Freak Posts: 2,247 Threads: 200 Joined: Jun 2005 11-10-2011, 11:31 PM looks like: s = (x^2 - 1) / (x^2 + 1) is a better transformation, since it is valid for all real values of x. Namir peacecalc Member Posts: 97 Threads: 9 Joined: Nov 2011 11-10-2011, 11:58 PM Hallo namir, when you need only numerical results, you can also use instead of infinities great/small numbers like +/- 10^6. That's sometimes tricky, shown in the advanced handbook for the 15c. sincerely peacecalc Edited: 10 Nov 2011, 11:59 p.m. Namir Posting Freak Posts: 2,247 Threads: 200 Joined: Jun 2005 11-11-2011, 03:15 AM That's the kind of tricks I was looking for. Putting it in pseudo-code 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. Mike (Stgt) Posting Freak Posts: 858 Threads: 80 Joined: Feb 2009 11-11-2011, 07:04 AM IIRC, there is a discussion worth to read in the PPC-ROM manual. Hope this hepls Ciao.....Mike Gjermund Skailand Junior Member Posts: 15 Threads: 2 Joined: Oct 2008 11-11-2011, 07:11 AM Tanh-Sinh transformation or "Double exponential method" may also be efficient, especially when the function is oscillating. There is a fast implementation in C (hpgcc2) for HP50G in my package INT1D at www.hpcalc.org. Dieter Senior Member Posts: 653 Threads: 26 Joined: Aug 2010 11-11-2011, 07:53 AM As already pointed out, there are basically two approaches for handling improper integrals: Use a large (finite) value where the integrand becomes negligible compared to the final result. Example: for an 8-digit result of the left tail Normal CDF a lower limit of -6 usually is sufficient as the PDF here is mererly 6E-9 and the whole integral from -infinity to -6 is less than 1E-9. Apply a variable transformation to make infinity "less infinite". ;-) This is the preferred method suggested in most of the other posts in this thread. Example: Take a look at the 15C Advanced Functions Handbook, p. 54 ff. There, this topic is discussed with several examples on how to use the 15C's Integrate function for improper integrals. On p. 60-64 you will find a very nice and illustrative application of these ideas, evaluating the Normal CDF as well as the error function, with both plus or minus infinity as the limits, giving exact results even far out in the tails. This is accomplished by using the transformation u = exp(t²) as soon as the integration limit exceeds a certain value (here: 1,6). Dieter « Next Oldest | Next Newest »

 Possibly Related Threads... Thread Author Replies Views Last Post Integration question and "RPN" mode comment Craig Thomas 16 4,620 12-05-2013, 02:32 AM Last Post: Nick_S HP Prime numerical restrictions? Alasdair McAndrew 4 1,410 11-16-2013, 05:32 PM Last Post: Alasdair McAndrew HP Prime numerical precision in CAS and HOME Javier Goizueta 5 1,744 11-16-2013, 03:51 AM Last Post: Paul Dale WP34s integration trapped in infinite loop Bernd Grubert 25 5,098 10-17-2013, 08:50 AM Last Post: Dieter HP Prime integration Richard Berler 1 976 10-06-2013, 10:52 PM Last Post: Helge Gabert [HP-Prime] AMBIGUITY between Numerical Calculation (HOME) and Numerical/Symbolic Calculation (CAS mode) CompSystems 2 1,140 08-18-2013, 07:06 PM Last Post: CompSystems OT: My brain is failing me again. Help with numerical / mechanical problem required. Harald 4 1,437 07-01-2013, 10:31 AM Last Post: Harald integration on 39gII emulator Wes Loewer 29 5,338 06-07-2013, 05:58 PM Last Post: Chris Smith WP-34S Integration Richard Berler 15 2,945 03-08-2013, 02:29 AM Last Post: Walter B HP 34S integration Richard Berler 16 3,078 02-18-2013, 04:42 PM Last Post: Marcus von Cube, Germany

Forum Jump: