Post Reply 
HP 41C solver problem
12-07-2017, 05:46 AM (This post was last modified: 12-07-2017 05:56 AM by Thomas Okken.)
Post: #9
RE: HP 41C solver problem
OK, so the problem with the ROOT program from the HP-41C Standard Applications book is that its termination condition is not very good. It checks whether the result is zero, or whether its absolute value is less than 10^-10, and that doesn't always work well.

In the case of 0.0074 * x^3 - 100, it works badly because the first and second terms of that formula are both near 100 at the root, so the actual root loses two or three digits of precision, so the "less than 10^-10" test is useless: unless the function evaluates to exactly zero, it is guaranteed to evaluate to something greater than 10^-10.

A better test would be to check what happens to the interval being searched.

Consider:

Given guesses x1 and x2, where f(x1) < 0 and f(x2) > 0, the secant method provides a new guess x3, which is the point at which the straight line through (x1, f(x1)) and (x2, f(x2)) intersects the x axis.

If f(x3) = 0, you're done.
If f(x3) < 0, set x1 = x3, and repeat.
If f(x3) > 0, set x2 = x3, and repeat.

But what if x3 is less than or equal to x1, or greater than or equal to x2? Mathematically, that's impossible, but in finite-precision math, it is possible.

In that case, you can fall back on the bisection method: just try x3 = (x1 + x2) / 2 instead, and then do the same check on f(x3) = 0, f(x3) < 0, and f(x3) > 0, as above. In this case, x3 can never be less than x1 or greater than x2, and the only way it can be equal to x1 or x2 is if x1 and x2 are as close as they can be, to each other, given the floating-point representation in use, and so, x3 = x1 or x3 = x2 provides a robust termination condition.

I'm guessing the ROOT program doesn't use this kind of algorithm because they wanted to keep it simple.

I'd say the easiest way of making the ROOT program more useful is to insert a VIEW X just before the XEQ IND 03 on line 39. That way, you can see what it's doing, and it's easy to tell when the program gets stuck in an endless loop while actually having converged.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
HP 41C solver problem - Trond - 12-07-2017, 03:17 AM
RE: HP 41C solver problem - Thomas Okken - 12-07-2017, 03:55 AM
RE: HP 41C solver problem - Trond - 12-07-2017, 04:27 AM
RE: HP 41C solver problem - Thomas Okken - 12-07-2017, 04:23 AM
RE: HP 41C solver problem - Trond - 12-07-2017, 05:08 AM
RE: HP 41C solver problem - Trond - 12-07-2017, 04:38 AM
RE: HP 41C solver problem - AlexFekken - 12-07-2017, 04:46 AM
RE: HP 41C solver problem - Trond - 12-07-2017, 05:43 AM
RE: HP 41C solver problem - Thomas Okken - 12-07-2017 05:46 AM
RE: HP 41C solver problem - Dieter - 12-07-2017, 10:39 AM
RE: HP 41C solver problem - Thomas Okken - 12-07-2017, 01:56 PM
RE: HP 41C solver problem - Dieter - 12-07-2017, 06:10 PM
RE: HP 41C solver problem - Guenter Schink - 12-07-2017, 07:25 PM
RE: HP 41C solver problem - Trond - 12-07-2017, 03:58 PM
RE: HP 41C solver problem - rprosperi - 12-07-2017, 11:37 PM
RE: HP 41C solver problem - hth - 12-08-2017, 05:13 PM
RE: HP 41C solver problem - Dieter - 12-08-2017, 06:58 PM
RE: HP 41C solver problem - hth - 12-08-2017, 07:25 PM
RE: HP 41C solver problem - Thomas Okken - 12-08-2017, 12:03 AM
RE: HP 41C solver problem - Dieter - 12-08-2017, 07:02 AM
RE: HP 41C solver problem - Thomas Okken - 12-08-2017, 02:50 PM
RE: HP 41C solver problem - Trond - 12-08-2017, 09:20 PM
RE: HP 41C solver problem - rprosperi - 12-08-2017, 11:16 PM
RE: HP 41C solver problem - rprosperi - 12-10-2017, 04:04 PM
RE: HP 41C solver problem - hth - 12-10-2017, 06:37 PM



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