在Mathematica中进行整合 [英] Integration in Mathematica

查看:96
本文介绍了在Mathematica中进行整合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过一些模拟,我想以一种象征性的"方式解决我已经解决的问题的另一种解决方案.现在,我想知道如何使用Mathematica直接获得集成.

I would like to get a different solution to a problem I have solved "symbolically" and through a little simulation. Now, I would like to know how could I have got the integration directly using Mathematica.

请考虑一个以r = 1的圆盘表示的目标,中心为(0,0).我想模拟一下我击中该目标投掷飞镖的概率.

Please consider a target represented by a disk with r = 1, centered at (0,0).I want to do a simulation of my probability to hit this target throwing darts.

现在,我没有偏见,平均来说,我将击中mu = 0,但我的方差是1.

Now, I have no biases throwing them, that is on average I shall hit the center mu = 0 but my variance is 1.

考虑到我的飞镖击中目标(或墙壁:-)时的坐标,我有以下分布,2个高斯分布:

Considering the coordinate of my dart as it hit the target (or the wall :-) ) I have the following distributions, 2 Gaussians:

XDistribution : 1/Sqrt[2 \[Pi]\[Sigma]^2] E^(-x^2/(2 \[Sigma]^2))

YDistribution : 1/Sqrt[2 \[Pi]\[Sigma]^2] E^(-y^2/(2 \[Sigma]^2))

当2个分布以0为中心且方差等于= 1时,我的联合分布变为二元高斯分布,例如:

With those 2 distribution centered at 0 with equal variance =1 , my joint distribution becomes a bivariate Gaussian such as :

1/(2 \[Pi]\[Sigma]^2) E^(-((x^2 + y^2)/(2 \[Sigma]^2)))

所以我需要知道我击中目标的概率或x ^ 2 + y ^ 2小于1的概率.

So I need to know my probability to hit the target or the probability of x^2 + y^2 to be inferior to 1.

在极坐标系中进行转换后的积分首先给了我我的解决方案:.39.仿真使用以下命令确认了这一点:

An integration after a transformation in a polar coordinate system gave me first my solution : .39 . Simulation confirmed it using :

Total@ParallelTable[
   If[
      EuclideanDistance[{
                         RandomVariate[NormalDistribution[0, Sqrt[1]]], 
                         RandomVariate[NormalDistribution[0, Sqrt[1]]]
                        }, {0, 0}] < 1, 1,0], {1000000}]/1000000

我认为,利用Mathematica的集成功能,可以找到一种更优雅的方式来解决此问题,但是从来没有映射过以太坊.

I feel there were more elegant way to solve this problem using the integration capacities of Mathematica, but never got to map ether work.

推荐答案

实际上有几种方法可以执行此操作.

There are actually several ways you can do this.

最简单的方法是将NIntegrate用作:

The simplest would be to use NIntegrate as:

JointDistrbution = 1/(2 \[Pi] \[Sigma]^2) E^(-((x^2 + y^2)/(2 \[Sigma]^2)));
NIntegrate[JointDistrbution /. \[Sigma] -> 1, {y, -1, 1}, 
    {x, -Sqrt[1 - y^2], Sqrt[1 - y^2]}] // Timing

Out[1]= {0.009625, 0.393469}

这是另一种凭经验进行操作的方法(类似于上面的示例),但是比使用NIntegrate慢得多:

This is another way to do it empirically (similar to your example above), but a lot slower than using NIntegrate:

(EuclideanDistance[#, {0, 0}] <= 1 & /@ # // Boole // Total)/
     Length@# &@RandomVariate[NormalDistribution[0, 1], {10^6, 2}] // 
  N // Timing

Out[2]= {5.03216, 0.39281}

这篇关于在Mathematica中进行整合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