【问题标题】:Newton-raphson function in R (ELI5)R (ELI5) 中的 Newton-raphson 函数
【发布时间】:2021-03-12 02:15:18
【问题描述】:

是否需要一些时间来逐行向我解释这个函数如何使用牛顿拉夫森方法计算函数的根?以及 r 代码是如何执行的。 特别是返回部分?

newton <- function(f, delta = 0.0000001, x_0 = 2, n=1000){
  h = 0.0000001
  i = 1; x1 = x_0
  p = numeric(n)
  while (i <= n) { 
    df.dx = (f(x_0 + h) - f(x_0)) / h
    x1 = (x_0 - (f(x_0) / df.dx)) 
    p[i] = x1 
    i = i+1 
    if (abs(x1 - x_0) < delta) break 
    x_0 = x1
  }
  return(p[1: (i-1)]) #
}

目前我已经定义了这样的变量,但我不确定它是否正确:

f = the function we input
delta = the accuracy threashold we are willing to accept
x_0 = our initial guess
n = the number of iterations
h = the distance from original guess to true root
abs = the current value of the function

感谢一百万的任何帮助!

【问题讨论】:

标签: r function math


【解决方案1】:

逻辑是找到[function f(x) = 0]的根。但是当这个函数是高阶时我们不能立即解根,所以我们使用程序1000(n)来猜测哪个最接近根.有时这个函数是连续可微的,但有时不是,所以如果我们发现p[]数据收敛到一个准确数,我们就得到根,否则不。

f = the function we input (Y)
delta = the accuracy threashold we are willing to accept (Y)
x_0 = our initial guess (Y)
n = the number of iterations (Y)
h = the distance from original guess to true root (N) 
h = the distance from X1 to X0,this value much little ,the root much closed.
abs = the current value of the function (N)
abs is a sys

【讨论】:

  • 啊,我知道那里有一些误解。谢谢大佬!
猜你喜欢
  • 2013-03-06
  • 1970-01-01
  • 2014-10-10
  • 2015-05-08
  • 1970-01-01
  • 2018-07-16
  • 2016-02-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多