(12C) Secant Method solution of f(x)=0
|
03-31-2018, 12:43 PM
(This post was last modified: 04-02-2018 01:49 PM by Gamo.)
Post: #1
|
|||
|
|||
(12C) Secant Method solution of f(x)=0
This Secant Method used only 29 line in the program but come with a cost of more steps to setup.
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 Example: X^X=Y Problem: X^X=1000 f(x) Program: GTO 28 P/R LN LSTx x EEX 3 LN - STO1 GTO 03 P/R Setup: 1. 3 STO 0, 5 STO 2 2. 1 STO 1 3. EEX CHS 6 STO 4 4. 1 CHS STO 3 5. GTO 03 6. R/S Answer: 4.555535705 Program: Code:
Gamo |
|||
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: 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 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 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: ... 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: ... Maybe you can try this version: Code: 01 STO 4 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 |
|||
10-19-2019, 06:40 PM
Post: #3
|
|||
|
|||
RE: (12C) Secant Method solution of f(x)=0
A little idea, because I hate to calculate the next estimated root. (A BIG HINT: With this method you can easily implement Muller's method if your calculator include parabolic fit!!!)
For secant method here is a "skeleton", but it can be run: Code: 0 Usage similar as above:
For e^x=x^2:
The result: Code: -1.4286 R/S Csaba |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)