Interval Arithmetic - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP Prime Software Library (/forum-15.html) +--- Thread: Interval Arithmetic (/thread-19340.html) Interval Arithmetic - Eddie W. Shore - 12-24-2022 07:43 PM The arithmetic functions for intervals are defined as: [a, b] + [c, d] = [a + c, b + d] [a, b] - [c, d] = [a - d, b - c] [a, b] × [c, d] = [min(a × c, a × d, b × c, b × d), max(a × c, a × d, b × c, b × d)] [a, b] ÷ [c, d] = [min(a/c, a/d, b/c, b/d), max(a/c, a/d, b/c, b/d)] INTERVALHELP: help screen for interval arithmetic functions INTERVALADD: adding two intervals INTERVALSUB: subtracting two intervals INTERVALMUL: multiply two intervals INTERVALDIV: divide two intervals In the Home mode, use the curly brackets (used for lists { }), to type the intervals. For example, the interval [ 81.8, 82.2 ] would be typed {81.8,82.2}. Code: ```EXPORT INTERVALHELP() BEGIN // 2022-12-22 EWS PRINT(); PRINT("Interval Arithmetic"); PRINT("Use curly brackets {}"); PRINT(""); PRINT("INTERVALADD({a,b},{c,d})"); PRINT("add intervals"); PRINT(""); PRINT("INTERVALSUB({a,b},{c,d}"); PRINT("subtract intervals"); PRINT(""); PRINT("INTERVALMUL({a,b},{c,d})"); PRINT("multiply intervals"); PRINT(""); PRINT("INTERVALDIV({a,b},{c,d})"); PRINT("divide intervals"); END;``` Code: ```EXPORT INTERVALADD(v1,v2) BEGIN RETURN v1+v2; END;``` Code: ```EXPORT INTERVALSUB(v1,v2) BEGIN RETURN v1-REVERSE(v2); END;``` Code: ```EXPORT INTERVALMUL(v1,v2) BEGIN LOCAL v3; v3:=CONCAT(v1*v2,v1*REVERSE(v2)); RETURN {MIN(v3),MAX(v3)}; END;``` Code: ```EXPORT INTERVALDIV(v1,v2) BEGIN INTERVALMUL(v1,1/REVERSE(v2)); END;``` Example Interval 1 = {13, 29} Interval 2 = {10, 14} Add: {23, 43} Subtract: {-1, 19} Multiply: {130, 406} Divide: {0.928571428572, 2.9} Source Moore, Ramon E. Mathematical Elements of Scientific Computing Holt, Rinehart, and Winston, Inc: New York. 1975. ISBN 0-03-088125-0 Download a zip file here: https://drive.google.com/file/d/1L8mmnm3xx58PVjavDROCiZAafBOCsH9o/view?usp=share_link