(HP71B) Newton's method
|
11-18-2024, 01:22 PM
(This post was last modified: 11-21-2024 09:58 AM by Albert Chan.)
Post: #8
|
|||
|
|||
RE: (HP71B) Newton's method
Instead of calculating f(x±h), we can do f(x+h), f(x+h2), with x+h, x+h2 closer to true root.
From points {x, h=fnh(x)}, {x+h, h2=fnh(x+h)}, we solve for secant root Note: h = fnh(x) is simply scaled f(x), so that x + h is closer to true root. x - ((x+h)-x) / (fnh(x+h)-fnh(x)) * h = x + (-h/(h2-h)) * h = x + s * h Old s can be used to improve fnh(x), to get closer to true root (*) lua> f = fn'x:exp(x)-3*x*x' lua> f(3), f(4) -6.914463076812332 6.598150033144236 f root = 3 .. 4. For h, we need to scale down f(x), and flip its direction. 10 DEF FNF(X)=EXP(X)-3*X*X 20 INPUT "X,S = ";X,S @ H=X @ C=0 30 FOR I=1 TO 30 @ H=H/X @ IF 1+H*H=1 THEN EXIT I 40 H=FNF(X)*S @ H2=FNF(X+H)*S @ C=C+2 50 IF H2 THEN S2=H/(H-H2) @ H=H*S2 @ S=S*S2 60 X=X+H @ DISP X,H,C @ NEXT I Code: X,S = 3, -0.1 Code: X,S = 4, -0.1 Here is previous post 'flattened' FNF. We just need to switch direction. >10 DEF FNF(x) = 1 - 3*x^2/exp(x) Code: X,S = 3, -1 Code: X,S = 4, -1 (*) I had made a mistake replacing old s with new s (negated reciprocal slope) It should have been s = product of previous s's, and should converge to 1 value. Even if secant root is off, secant line slope should be close, and can be reused. Comment: This simple algorithm convergence rate is faster than Newton! For both examples, rate of convergence approaches (1+√2) ≈ 2.41421 Distributed per function call, we have √(1+√2) ≈ 1.55377 This is close to Secant's rate, φ = (1+√5)/2 ≈ 1.61803 Per iteration convergence rate calculations, mpmath with mp.dps = 10000 Numbers are log ratio of |relative errors| between iteration lua> ok = 3.73307902863 lua> log(abs(1-3.77904928733/ok)) / log(abs(1-3/ok)) -- 1st col, 1st row 2.701295751437436 Code: f(x) = exp(x) - 3*x*x f(x) = 1 - 3*x*x/exp(x) |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
(HP71B) Newton's method - Albert Chan - 10-01-2023, 03:59 PM
RE: (HP71B) Newton's method - Albert Chan - 10-01-2023, 04:34 PM
RE: (HP71B) Newton's method - Albert Chan - 10-01-2023, 09:47 PM
RE: (HP71B) Newton's method - Albert Chan - 10-02-2023, 04:04 PM
RE: (HP71B) Newton's method - Albert Chan - 11-12-2024, 12:12 PM
RE: (HP71B) Newton's method - Albert Chan - 11-13-2024, 01:12 PM
RE: (HP71B) Newton's method - Albert Chan - 11-13-2024, 08:38 PM
RE: (HP71B) Newton's method - Albert Chan - 11-18-2024 01:22 PM
RE: (HP71B) Newton's method - Albert Chan - 11-21-2024, 12:08 AM
|
User(s) browsing this thread: 1 Guest(s)