Showing posts with label Bisection method. Show all posts
Showing posts with label Bisection method. Show all posts

Saturday, August 21, 2021

TI-95 ProCalc: Approximate Derivative and Bisection Method

TI-95 ProCalc: Approximate Derivative and Bisection Method


Introduction:  The Label FX and Flags to set Radians Mode

The two programs presented today will use a subroutine with the label FX.  FX is going to be where you store your function.  I have designated the variables such that X can be used as storing and recall in the subroutine.   To edit FX:

In run mode (out of LEARN):  [ 2nd ] [ 2 ] (GTL) FX, [ LEARN ] [ F2 ] (PC)

The subroutine FX must end with = RTN.  

Radians mode can be set during programming with the following flag commands: RF 34 SF 33.

FYI, Degrees Mode:  RF 34 RF 33

And Gradians Mode:  RF 33 SF 34

Approximate Derivative

This program calculates f'(x), rounds, and displays the answer to five decimal places.  

f'(x) ≈ ( f(x + h) - f(x - h) ) / ( 2 * h ),  h is set to 10^-5

FIX 9 resets the TI-95 ProCalc to floating (all/standard) mode.

TI-95 ProCalc File DRV
Size:  varies

RF 34 SF 33 1 EE 5 +/- STO H

CLR 'X?' BRK STO A 

+ RCL H = SBL FX STO D

RCL A - RCL H = SBL FX ST- D

RCL D / ( 2 * RCL H ) = 

FIX 5 RND FIX 9 STO D HLT

LBL FX   [insert f(x) here, do not store values to A or H] = RTN

Examples

f(x) = x * sin x 
FX:  STO X * SIN = RTN
f'( π/5 ) returns 1.09611 
f'( 1.6*π ) returns 0.60223

f(x) = 3 * e^x
FX:  INV LN * 3 = RTN
f'( 1 ) returns 8.15485
f'( -1.215 ) returns 0.89013

Bisection Method

The bisection method finds a root for the equation f(x) = 0.  An advantage to the bisection method is that there is no requirement to calculate the derivative.  However, two initial guesses a and b are required such that f(a) * f(b) < 0, and the calculation process can be lengthy.

I set the tolerance to 10^-10.   

Note:  I will need a variable to store the 0 value.  IF tests on the TI-95 ProCalc can not compare to numeric values directly.   I use the variable Z to store 0.

TI-95 ProCalc File BIS
Size:  varies

'BISECTION F(X)=0' PAU

CLR 'A?' BRK STO A

CLR 'B?' BRK STO B

10 +/- INV LOG STO T

0 STO Z

LBL A0 ( RCL A + RCL B ) / 2 = STO C

SBL FX STO F ABS IF <T GTL BO

RCL B SBL FX * RCL F = IF >Z GTL A1

RCL C STO A GTL A0

LBL A1 RCL C STO B GTL A0

LBL B0 CLR 'SOL=' COL 16 MRG C HLT

LBL FX  [insert f(x) here, do not store values to A, B, C, T, or Z] = RTN

Examples

3*x - e^x = 0
FX:  STO X * 3 - RCL X INV LN = RTN
Interval:  [1, 2] (A = 1, B = 2)
Result: 1.512134552

x - 2^(-x) = 0
FX:  STO X - 2 y^x RCL X +/- = RTN
Interval:  [0, 1]  (A = 0, B = 1)
Result:  0.6411857446

Source:
Byju's Classes  "Bisection Method - Definition, Procedure, and Example"  https://byjus.com/maths/bisection-method/  Retrieved June 5, 2021

Commas added to the results for readability.  

Eddie

All original content copyright, © 2011-2021.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author. 

Sunday, January 4, 2015

fx-5800p: Bisection Method

fx-5800p: Bisection Method

The program BISECT finds a root for f(X) given an initial open interval of (A, B). I have the tolerance set to 10^-9. To prevent calculations from going "forever", I set the maximum number of iterations to 150. You can adjust these factors in the program as desired.

The first point to be tested is (A+B)/2. If this is a root, the program stops and it will return this root as a result.

The program BISECT calls on a subroutine program FX. The function f(X) is stored in FX.

While programming, use the Prog to call subroutines. The syntax is:


Prog "name of subroutine in quotes"


Press [SHIFT] [FILE].

Remember for the fx-5800p, all variables (A-Z, and Z[#]s) are global, meaning they will carry over from programs and subroutines.

Anything following the double slash (//) is a comment.

Program FX
insert function of X here → Y
//store result in Y

// A Return command is implied.

Program BISECT
1 → I // I = iteration count
"A"? → A
"B"? → B
A → X
Prog "FX"
Y → C
B → X
Prog "FX"
Y → D
While Abs(A-B) > 10^(-9) // tolerance setting
(A + B) ÷ 2 → X
Prog "FX"
If Y = 0
Then
Break
IfEnd
If Y*C > 0
Then
X → A
Y → C
Else
X → B
Y → D
IfEnd
I + 1 → I
If I > 150 // iteration limit
"ITER. EXCEEDED" ◢
Stop
IfEnd
WhileEnd // finish the loop
"ITERATIONS:" ◢ // optional
I ◢ // optional
"ROOT=" ◢ // result
X


Example:

f(X) = X^(3)-2X+1, for the intervals (-2,0), (0,2), and (0,1).

Program FX would look like this:

Program FX
X^3 - 2*X + 1 → Y


Run BISECT.

For (-2,0), results are:
ITERATIONS: 32
ROOT = -1.618033989

For (0,2), results are:
ITERATIONS: 1
ROOT = 1

For (0,1), results are:
ITERATIONS: 31
ROOT = 0.6180339893



This blog is property of Edward Shore. 2015

HP 67 Collection: October 2026

HP 67 Collection: Oct ober 2026 All examples are done in FIX 4. (DSP 4) Earth's Gravity at a Specific Latitude The true ea...