导数与牛顿迭代法_Derivative and Newton iterative algorithm

导数的概念:
设y=f(x)在x0的邻域U内有定义,x0,x0+△x∈U,△x:该变量,增量.△y = f(x0+△x)-f(x0),△y/△x = [f(x0+△x)-f(x0)]/△x;
如果lim(△x->0) △y/△x 存在,则称此极限为f(x)在x0处的导数.记为:f’(x0)或y’|(x=x0)或dy/dx|(x=x0)

1.给定f(x),x0,则f’(x0)随之而确定,f’(x0)是一个数.
2.求导过程中△x->0是变量
3.若f(x)在(a,b)内每一点都可导,则称f(x)在(a,b)区间可导.
f’(x0) = lim(△x->0) △y/△x;

例如:f(x) = x3 ,求x=2时的导数.

f ‘ (x) = △y/△x;

△y = f(x+△x) - f(x) = (x+△x)3-x3 = 3x2△x + 3x△x2 + △x3 ;

所以f ‘ (x) = 3*x2 ;(因为△x趋向于0);

f ‘ (2) =12;

导数的一些性质:

几何性质:曲线y = f(x)在(x0,f(x0))的切线存在,且此切线不垂直于x轴.
(曲线折点切线不存在,点切线垂直于x轴,tg 值无限大,所以不可导)

wiki导数的介绍: 导数

牛顿迭代法的公式为 :

如果f ‘ (xn-1)!=0;那么 xn = xn-1 - f(xn-1)/f ‘ (xn-1);

推导过程为:

假设有函数f(x),使得f(x) = 0;

求此时x的值,在函数上取一点x0,其下一个点值f(x1)比f(x0)更接近与0,这个时候假设x0的值f(x0)趋近f(x)的值,
则可以假设此点的切线斜率为k:

则F(x1)-F(x0) = k(x1-x0).而斜率为f(x0) 的导数f ‘ (x0),而F(x1)=0;

所以:x1= x0 - f(x0)/f ‘ (x0);

示例:求任意一个正数的平方根.

牛顿迭代法则可以视为:求函数f(x) = x2 - N = 0 的解.

java代码如下:

public static double sqrt(double n, double guess) {

if (n > 0 && guess > 0) {

double temp = (guess + n / guess) / 2;

if (temp == guess) {

return temp;

} else {

System.out.println(“the newton computation –” + temp);

return sqrt(n, temp);

}

}

return 0;

}

同样也可以使用二分法来实现求解,代码如下:

public static double bisectionSqrt(double n, double min, double max) {

if (n > 0) {

double mid = (min + max) / 2;

double temp = mid * mid;

if (Math.abs(n - temp) <= 0.000000001) {

return mid;

} else if (temp > n) {

max = mid - 1;

System.out.println(“the bisection computation –” + mid);

return bisectionSqrt(n, min, max);

} else if (temp < n) {

min = mid + 1;

System.out.println(“the bisection computation –” + mid);

return bisectionSqrt(n, min, max);

}

}

return 0;

}

牛顿法在解决问题的效率上远远大于二分法:

public static void main(String args[]) {

System.out.println(sqrt(3, 2));

System.out.println(bisectionSqrt(3, 0, 3));

}

计算结果为:

the newton computation –1.75

the newton computation –1.7321428571428572

the newton computation –1.7320508100147274

the newton computation –1.7320508075688772

1.7320508075688772

the bisection computation –1.5

the bisection computation –2.75

the bisection computation –2.125

the bisection computation –1.8125

the bisection computation –1.65625

the bisection computation –1.734375

the bisection computation –1.6953125

the bisection computation –1.71484375

the bisection computation –1.724609375

the bisection computation –1.7294921875

the bisection computation –1.73193359375

the bisection computation –1.733154296875

the bisection computation –1.7325439453125

the bisection computation –1.73223876953125

the bisection computation –1.732086181640625

the bisection computation –1.7320098876953125

the bisection computation –1.7320480346679688

the bisection computation –1.7320671081542969

the bisection computation –1.7320575714111328

the bisection computation –1.7320528030395508

the bisection computation –1.7320504188537598

the bisection computation –1.7320516109466553

the bisection computation –1.7320510149002075

the bisection computation –1.7320507168769836

the bisection computation –1.7320508658885956

the bisection computation –1.7320507913827896

the bisection computation –1.7320508286356926

the bisection computation –1.732050810009241

the bisection computation –1.7320508006960154

the bisection computation –1.7320508053526282

1.7320508076809347