全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
2628 2
2016-03-27
theta <- .5
iter=2
hattheta=c()
while ((hattheta[iter]-hattheta[iter-1])^2>10^(-2)){
        hattheta[1]<-theta
        hattheta[iter]=(159*hattheta[iter-1]+68)/(197*hattheta[iter-1]+144)
        print(hattheta)
        iter=iter+1

}

显示错误
Error in while ((hattheta[iter] - hattheta[iter - 1])^2 > 10^(-2)) { :
  参数长度为零

迭代公式为:

\[]\theta^{t+1}=\frac{159\theta^{t}+68}{197\theta^{t}+144}\]

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2016-3-27 11:18:52
仔细体会一下代码的运行,你的while循环走不下去啊。
复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-3-27 11:33:43
jiangbeilu 发表于 2016-3-27 11:18
仔细体会一下代码的运行,你的while循环走不下去啊。
但这样出来的迭代结果有问题0.6082474

hattheta
[1] 0.5000000 0.6082474 0.6243211 0.6264889 0.6267773 0.6268156 0.6268207
[8] 0.6268214 0.6268215 0.6268215 0.6268215 0.6268215 0.6268215 0.6268215
[15] 0.6268215 0.6268215 0.6268215 0.6268215 0.6268215 0.6268215 0.6268215
>
这是我用for做20次循环做出来的可以看出稳定在0.628215
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群