Bisection Solver - J E Patterson

J E Patterson - jepspectro.com

Description

J E Patterson - jepspectro.com - 20231119

Bisection Solver


This solver performs like the built-in solver but it is somewhat slower.

GSB A runs a self contained bisection solver which acts on f(x) = 0 under label E. This program was written to test the hp-15c Simulator by Torsten Manz.

Label E can hold any equation of the form f(x) = 0. Note that some of the hp-15C Owner's Handbook examples may require some extra ENTER statements at the beginning as the stack is expected to be filled with x. The open box example on page 189 requires three ENTER statements at the beginning.

To compare with the built-in solver press 1 ENTER 2 f SOLVE E.

A problem from the hp-15c Owner's Handbook - page 189:

A 4 decimetre by 8 decimetre metal sheet is available, i.e. 400 mm by 800 mm.
The box should hold a volume V of 7.5 cubic decimetres, i.e. 7.5 litres.
How should the metal be folded for the tallest box in decimetres.
We are using decimetres rather than mm because equation entry is simplified.
Let x be the height.
Volume V = (8 - 2x)(4-2x)x. There are two sides and two ends of height x.
Rearrange to f(x) = 4((x - 6)x + 8)x - V = 0 and solve for the height x.

Instructions:

There are 3 solutions depending on the guesses.

0 ENTER 1 GSB A gives x = a flat box with a height of 0.2974 decimetres or 29.74 mm.
1 ENTER 2 GSB A gives x = a reasonable height of 1.5 decimetres or 150 mm.
2 ENTER 3 GSB A can't find a root as there are none in this interval. Press any key to stop.
3 ENTER 4 GSB A can't find a root as there are none in this interval. Press any key to stop.
4 ENTER 5 GSB A returns the impossible box height x = 4.206 decimetres or 420.26 mm.

Solver:

Choose two guesses x1 and x0.
Do
Set flag 1
Calculate f(x0)
Let x2 = (x1 - x0)/2
Calculate f(x2)
If f(x2)*f(x0) < 0 let x1 = x2, clear flag 1
If flag 1 is set let x0 = x2
Loop until f(x2) = 0 within an error tolerance determined by the FIX, SCI or ENG significant digits setting.
Display root x2.

Notes:

Choose guesses which bracket the root of interest. Adjust for other roots. Guesses can be tested with GSB E. For the Bisection solver look for a sign change.

In SCI and ENG modes on the DM15 and a real hp-15C some roots are not always found. This is because RND is implimented slightly differently in the hp-15C Simulator. Just stop the iteration by pressing any key and examine the register where x is held. This can be done with GSB D. Alternatively change to FIX mode - e.g. FIX 4 before solving.

SOLVEkey.pdf has a good explanation of the additional tricks used to solve difficult equations using the built-in Solver.

Program Resources

Labels

Name Description
 A Bisection solve routine - needs two guesses in x and y
 D Recover root after program stop
 E Formula to Solve = 0
 1 Bisection loop updates x2 and either x0 to x1 or x1 to x0
 2 Store x0 to x1 and x2 to x2
 3 Store x1 to x0 and x2 to x1

Storage Registers

Name Description
.0 x0
.1 x1
.2 x2 = (x0+x1)/2
.3 f(x0)
.4 f(x2)

Flags

Number Description
1 If flag 1 is set x0 = x2 else x1 = x2

Program

Line Display Key Sequence Line Display Key Sequence Line Display Key Sequence
000 019 32 3 GSB 3 038 45 .1 RCL . 1
001 42,21,11 f LBL A 020 43, 6, 1 g F? 1 039 43 32 g RTN
002 44 .0 STO . 0 021 32 2 GSB 2 040 42,21,15 f LBL E
003 33 R⬇ 022 45 .4 RCL . 4 041 36 ENTER
004 44 .1 STO . 1 023 43 34 g RND 042 36 ENTER
005 42,21, 1 f LBL 1 024 43,30, 0 g TEST x≠0 043 36 ENTER
006 43, 4, 1 g SF 1 025 22 1 GTO 1 044 6 6
007 45 .0 RCL . 0 026 45 .2 RCL . 2 045 30
008 32 15 GSB E 027 43 32 g RTN 046 20 ×
009 44 .3 STO . 3 028 42,21, 2 f LBL 2 047 8 8
010 45 .1 RCL . 1 029 45 .2 RCL . 2 048 40 +
011 45,40, .0 RCL + . 0 030 44 .0 STO . 0 049 20 ×
012 2 2 031 43 32 g RTN 050 4 4
013 10 ÷ 032 42,21, 3 f LBL 3 051 20 ×
014 44 .2 STO . 2 033 45 .2 RCL . 2 052 7 7
015 32 15 GSB E 034 44 .1 STO . 1 053 48 .
016 44 .4 STO . 4 035 43, 5, 1 g CF 1 054 5 5
017 45,20, .3 RCL × . 3 036 43 32 g RTN 055 30
018 43,30, 2 g TEST x<0 037 42,21,14 f LBL D 056 43 32 g RTN