Sunteți pe pagina 1din 8

ROOT FINDING WITHOUT DERIVATIVES

Secant Method for solving f (x) = 0.


Secant line analysis: given x0, x1, use
f (x) f (x1) + (x x1)(f (x1) f (x0))/(x1 x0);

Use
x2 = x1 f (x1)(x1 x0)/(f (x1) f (x0)).
Basic Secant Method Algorithm: starting with
approximation x0, tolerance  and maximum steps N
1. Initialize with x0, x1 and i = 1;
2. Set xi+1 = xi f (xi)(xi xi1)/(f (xi) f (xi1));
3. If |xi+1 xi| >  and i < N ,
set i = i + 1 and go to step 2;
4. Stop with x = xi+1.
Notes:
i) only one new f value per step;
ii) do NOT use equivalent
x2 = (f (x1)x0 f (x0)x1)/(f (x1) f (x0)).

SECANT METHOD CONTINUED


Example: f (x) = x2 sin(x) 0.5.
f = @(x) x^2 - sin(x) - .5;
x = 1; fx = f(x); xp = 2; N = 7;
for i = 1:N
xm = x; fm = fx; x = xp; fx = f(x);
xp = x - fx*(x-xm)/(fx - fm);
disp([i x fx ] )
end, disp([N+1 xp f(xp)])
1
2
2.59070257317432
2
1.11645660737862
-0.152075644623564
3
1.16544541373339
-0.0607010618578058
4
1.19798917453506
0.0038694983567148
5
1.19603893547061
-8.73202586370025e-05
6
1.19608197393057
-1.20286009708259e-07
7
1.19608203329899
3.74922315415915e-12
8
1.19608203329713
-2.22044604925031e-16
x = 0; fx = f(x); xp = -1; N = 7;
...
1 -1
1.3414709848079
2 -0.27152206259289
-0.158077722738297
3 -0.348315922526153
-0.0373606725858036
4 -0.372082824168815
0.002002148159166
5 -0.370873945905714
-2.24188181774387e-05
6 -0.370887332285262
-1.31002297898419e-08
7 -0.370887340112043
8.58202398035246e-14
8 -0.370887340111992
-5.55111512312578e-17
2

SECANT ERROR ANALYSIS


Secant Method analysis: use Taylor series, xi = r + ei

Superlinear convergence:
if a sequence {xn} converges to r with
lim =

|en+1|
= M,

|en|

constant, with > 1, then


the sequence has superlinear convergence.
Note: can show for Secant method that |en+1| M |en|1.618,
with M |f 00(r)/(2f 0(r))|.618.

ROOT FINDING WITHOUT DERIVATIVES


Method of False Position :
combines root bracketing with Secant method.

Algorithm
Initialize: find a1, b1, with f (a1)f (b1) < 0;
For i = 1 : N
compute c = bi f (bi)(bi ai)/(f (bi) f (ai));
if f (ai)f (c) < 0, set bi+1 = c, ai+1 = ai;
otherwise, set ai+1 = c, bi+1 = bi;
EndFor
Set r c.

ROOT FINDING WITHOUT


DERIVATIVES
Matlab:
f = @(x) x^2 - sin(x) - .5;
a = 1; fa = f(a); b = 2; fb = f(b); N = 9;
for i = 1:N
c = b - fb*(b-a)/(fb-fa); fc = f(c);
if fa*fc<0, b=c;fb=fc; else, a=c;fa=fc; end
disp([i c fc ] )
end
% i
x_i
f(x_i)
1
1.11645660737862
-0.152
2
1.16544541373339
-0.0607
3
1.18455165198974
-0.0232
4
1.19177925704792
-0.00869
5
1.19448151386991
-0.00324
6
1.19548739458057
-0.00120
7
1.19586120639367
-0.000447
8
1.19600003989364
-0.000166
9
1.19605159087838
-0.0000617
Notice linear convergence.

ROOT FINDING WITHOUT DERIVATIVES


Mullers Method : uses to three f values to fit a quadratic;
closest xaxis crossing point for quadratic approximates r.
Given x0, x1), x2), let
f (x) P (x) = f (x2) + u(x x2) + v(x x2)2;
find u and v so that P (x0) = f (x0), P (x1) = f (x1).
Then find x3 so that P (x3) = 0:
p

2
x3 = x2 2f (x2)/ u + sign(u) u 4f (x2)v

Example with
f (x) = x2 sin(x) 0.5, x0 = 0, x1 = 2, x2 = .5:
% i
3
4
5
6
7
8

x_i
1.18893279136691
1.19606169851046
1.19608203426444
1.19608203329713
1.19608203329713
NaN

f(x_i)
-0.0144
-4.12e-05
1.96e-09
2.22e-16
2.22e-16
NaN

Can show ei+1 eiei1ei2K e1.84


i M.
Convergence is superlinear with = 1.84.
6

ROOT FINDING WITHOUT DERIVATIVES


Brents Method : combines root bracketing with
inverse quadratic interpolation and Secant methods.
Inverse quadratic interpolation (IQI):
uses three x values a, b, c with f values A, B, C to form
a(y B)(y C) b(y A)(y C) c(y A)(y B)
+
+
P (y) =
(A B)(A C) (B A)(B C) (C A)(C B)

New x value is
aBC
AbC
ABc
P (0) =
+
+
;
(A B)(A C) (B A)(B C) (C A)(C B)
rewritten in corrected form
r(r q)(c b) + (1 r)s(c a)
xi+1 = c
(q 1)(r 1)s 1)
with q = A/B, r = C/B, s = C/A.
Can show ei+1 eiei1ei2K e1.84
i M.
Convergence is superlinear with = 1.84.
7

ROOT FINDING WITHOUT


DERIVATIVES
Brent algorithm: initialize a, b, c with bisection method;
i) use IQI or Secant for new xi;
ii) replace one of a, b, c with new xi
if backward error and bracketing interval are reduced;
iii) otherwise use another bisection step for new a, b, c.
Matlab implementation is fzero.
f = @(x) x^2 - sin(x) - .5;
r = fzero(f,[1 2],optimset(Display,iter));
disp(r)
Func-count
x
f(x)
Procedure
2
1
-0.341471
initial
3
1.11646 -0.152076
interpolation
4
1.20478
0.0177367
interpolation
5
1.19556 -0.00106592
interpolation
6
1.19608 -6.67124e-06 interpolation
7
1.19608
3.07732e-11 interpolation
8
1.19608 -2.22045e-16 interpolation
1.19608203329713

S-ar putea să vă placă și