标签:des style http io ar color os 使用 sp
本文简要介绍了Newton-Raphson方法及其R语言实现并给出几道练习题供参考使用。 下载PDF格式文档(Academia.edu)
# Example 1
f = function(x){x^5 - 7}
h = 1e - 7
df.dx = function(x){(f(x + h) - f(x)) / h}
df.dx(1); df.dx(2)
# [1] 5.0000009999
# [1] 80.0000078272
app = newton(f, x0 = 2)
app
# [1] 1.68750003057 1.52264459615 1.47857137506 1.47578373325 1.47577316175
# [6] 1.47577316159
f(app[length(app)])
# [1] 1.7763568394e-15
# Example 2
f = function(x){x^5 - 5 * x^4 + 5 * x^2 - 6}
x = c(1 : 5)
f(x)
# [1] -5 -34 -123 -182 119
h = 1e-7
df.dx = function(x){(f(x + h) - f(x)) / h}
df.dx(4); df.dx(5)
# [1] 40.0000163836
# [1] 675.000053008
app = newton(f, x0 = 5)
app
# [1] 4.82370371755 4.79453028339 4.79378501861 4.79378454069 4.79378454069
f(app[length(app)])
# [1] -2.84217094304e-14
# Example 3
f = function(x){4 * x^3 - 50 * x^2 + 136 * x - 100}
x = c(0 : 4)
f(x)
# [1] -100 -10 4 -34 -100
h = 1e-7
df.dx = function(x){(f(x + h) - f(x)) / h}
df.dx(1); df.dx(2); df.dx(3)
# [1] 47.9999962977
# [1] -16.0000024607
# [1] -56.0000012229
app1 = newton(f, x0 = 1)
app2 = newton(f, x0 = 2)
app1; app2
# [1] 1.20833334940 1.25768359879 1.26062673622 1.26063715631 1.26063715644
# [1] 2.24999996155 2.19469026652 2.19192282154 2.19191572132 2.19191572127
f(app1[length(app1)]); f(app2[length(app2)])
# [1] 2.84217094304e-14
# [1] -2.84217094304e-14
标签:des style http io ar color os 使用 sp
原文地址:http://www.cnblogs.com/zhaoyin/p/4125450.html