我目前正在嘗試實作一個近似 f(x) = 0 的數學方法。我已經用一些語言實作了它,我現在想用 ruby?? 來做它只是為了訓練。但是我有這個我真的不明白的錯誤這是我的代碼
def fonction (x)
return (x ** 3) 4 * (x ** 2) - 10
end
def derive (x)
return 3 * (x ** 2) 8 * x
end
def newton(f, fPrime, n, u0)
if n == 0 then
return u0
else
uN = newton (f, fPrime, (n - 1), u0)
return uN - f(uN) / fPrime(uN)
end
end
for i in 0..6
puts (newton (fonction, derive, i, 2))
end
uj5u.com熱心網友回復:
我認為牛頓方法呼叫有空間
uN = newton (f, fPrime, (n - 1), u0) # there is space after newton
也在這個
for i in 0..6
puts (newton (fonction, derive, i, 2)) # there is space after newton
end
嘗試洗掉它,我猜你會看到另一個錯誤,我在 repl 上試試
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/428044.html
