Precision of SOLVER ?

Post here to share useful tips and tricks, to ask questions about using your DM42 or to report software-related problems
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Precision of SOLVER ?

Post by Walter »

In the SOLVER's solution, the difference between the last two approximations obviously depends on the display format set. For SOLVing an INTEGral on DM42 with ALL chosen, said difference may become some 4E-12. This corresponds approximately with what's claimed in the HP-42S manuals - but note the HP-42S was a 12-digit calculator.

I just wonder how and where the 34 digits of Free42 are taken into account. How can I set the DM42 to 34-digit precision for solving?

Thanks in advance for pointing me to relevant information.

(I concur that 34 digits for such a solution are overkill but just want to know.)
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
rawi
Posts: 102
Joined: Sat Dec 28, 2019 4:50 am
Location: Bavaria, Germany

Re: Precision of SOLVER ?

Post by rawi »

You cannot set the accuracy of solving. You get the best solution independent of the display format you choose. The y register does not give an indication of the accuracy. It is just the second-best solution.
If you solve an equation with an integral the accuracy of the integral depends on the ACC factor you put in, not on the display format (as with the DM 15). Here you can put in as well numbers smaller than 1E-12. I tried it with the integral from 0 to 2 of sin(x)/x and an accuracy of 1E-20, and it worked fine with an accuracy of 1.45E-21.
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: Precision of SOLVER ?

Post by Walter »

rawi wrote:
Sat May 20, 2023 4:23 pm
You cannot set the accuracy of solving. You get the best solution independent of the display format you choose. The y register does not give an indication of the accuracy. It is just the second-best solution.
If you solve an equation with an integral the accuracy of the integral depends on the ACC factor you put in, not on the display format (as with the DM 15). Here you can put in as well numbers smaller than 1E-12. I tried it with the integral from 0 to 2 of sin(x)/x and an accuracy of 1E-20, and it worked fine with an accuracy of 1.45E-21.
Yes in principle but:
  1. Thanks for pointing to a very precise ACC. I knew how to control the precision of the integral, but wasn't aware of the opportunity to use such a small ACC.
  2. My main point, however, was the precision of SOLVE. I want to find the roots of an integral function. ACC is fixed to 1E-5. Keeping everything constant, just setting the display to
    1. SCI 1, the last two approximations of the root differ by 5E-2,
    2. SCI 3, the last two approximations of the root differ by 7E-6,
    3. SCI 6, the last two approximations of the root differ by 6E-8,
    4. SCI 9, the last two approximations of the root differ by 7E-8,
    5. SCI 10, the last two approximations of the root differ by 4E-11,
    6. SCI 11 (this is the maximum input possible), the last two approximations of the root differ by 4E-11,
    7. ALL, the last two approximations of the root differ by 4E-12.
    This looks like a trend, doesn't it? Computing time rose in parallel, BTW.
In the HP-42S manuals, I can't find nothing about the stop condition for SOLVE as long as the root isn't hit directly. DM42 manual doesn't cover such trivial mathematical stuff. Does anybody know more?
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: Precision of SOLVER ?

Post by Walter »

More observations using the same function:
  1. With SCI 2, |f(root)| ≈ 2E-3.
  2. With SCI 4, |f(root)| ≈ 8E-6.
  3. With SCI 6, |f(root)| ≈ 4E-8.
  4. With SCI 8, |f(root)| ≈ 3E-10.
  5. With SCI 10, |f(root)| ≈ 1E-11.
  6. With SCI 11, |f(root)| ≈ 3E-12.
  7. With ALL, |f(root)| ≈ 3E-12.
DM42 claims calculating with 34 digits... How can I get better here?

EDIT (23-05-21): Thanks to electronic searching, I found the following statement in HP-42S RPN Scientific Programming Examples and Techniques of July 1988, p. 108:
In most situations, the calculated root is an accurate estimate of the theoretical, infinitely precise root of the function. An ideal solution is one for which f(x) exactly equals 0. However, a nonzero value for f(x) is often also acceptable, because it results from approximating the root with limited (12-digit) precision.
Let me say I'd concur with this if it were true but it doesn't even comply to the results stated above. And for the DM42, where do the additional 22 digits come into play??
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
rawi
Posts: 102
Joined: Sat Dec 28, 2019 4:50 am
Location: Bavaria, Germany

Re: Precision of SOLVER ?

Post by rawi »

