當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Ruby Newton模塊用法及代碼示例

本文簡要介紹ruby語言中 Newton模塊 的用法。

newton.rb

用牛頓法求解非線性代數方程組 f = 0。該程序不依賴於 BigDecimal

調用:

  n = nlsolve(f,x)
where n is the number of iterations required,
      x is the initial value vector
      f is an Object which is used to compute the values of the equations to be solved.

它必須提供以下方法:

f.values(x)

返回 x 處所有函數的值

f.zero

返回 0.0

f.one

返回 1.0

f.two

返回 2.0

f.ten

返回 10.0

f.eps

返回用於確定兩個值是否相等的收斂標準(epsilon 值)。如果 |a-b| < epsilon,這兩個值被認為是相等的。

退出時,x 是解向量。

相關用法


注:本文由純淨天空篩選整理自ruby-lang.org大神的英文原創作品 Newton模塊。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。