(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: 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 |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(12C) Secant Method solution of f(x)=0 - Gamo - 03-31-2018, 12:43 PM
RE: (12C) Secant Method solution of f(x)=0 - Dieter - 04-02-2018 08:01 AM
RE: (12C) Secant Method solution of f(x)=0 - Csaba Tizedes - 10-19-2019, 06:40 PM
|
User(s) browsing this thread: 1 Guest(s)