Post Reply 
Variant of the Secant Method
12-09-2020, 04:38 PM (This post was last modified: 12-09-2020 11:21 PM by Albert Chan.)
Post: #3
RE: Variant of the Second Method
Let's try solving x, for sinc(x) = 1/6.5

lua> function f(x) return sin(x)/x - 1/6.5 end
lua> function secant(x1,y1,x2,y2) return x1-y1/(y2-y1)*(x2-x1) end
lua> x1, x2 = 2.711, 2.712
lua> y1, y2 = f(x1) , f(x2)
lua> x3 = secant(x1,y1, x2,y2)
lua> y3 = f(x3)
lua> x3
2.7113129474671775

-- Inverse Interpolation, assumed f(x) is strictly increasing or descreasing around root
-- Fit x = g(y), then evaluate g(0)

lua> x12 = (x2-x1)/(y2-y1)
lua> x23 = (x3-x2)/(y3-y2)
lua> x123 = (x23-x12)/(y3-y1)
lua> x3 + (0-y3)*(x23 + (0-y2)*x123)
2.711312910356982

-- Aikten interpolation, as 1 liner: inner secant = x4, outer secant = x5
-- y1 x1
-- y2 x2 x3
-- y3 x3 x4 x5

lua> secant(secant(x3,y3, x1,y1),y3, x3,y2)
2.711312910356982

-- improved secant, interpolate for slope

lua> y23 = (y3-y2)/(x3-x2)
lua> y12 = (y2-y1)/(x2-x1)
lua> y123 = (y23-y12)/(x3-x1)
lua> slope = y23 + (x3-x2)*y123
lua> x3 - y3/slope
2.7113129103569826

-- Newton's method, actual slope

lua> x, y = x3, y3
lua> slope = (x*cos(x) - sin(x))/x^2
lua> x - y/slope
2.711312910356983

For reference, I used ASINC, for Free-42 Decimal.
Comparing apples to apples, input is float(1/6.5) = 0x1.3b13b13b13b14p-3

5542891849071380 2 55 X^Y รท XEQ "ASINC"

2.71131291035698331469084928874754

All 3 methods gives excellent results, doubling accuracy of x3
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Variant of the Secant Method - ttw - 12-09-2020, 04:33 AM
RE: Variant of the Second Method - Albert Chan - 12-09-2020 04:38 PM
RE: Variant of the Secant Method - Namir - 12-10-2020, 01:54 PM
RE: Variant of the Secant Method - Namir - 12-10-2020, 02:56 PM
RE: Variant of the Secant Method - Namir - 12-12-2020, 04:22 AM
RE: Variant of the Secant Method - ttw - 12-12-2020, 02:41 PM



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