蒙特卡罗方法模拟计算圆周率

2014-07-28 00:14:42彭滔魏雷阳
电脑知识与技术 2014年17期

彭滔 魏雷阳

摘要:蒙特卡罗方法是一种新型计算方法,它需要真实的随机数,在统计学方面有强有力的应用,随着高性能计算机变得越来越便宜,此方面变得愈发普遍,该文通过设计一个随机试验,建立pi值与试验次数的联系方程,使用R语言来模拟计算PI值。

关键词:蒙特卡罗方法;随机模拟;R语言

中图分类号:TP311 文献标识码:A 文章编号:1009-3044(2014)17-4038-02

A New Way to Compute Simulately PI with Monte Carlo Method in R Language

PENG Tao, WEI Lei-yang

(Sanya Polythenic College, Sanya 572022, China)

Abstract: Monte Carlo methods is a new way of computational algorithms, basically Monte Carlo simulation methods require truly random numbers , Monte Carlo is a powerful numerical technique useful for solving problems especially in statistics. When high-speed computers becomes cheap,the method has gained in importance and popularity,when a circle with its bounding square is drawn,let randomly generate a point in the squre, the probability that the point falls in the circle is circle area /square area = PI/4,we can get pi from the equation.We finish the stochastic simulation with R language in the article.

Key words: Monte Carlo methods; stochastic simulation; R languange

1 蒙特卡罗方法简介

蒙特卡罗方法是一种随机模拟方法,以概率和统计理论方法为基础,使用随机数(或更常见的伪随机数)来解决计算问题的方法。其早期的雏形存在于17-18世纪,1777年法国数学家普丰(Georges Louis Leclere de Buffon,1707—1788)提出用投针实验的方法求圆周率π,统计史上称为普丰投针问题。

在平面上画有一组间距为a的平行线,将一根长度为l(l

p=2l/(πa) π为圆周率。

几个世纪以来,先后有无数人重复了这个试验,比较有名气的试验见下表。

该方法的简要步骤概括如下:

1)根据概率论或统计理论建立一个数学模型(方程、等式或不等式)

2)以人工试验的方法进行大量的重复工作,记录每次试验的结果

3)利用概率的统计定义,归纳全部试验结果,从已经建立的模型中,解出研究对象的数值。

由于该方法涉及大量的手工试验,在计算机技术没有发展之前,缺乏推广,导致使用受限。

20世纪40年代美国在第二次世界大战中,为了研制原子弹,力推“曼哈顿计划”,该计算的成员S.M.乌拉姆和J.冯·诺伊曼结合当时已有的计算技术,重新推出这种统计模拟计算方法,他们以驰名世界的赌城—摩纳哥的Monte Carlo—来命名这种方法,蒙特卡罗方法。……

登录APP查看全文