Post Reply 
(12C) Secant Method solution of f(x)=0
04-02-2018, 08:01 AM (This post was last modified: 04-02-2018 12:55 PM by Dieter.)
Post: #2
RE: (12C) Secant Method solution of f(x)=0
(03-31-2018 12:43 PM)Gamo Wrote:  Setup Procedure:
1. Store Two Guesses at R0 and R2
2. Store f(x) end point at R1
3. Store Tolerant at R4
4. Store Interval at R3
5. GTO 03
6. R/S

What is "f(x) end point" in step 2 ? Why is it 1 in the example?
And what is the "interval" in step 4 ? Why is it –1 in the example?
I get an Error 0 if I run the program with the example data.

Looking at the program, I think the values in R1 (step 2) and R3 (step 4) should be f(x1) and f(x2).

(03-31-2018 12:43 PM)Gamo Wrote:  Example: X^X=Y
Problem: X^X=1000
f(x) Program:
GTO 28
P/R
LN
LSTx
x
EEX
3
-
STO1
GTO 03
P/R

Here f(x) is rewritten as x*ln(x) – ln 1000 = 0
So there is a "LN" missing after the EEX 3.

And here's a tip: You can elegantly store x1 and f(x1) during the calculation.

Code:
RCL 2
RCL 0
STO 2
-
RCL 3
RCL 1
STO 3
-
/

And another tip: if you want to check if |x| is less than R4 (error tolerance) you can also divide x by R4 and check if the integer part is zero. This is both shorter and faster, three steps instead of six:

Code:
...
RCL 4
/
INT
X=0?
GTO 01

BTW checking the relative error (division by R0) may cause problems since R0 can be zero. You can avoid this if you replace this value with 1:

Code:
...
STO-0
RCL 0
x=0?
e^x
/

Maybe you can try this version:

Code:
01 STO 4
02 Rv
03 STO 3
04 Rv
05 STO 2
06 Rv
07 STO 1
08 RCL 1
09 RCL 2
10 STO 1
11 -
12 RCL 3
13 RCL 4
14 STO 3
15 -
16 /
17 RCL 4
18 x
19 STO-2
20 RCL 2
21 X=0?
22 e^x
23 /
24 EEX
25 8
26 x
27 INTG
28 X=0?
29 GTO 31
30 GTO 33
31 RCL 2
32 GTO 00
33 RCL 2
34 ENTER    // start f(x)
35 LN
36 x
37 EEX
38 3
39 LN
40 -   .
41 STO 4    // end f(x) with
42 GTO 08   // these two lines

You have to enter the two guesses x1 and x2 as well as their respective function values f(x1) and f(x2). The program expects them on the stack. You can also store them manually in R1...R4 and remove the first seven lines, which makes the program much shorter. In this case, here is the register mapping:

R1:  x1
R2:  x2
R3:  f(x1)
R4:  f(x2)

If in the example the guesses are 3 and 5 their function values are f(3)=–3.611918412 and f(5)=1.139434281. But usually rounded values will do:

3 [ENTER] 5  [ENTER]  –3,6 [ENTER] 1,1  [R/S]
=> 4,555535706

You can even round f(x1) to –4 and f(x2) to 1 and it still works. If you're lazy you may even try just the signs of f(x), here –1 and +1 (which indeed is enough to return a correct result).

An input for the relative error threshold is not required, the program quits if it drops below 1E–8 which usually means that the result is as good as it gets.

However, I think the already posted modified Regula Falsi / Illinois algorithm works better than the Secant Rule, so it should be preferred.

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (12C) Secant Method solution of f(x)=0 - Dieter - 04-02-2018 08:01 AM



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