Walter wrote:
More observations using the same function:
With SCI 2, |f(root)| ≈ 2E-3.
With SCI 4, |f(root)| ≈ 8E-6.
With SCI 6, |f(root)| ≈ 4E-8.
With SCI 8, |f(root)| ≈ 3E-10.
With SCI 10, |f(root)| ≈ 1E-11.
With SCI 11, |f(root)| ≈ 3E-12.
With ALL, |f(root)| ≈ 3E-12.
Thank you for pointing out this. I did not know that. This is strange and not covered in the manual.
Would it help to multiply the equation's result with a high number, e.g. 1E5? OK, very pragmatic, but it should lead in the right direction.
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: Precision of SOLVER ?

Post by Thomas Okken »

Apart from functions that display numbers or convert them to strings, the only functions whose behavior is influenced by the display mode are RND, TRUNC, and AMORT.
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: Precision of SOLVER ?

Post by Walter »

Thomas Okken wrote:
Sun May 21, 2023 9:48 pm
Apart from functions that display numbers or convert them to strings, the only functions whose behavior is influenced by the display mode are RND, TRUNC, and AMORT.
Thanks, Thomas. Though what's the stop condition for the Solver unless it finds a root directly? I.e. if the last two approximations return results of opposite signs and the function there is 'small' but not zero? To me, it looks like this stop condition does depend on display format, however.
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
J-F Garnier
Posts: 47
Joined: Sun Mar 11, 2018 5:37 pm
Location: France

Re: Precision of SOLVER ?

Post by J-F Garnier »

Walter wrote:
Mon May 22, 2023 8:12 am
Though what's the stop condition for the Solver unless it finds a root directly? I.e. if the last two approximations return results of opposite signs and the function there is 'small' but not zero? To me, it looks like this stop condition does depend on display format, however.
On the HP-42S, the stop condition (for "normal" functions with a true root, not a minimum) is either f(x)=0 or sign reversal for two neighbouring numbers (numbers that differ by 1 ULP). It may be different on Free42/DM42, but probably not the point here.

It's easy to show that the solver root doesn't depend on the display format. Try:

LBL "TST"
MVAR "X"
RCL "X"
E^X
2
-
RTN

The solver returns the root (which is LN(2)) with 10^-12 (on the HP-42S) or ~10^-34 (Free42) accuracy independently from the display format.

A small difference here between HP-42S and Free42, at least in my example (not sure it's a general rule) . Here the root is found by f(x)=0, the last two estimations in X and Y are equal on the HP-42S, but not on Free42.

The effect you see is probably caused by the function you are trying to solve, but without details on it, we can't analyse further.

J-F
Thomas Okken
Posts: 1100
Joined: Tue May 02, 2017 5:48 pm
Location: Netherlands
Contact:

Re: Precision of SOLVER ?

Post by Thomas Okken »

Walter wrote:
Mon May 22, 2023 8:12 am
Thomas Okken wrote:
Sun May 21, 2023 9:48 pm
Apart from functions that display numbers or convert them to strings, the only functions whose behavior is influenced by the display mode are RND, TRUNC, and AMORT.
Thanks, Thomas. Though what's the stop condition for the Solver unless it finds a root directly? I.e. if the last two approximations return results of opposite signs and the function there is 'small' but not zero?
If a function never evaluates to exactly zero, the iteration will still terminate eventually, when the lower and upper bounds of the search interval have become neighboring floating-point numbers. When that happens, whichever one evaluates to the absolutely smallest value will be reported as the root -- unless the values moved away from zero as the iteration approached the sign reversal, in which case it is reported as a Sign Reversal.
Walter wrote:
Mon May 22, 2023 8:12 am
To me, it looks like this stop condition does depend on display format, however.
What does your function look like?
User avatar
Walter
Posts: 3070
Joined: Tue May 02, 2017 11:13 am
Location: On a mission close to DRS, Germany

Re: Precision of SOLVER ?

Post by Walter »

Ok, here's the function to be solved:

Code: Select all

LBL "II"
MVAR "R"
1E-5
STO "ACC"
CLX
STO "LLIM"
PI
STO "ULIM"
RCL× "R"
STO+ ST X
RND
STO "X"
PGMINT "JJ"
INTEG "T"
END

LBL "JJ"
RCL "T"
ENTER
SIN
RCL× "X"
-
COS
END
SOLVER "II" 0.1 R 1 R R finds a root close to 0.6, for example.

EDIT: Background: The solver looks for the roots of the square of the Bessel function of the 1st kind and order 1. There's an infinite number of roots, beginning with 0.6, 1.1, and 1.6 (approximate values).

Don't forget setting RADians.
WP43 SN00000, 34S, and 31S for obvious reasons; HP-35, 45, ..., 35S, 15CE, DM16L S/N# 00093, DM42β SN:00041
Post Reply