(71B) Bisection Plus for the HP-71B - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: General Software Library (/forum-13.html) +--- Thread: (71B) Bisection Plus for the HP-71B (/thread-419.html) |
(71B) Bisection Plus for the HP-71B - Namir - 01-12-2014 05:44 PM 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): HP-71B Implementation Code: 10 REM BISECTION PLUS 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. RE: (71B) Bisection Plus for the HP-71B - C.Ret - 06-11-2021 06:37 PM Hi, I really appreciate this algorithm that stay in the inputted range. Today, it serve me a bit seeking for the roots of a bunch of polynomials. I just modify the original program to add two features :
As useall, since I modified and enhance a few the original code, I post here to share for further user . 5 DIM F$[49] 10 INPUT "F(X)=",F$;F$ @ INPUT "[A,B]=";A,B @ INPUT "Tol=","1E-8";T @ INPUT "MaxIte=","30";M 12 X=B @ Y2=VAL(F$) @ X=A @ Y1=VAL(F$) @ IF Y1*Y2>0 THEN BEEP @ DISP "Fa & Fb = sign !" @ END 14 FOR N=1 TO M @ P=X @ X=(A+B)/2 @ Y=VAL(F$) @ IF ABS(B-A)<T THEN 24 16 IF Y*Y1<0 THEN S=(Y1-Y)/(A-X) @ I=S*A-Y1 ELSE S=(Y2-Y)/(B-X) @ I=S*B-Y2 18 L=X @ Z=Y @ X=I/S @ Y=VAL(F$) @ IF Y=0 OR ABS(P-X)<T THEN 24 20 IF Z*Y<0 THEN A=L @ Y1=Z @ B=X @ Y2=Y ELSE IF Y*Y2<0 THEN A=X @ Y1=Y ELSE B=X @ Y2=Y 22 DISP X @ NEXT N @ BEEP 24 DISP USING '3ZX,"F("K,")="SDE';N,T*(X DIV T),Y @ END Usage:
The program displays intermediate refinement for the guess. Eventually, adjust display speed with DELAY command. This have to be tuned before starting the program. When it converges or after the maximal iteration count, the program displays the root value in the format : 00n F( x.xxxxxxxx ) = ±#E-0##. Where: 00n indicate iteration count. x.xxxxxxxx is the root \( x_0 \) rounded to the tolerance. ±#E-0## is the sign and amplitude of the residual \( y=F(x_0)\approx 0 \) Another root can be seek for the same function or for a new function, just press [ f ][CONT] or [RUN] to process. All the parameters can be kept or modified as wish... no edition of the program is needed. Step 1: Root of \( f(x)=e^x-3x^2 \) in \( \left [\,-2\,,\,0\,\right ] \) Code: [RUN] Code:
Code: F(X)=EXP(X)-3*X^2 [END LINE] Edited 25.06.2021 for typos and examples reformat |