我試圖將牛頓公式應用於長度n = 500的一些反抽樣方法。 (u均勻隨機數,Fphi_x我們根據分佈,fphi_x我們的密度)。 牛頓式則是:求x,使得Fphi_x(X)-u = 0積分大概根據小數位不同
`u=runif(500)
xnewton=rep(1e-30,500)
fphi_x=function(x){return(0.307/(x^{5/12}*(x+1)))}
Fphi_x=function(u){k=integrate(fphi_x,0,u)$value
return(k)}
for(i in 1:500)
{
while(abs(Fphi_x(xnewton[i])-u[i])>0.0000001){
xnewton[i]=xnewton[i]-(Fphi_x(xnewton[i])-u[i])/fphi_x(xnewton[i])
}
}`
的代碼是正確。但我得到的錯誤代碼: Error in integrate(fphi_x, 0, u) : the integral is probably divergent.
我發現:
Fphi_x(1e15)=1.197390096030634e-05
,但如果我有它的小數;例如 Fphi_x(10000000000.000000)
我收到錯誤消息。 根據我的分佈,我將確保獲得高數字,並帶有小數位。 431232.132131。如何解決這個問題? 致以問候
謝謝。這效果很好! – ziT