我正在嘗試在R中實現這個方程到非線性求解器中最困難的時候。我正在嘗試nleqslv
和BB
程序包,但到目前爲止只能得到錯誤。我已經搜索並閱讀文檔,直到我的眼睛流血,但我無法將我的大腦包裹在它周圍。公式本身是這樣的:包含求和的非線性方程R
s2 * sum(price^(2*x+2)) - s2.bar * sum(price^(2*x)) = 0
凡s2
,s2.bar
,和price
是已知的相等長度的向量。
我BB
嘗試的最後一次嘗試是這樣的:
gamma = function(x){
n = len(x)
f = numeric(n)
f[n] = s2*sum(price^(2*x[n]+2)) - s2.bar*sum(price^(2*x[n]))
f
}
g0 = rnorm(length(price))
results = BBsolve(par=g0, fn=gamma)
任何幫助是極大的讚賞
f [n]是一個矢量的一個元素,但是你試圖給它分配一個長度等於長度(s2)的整個矢量。你的意思是使用s2 [n]和s2.bar [n]而不是s2和s2.bar?價格不會引起問題,因爲您在指數後對整個向量進行求和。 – psychometriko
讓我再試一次: 我可能會從一開始就錯了。我試圖解決的實際公式是這樣的: http://i1330.photobucket.com/albums/w561/lompoc421/CodeCogsEqn%201_zpsrwocvotk.gif – Lompoc42