Variant of the Secant Method
|
12-11-2020, 04:34 PM
(This post was last modified: 02-07-2021 11:57 AM by Albert Chan.)
Post: #7
|
|||
|
|||
RE: Variant of the Secant Method
Quadratic interpolation is simply 2 linear interpolations, followed by linear interpolation.
x3 y3 x2 y2 y23 x1 y1 y13 y123 Similarly, cubic interpolation is 2 quadratic interpolations, followed by linear interpolation. x4 y4 x3 y3 x2 y2 y234 x1 y1 y134 y1234 Using this recursive nature of polynomial interpolation, I get this neat Lua code Code: function interp(x1,y1,x2,y2,x3,y3,x4,y4) -- estimate y = p(0) Extending interp(...) is trivial, by adding (x5,y5), ... The down-side is each bump up in polynomial degree, doubled the work. For high degree fit, divided-difference style is better, because it can cache previous results. OTTH, assuming we have convergence, old points are very, very far away. Fitting those probably may not help much ... --- For slope of improved secant, we can also consider this an interpolation problem. Example, for a cubic fit, we generate divided-difference table: x4 y4 x3 y3 y34 x2 y2 y24 y234 x1 y1 y14 y123 y1234 p(x) = y4 + (x-x4)*(y34 + (x-x3)*(y234 + (x-x2)*y1234)) = y4 + (x-x4)*M p'(x) = M + (x-x4)*M' → p'(x4) = M Basing all values relative to (x4, y4). Example X3 = x3-x4, Y3 = y3-y4 ... M is just interpolation of individual slopes. X3 Y3/X3 X2 Y2/X2 X1 Y1/X1 M Again, extending this is simply adding more slopes to fit Code: function secant(x1,y1,x2,y2,x3,y3,x4,y4) -- estimate root of p(x) Example: lua> function f(x) return sin(x)/x - 1/6.5 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> interp(y1,x1, y2,x2, y3,x3) -- inverse interpolate, x = g(0) 2.711312910356982 lua> secant(x1,y1, x2,y2, x3,y3) -- improved secant, x = x3 - y3/slope 2.7113129103569826 |
|||
« Next Oldest | Next Newest »
|
Messages In This Thread |
Variant of the Secant Method - ttw - 12-09-2020, 04:33 AM
RE: Variant of the Second Method - Valentin Albillo - 12-09-2020, 05:40 AM
RE: Variant of the Second Method - Albert Chan - 12-09-2020, 04:38 PM
RE: Variant of the Secant Method - Albert Chan - 12-09-2020, 11:51 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 - Albert Chan - 12-11-2020 04:34 PM
RE: Variant of the Secant Method - Albert Chan - 12-11-2023, 03:25 PM
RE: Variant of the Secant Method - Albert Chan - 12-11-2020, 04:46 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
RE: Variant of the Secant Method - Albert Chan - 12-12-2020, 04:27 PM
RE: Variant of the Secant Method - Thomas Klemm - 12-16-2023, 08:11 PM
|
User(s) browsing this thread: 2 Guest(s)