Post Reply 
(12C) Solve f(x)=0 with modified Regula Falsi method
03-26-2018, 07:43 AM (This post was last modified: 03-26-2018 10:08 AM by Dieter.)
Post: #3
RE: (12C) Solve f(x)=0 with modified Regula Falsi method
(03-26-2018 06:26 AM)Gamo Wrote:  Solve X^3 = 3^X
Rewrite equation to X^3 - 3^X = 0

...

The answer is 2.478052679

One answer is 2,47805. But there are two.

(03-26-2018 06:26 AM)Gamo Wrote:  I try initial guess 1 ENTER 3 R/S > return 3

Sure. X=3 is a solution: 3^3 = 3^3.

(03-26-2018 06:26 AM)Gamo Wrote:  press R/S again > Error 0

Why do you press R/S again? What do you want to do this way?

If you press R/S again you restart the solver with two identical guesses 3 and 3. So the calculated secant is a horizontal line that will never cross the x-axis and a division by zero will occur. That's why the two guesses must be different.

However, the program can be changed so that it does accept two identical guesses if these are already a root of f(x). See below.

(03-26-2018 06:26 AM)Gamo Wrote:  Did I do something wrong?

You simply didn't notice that 3 is one of the two solutions. ;-)

- If you enter 1 and 3 as initial guesses the program correctly returns X=3.
- Of course the program can also calculate the other root: simply start with different guesses, for instance 1 and 2,5 => 2,478052679.

BTW, the exact root is 2,4780526802883..., but with 10 digit precision everything between 2,478052678 and ...683 evaluates to f(x)=0. If you start with 1 and 2,8 or 1 and 2,9 you will get these results.

Edit: here is a modified version that works even with two identical guesses if these are a root of f(x).
f(x) now starts at line 76 and ends with GTO 10.

Code:
01 STO 2   store b
02 x<>y
03 STO 1   store a
04 1
05 CHS
06 STO 0   flag := -1
07 RCL 1
08 STO 3
09 GTO 76  calculate f(a)
10 x=0?    all f(x) calls return here
11 GTO 73  if f(x)=0 then quit
12 RCL 0
13 x=0?    flag = 0?
14 GTO 54  this was an f(c) call, continue with iteration loop
15 0
16 x<=y?   flag > 0?
17 GTO 26  this was an f(b) call, continue with storing f(b)
18 Rv
19 Rv      so flag is < 0
20 STO 4   this was an f(a) call, continue with storing f(a)
21 1
22 STO 0   flag := +1
23 RCL 2
24 STO 3
25 GTO 76  calculate f(b)
26 STO 0   flag := 0
27 Rv
28 Rv
29 STO 5   store f(b)
30 RCL 4
31 x       f(a) x f(b)
32 CHS     if no sign change between a and b
33 SQRT    stop with error message
34 RCL 2
35 RCL 2
36 RCL 1   step 34 - 44
37 -       calculate the
38 RCL 5   new approximation c
39 RCL 4
40 -
41 /
42 RCL 5
43 x
44 -
45 STO 3   store c
46 RND     round c to display precision
47 RCL 2
48 RND     round b to display precision
49 -
50 x=0?    do both agree?
51 GTO 73  then exit
52 RCL 3
53 GTO 76  calculate f(c)
54 Rv      return from f(c) call, f(c) is in Y
55 RCL 5
56 x<>y
57 x       f(b) x f(c)
58 0
59 x<=y?   no sign change between b and c?
60 GTO 66  then apply Illinois correction
61 RCL 2
62 STO 1   else a := b
63 RCL 5   and f(a) := f(b)
64 STO 4
65 GTO 68
66 2       Illinois adjustment:
67 STO/4   f(a) := 1/2 f(a)
68 RCL 3
69 STO 2   b := c
70 LastX
71 STO 5   f(b) := f(c)
72 GTO 34  and do another iteration
73 RCL 2   exit routine: return previous
74 RCL 3   and final approximation
75 GTO 00  and quit
76 ...     start f(x) here
nn GTO 10  end f(x) with this line

Additional feature: in the f(x) code, x now can be addressed with "RCL 3".
So your example can be coded like this:

3
Y^X
3
RCL 3
Y^X


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


Messages In This Thread
RE: (12C) Solve f(x)=0 with modified Regula Falsi method - Dieter - 03-26-2018 07:43 AM



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