HP-71B Enhanced Math LEX
|
01-27-2020, 11:35 AM
(This post was last modified: 01-27-2020 12:38 PM by Albert Chan.)
Post: #16
|
|||
|
|||
RE: HP-71B Enhanced Math LEX
(01-27-2020 08:05 AM)J-F Garnier Wrote: I understand that the alternate formula (x+y)*(x-y) saves a multiplication, but does it guarantee that the result will be *always* better? Yes, I believe (x*x-y*y) is better calculated as (x+y)*(x-y) |x| + |y| always accurate to whatever the system precision (unless it overflows) |x| − |y| is exact if ratio of |x| and |y| = 1/2 to 2. (unless it underflows) (see Kahans Miscalculating Area and Angles of a Needle-like Triangle, Section 4, Why Cancellation Cannot Hurt) Below code searched bad REPT(Z*Z), for X = 0.1 to 1/3, 1 ≤ Y/X < 2 Code: 10 COMPLEX Z,Z1,Z2 >RANDOMIZE 1 >RUN Z= (.235285090644,.236095767159) Z*Z= (-3.82137391042E-4,.111099627953) Z^2= (-3.82137391039E-4,.111099627953) OK = (-3.82137391041E-4,.111099627953) >RUN Z= (.180255457178,.190657390504) Z*Z= (-3.85821071135E-3,6.87340701793E-2) Z^2= (-3.85821071134E-3,6.87340701793E-2) OK = (-3.85821071134E-3,6.87340701793E-2) >RUN Z= (.1084548287,.127000096548) Z*Z= (-4.36657465486E-3,.027547547432) Z^2= (-4.36657465485E-3,.027547547432) OK = (-4.36657465485E-3,.027547547432) Error (both Z*Z and Z^2) increases if |X| ≈ |Y|. After more runs, we have: >SCI 12 >RUN Z= (1.27043248466E-1 ,1.27045908048E-1) Z*Z= (-6.75770947000E-7, 3.22806497255E-2) Z^2= (-6.75770946606E-7, 3.22806497255E-2) OK = (-6.75770947060E-7, 3.22806497255E-2) |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)