Post Reply 
(71B) Bisection Plus for the HP-71B
01-12-2014, 05:44 PM (This post was last modified: 06-15-2017 01:37 PM by Gene.)
Post: #1
(71B) Bisection Plus for the HP-71B
This program implements the new Bisection Plus algorithm for the HP-Prime. Click here to download a pdf file that discusses the new algorithm.

I have attached a ZIP file that contains the program for the Windows HP-71B emulator.

Algorithm

Code:
Given f(x)=0, the root-bracketing interval [A,B], and the tolerance for the root of f(x):

Calculate Fa = f(A) and Fb=f(B).
Exit if Fa*Fb > 0
X2 = A
Repeat 
  LastX2 = X2
  X1=(A+B)/2
  Fx1 = f(X1)
  If Fx1*Fa > 0 then
    Slope = (Fb – Fx1)/(B – X1)
    Intercept = Fb – Slope * B
  Else
    Slope = (Fa – Fx1)/(A – X1)
    Intercept = Fa – Slope * A
  End If  
  X2=-Intercept / Slope
  Fx2 = f(X2)
  If Fx1*Fx2 < 0 then
    A = X1
    Fa = Fx1
    B = X2
    Fb = Fx2
  Else
    If Fx2*Fa > 0 then
      A=X2
      Fa=Fx2
    Else
      B=X2
      Fb=Fx2
    End If
  End If  
Until |A-B| < tolerance OR |X2 - LastX2| < toelrance
Return X2

HP-71B Implementation

Code:
10 REM BISECTION PLUS
20 DESTROY ALL
30 DEF FNX(X)=EXP(X)-3*x^2
40 INPUT "A? ";A
50 INPUT "B? ";B
60 INPUT "TOLER? ";T
70 IF T<=0 OR T>=1 THEN T=1E-8
80 F7=FNX(A) @ F8=FNX(B)
90 IF F7*F8>0 THEN 380
95 X2=A @ I9=0 
100 I9=I9+1 @ L=X2 @ X1=(A+B)/2
110 F1=FNX(X1)
120 IF F1*F7<0 THEN 160
130 S = (F7 – F1)/(A – X1)
140 I = F7 – S * A
150 GOTO 180
160 S = (F8 – F1)/(B – X1)
170 I = F8 – S * B
180 X2 = -I / S # DISP x2 @ WAIT .2
190 F2 = FNX(X2)
200 if F1*F2 > 0 THEN 260
210 A = X1
220 F7 = F1
230 B = X2
240 F8 = F2
250 GOTO 320
260 If F2*F7 < 0 THEN 300
270 A=X2
280 F7=F2
290 GOTO 320
300 B=X2
310 F8=F2
320 IF ABS(A - B) < T THEN 350
330 IF ABS(X2 - L) < T THEN 350
340 GOTO 100
350 DISP "ROOT = ";X2 @ PAUSE
360 DISP "ITERS = ";I9
370 GOTO 390
380 DISP "FA AND FB HAVE SAME SIGN"
390 END

Usage

1. Press [RUN]. The program prompts you to enter the the value of A.
2. Key in the value of A and press [ENTER]. The program prompts you to enter the the value of B.
3. Key in the value of B and press [ENTER]. The program prompts you to enter the the value for the tolerance.
4. Key in the value for the tolerance and press [ENTER].
5. The program displays intermediate refinement for the guess. When it converges the program displays "ROOT=" followed by the root value.
6. Press [CONT]. The program displays the number of iterations.

Example

Find the root for f(x)=exp(x)-3*X^2 in the range [3, 4].

1. Press [RUN]. The program prompts you to enter the the value of A.
2. Key in 3 and press [ENTER]. The program prompts you to enter the the value of B.
3. Key in 4 and press [ENTER]. The program prompts you to enter the the value for the tolerance.
4. Key in 1E-8 and press [ENTER].
5. The program displays intermediate refinement for the guess. When it converges the program displays "ROOT=3.73308".
6. Press [CONT]. The program displays the number of iterations as "ITER=7".

Customization

Line 30 contains the definition of f(X). Edit this line to reflect your function.


Attached File(s)
.zip  Bisection Plus.zip (Size: 1.6 KB / Downloads: 7)
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(71B) Bisection Plus for the HP-71B - Namir - 01-12-2014 05:44 PM



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