fengshenyijiu的个人博客分享 http://blog.sciencenet.cn/u/fengshenyijiu

博文

蒙特卡罗学习之利用python通过蒲丰投针计算π的值

已有 2419 次阅读 2021-10-11 09:17 |个人分类:蒙卡|系统分类:科研笔记

图片.png

以下为python实现随机实验过程的代码

math
random
numpy np
tqdm tqdm
D=L=exp_num=Lambda=touch_num=sum2=sum3=i tqdm((exp_num)):
    x = D/*random.random()
    theta = math.pi*random.random()
    x <=(L/)*math.sin(theta):
        touch_num+=P = touch_num / exp_num
        pi_stand = * L / (D * P)
        sum2 += pi_stand** sum3 += pi_stand
sigma = math.sqrt(/exp_num*sum2-(/exp_num*sum3)**)
Epsilon = *sigma /math.sqrt(exp_num)
(exp_num)
()
(.format(pi_stand))
(.format(Epsilon))

      



https://blog.sciencenet.cn/blog-3489976-1307507.html


下一篇:在win10下利用DOS批量提交同文件夹内所有gif输入卡至Gaussian 09
收藏 IP: 49.5.15.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-26 20:02

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部