收敛时牛顿法的收敛速度是二阶的,不低于二阶。如果函数有重根,牛顿法一般不是二阶收敛的。
x
k
+
1
=
x
k
?
f
(
x
k
)
f
′
(
x
k
)
x_{k+1}=x_k- \frac{f(x_k)}{f'(x_k)}
xk+1?=xk??f′(xk?)f(xk?)?
matlab实现
%% 牛顿迭代例子
f = @(x) x.^2-2;
g = @(x) 2.*x;
x = newton(f,g,2,1e-7,100)
%% 牛顿迭代
function x = newton(f,g,x_0,eps,max_iter)
x0 = x_0;
for i = 1:max_iter
x = x0 - f(x0)/g(x0)
if abs(x-x0)<eps
break
end
x0 = x;
end
end
实际上是对每次迭代跳跃步长的修正,试着少条一点距离,看是否在下山。
matlab编程实现
%% 牛顿迭代例子
f = @(x) x.^2+sin(10*x)-1;
g = @(x) 2.*x+10*cos(10*x);
[x,i] = newtonD(f,g,30,1e-16,100)
%% 牛顿下山法
function [x,i] = newtonD(f,g,x_0,eps,max_iter)
x0 = x_0;
for i = 1:max_iter
lbd = 1;
x = x0 - f(x0)/g(x0)*lbd;
while abs(f(x))>=abs(f(x0))
lbd = lbd/2;
x = x0 - f(x0)/g(x0)*lbd;
end
if abs(f(x))<eps
break
end
x0 = x;
end
end