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

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...