var amount = 0.0d;
var hitTheTargetCount = 0.0d;
var M = 2.0d;
var rnd=new Random();
for (int i = ; i < ; i++)
{
var x = rnd.NextDouble() * Math.PI;
var y = rnd.NextDouble() * M;
//Console.WriteLine("x:{0},y:{1}", x, y);
if (y <= Math.Sin(x))
{
hitTheTargetCount++;
}
amount++;
} var s = (hitTheTargetCount / amount) * M * Math.PI;
Console.WriteLine(s);

以上代码针对 sin(x) 0-pi 进行积分

积分int( sqrt(1-x^2),0,1)

        private void button1_Click(object sender, EventArgs e)
{
var amount = 0.0d;
var hitTheTargetCount = 0.0d;
var M = 1.0d;
var rnd=new Random();
for (int i = ; i < ; i++)
{
var x = rnd.NextDouble() * M;
var y = rnd.NextDouble() * M;
//Console.WriteLine("x:{0},y:{1}", x, y);
if (y <= Math.Sqrt(-Math.Pow(x,)))
{
hitTheTargetCount++;
}
amount++;
} var s = (hitTheTargetCount / amount) * M * M;
Console.WriteLine(s * );
} private void button2_Click(object sender, EventArgs e)
{
Func<double, double> func = (x) => { return (Math.Sqrt( - Math.Pow(x, ))); }; var n = ;
double h = 1.0d / n;
double sumx = ;
double sum = func(0.0); for (int i = ; i < n; i++)
{
sumx += h;
var factor = ((i % ) == ) ? : ;
//Console.WriteLine(i +":" + factor +"," + sumx);
sum += factor * func(sumx);
}
sum += func();
var v = * (sum * h) / ;
Console.WriteLine(v);
}

Monte Carlo 数值积分的更多相关文章

  1. Monte Carlo方法简介(转载)

    Monte Carlo方法简介(转载)       今天向大家介绍一下我现在主要做的这个东东. Monte Carlo方法又称为随机抽样技巧或统计实验方法,属于计算数学的一个分支,它是在上世纪四十年代 ...

  2. 增强学习(四) ----- 蒙特卡罗方法(Monte Carlo Methods)

    1. 蒙特卡罗方法的基本思想 蒙特卡罗方法又叫统计模拟方法,它使用随机数(或伪随机数)来解决计算的问题,是一类重要的数值计算方法.该方法的名字来源于世界著名的赌城蒙特卡罗,而蒙特卡罗方法正是以概率为基 ...

  3. PRML读书会第十一章 Sampling Methods(MCMC, Markov Chain Monte Carlo,细致平稳条件,Metropolis-Hastings,Gibbs Sampling,Slice Sampling,Hamiltonian MCMC)

    主讲人 网络上的尼采 (新浪微博: @Nietzsche_复杂网络机器学习) 网络上的尼采(813394698) 9:05:00  今天的主要内容:Markov Chain Monte Carlo,M ...

  4. Monte Carlo Approximations

    准备总结几篇关于 Markov Chain Monte Carlo 的笔记. 本系列笔记主要译自A Gentle Introduction to Markov Chain Monte Carlo (M ...

  5. (转)Markov Chain Monte Carlo

    Nice R Code Punning code better since 2013 RSS Blog Archives Guides Modules About Markov Chain Monte ...

  6. [其他] 蒙特卡洛(Monte Carlo)模拟手把手教基于EXCEL与Crystal Ball的蒙特卡洛成本模拟过程实例:

    http://www.cqt8.com/soft/html/723.html下载,官网下载 (转帖)1.定义: 蒙特卡洛(Monte Carlo)模拟是一种通过设定随机过程,反复生成时间序列,计算参数 ...

  7. Introduction to Monte Carlo Tree Search (蒙特卡罗搜索树简介)

    Introduction to Monte Carlo Tree Search (蒙特卡罗搜索树简介)  部分翻译自“Monte Carlo Tree Search and Its Applicati ...

  8. (转)Monte Carlo method 蒙特卡洛方法

    转载自:维基百科  蒙特卡洛方法 https://zh.wikipedia.org/wiki/%E8%92%99%E5%9C%B0%E5%8D%A1%E7%BE%85%E6%96%B9%E6%B3%9 ...

  9. Introduction To Monte Carlo Methods

    Introduction To Monte Carlo Methods I’m going to keep this tutorial light on math, because the goal ...

随机推荐

  1. 2016-08-05:samba服务器配置

    centos samba服务器配置 配置smb.conf文件 [share] path = /home/lee writable = yes 添加smb用户 smbpasswd -a root 启动s ...

  2. 通知 Notification

    1. NotificationManager ma=(NotificationManager) context.getSystemService(context.NOTIFICATION_SERVIC ...

  3. apache相关

    http://hw1287789687.iteye.com/blog/2212292 http://enable-cors.org/server_apache.html http://blog.sin ...

  4. 30、shiro框架入门2,关于Realm

    1.Jdbc的Realm链接,并且获取权限 首先创建shiro-jdbc.ini的配置文件,主要配置链接数据库的信息 配置文件中的内容如下所示 1.变量名=全限定类名会自动创建一个类实例 2.变量名. ...

  5. Devexpress VCL Build v2015 vol 15.2 开始测试

    增加了几个小玩意,与大版本变化根本无法匹配. 具体可以官网了解 https://www.devexpress.com/Subscriptions/New-2015.xml?product=vcl

  6. “数学口袋精灵”第二个Sprint计划(第十天)总结

    第二阶段Sprint完成情况: 目标:完成一个小游戏 情况:ui基本完成. 代码基本也完成了,部分未完善. 音乐方面有点小bug,正在完善. 具体运行结果(截图): 首页: 游戏界面(可以计算多个运算 ...

  7. WPF TextBlock文本纵向排列

    一.将TextBlock文本纵向排列输出有两种模式. 1.文字正常放置,只是纵向排列. 2.文字同样旋转90度,纵向排列. 二.详见下文实例 1.文本正常放置,纵向排列. (1)后台代码 string ...

  8. javascript-test1

    var AAA = function(name, age) { this.name = name ; this.age = age; } AAA.prototype.getName = functio ...

  9. 关于 this 和 prototype 的理解

    1:this 的理解比较好的书是 <Javascript语言精粹> 平时我们全局写 var a = 1, 其实就是 window.a = 1; var f = function(){},  ...

  10. CSS背景图拉伸自适应尺寸,全浏览器兼容

    突然有人问我这个问题,说网上CSS filter的方法在非IE浏览器下不奏效.思考之后,问题之外让我感慨万千啊,很多我们所谓的难题,都会随着时代的发展迎刃而解,或被新的问题所取代. 当CSS背景图片拉 ...