两个Transformed-前缀的mathematica函数

来源:互联网 发布:在线财神网淘宝店 编辑:程序博客网 时间:2024/06/06 08:57

一个是TransformedField,坐标转换;另一个TransformedDistribution,随机变量分布的变换。

随机变量的变换

之前提到过,随机变量的复合变换,一般情况下通过求变换的反函数,求雅克比矩阵及其行列式,必要的情况下再求边际分布。

举个简单例子,有人在微博上讨论,正态分布的随机变量和均匀分布的随机变量相乘之后得到的新随机变量,是否服从正态分布?

因为随机变量复合之后大部分新的变量的分布或分布密度函数形式复杂,逐步计算相当繁琐,TransformedDistribution集成并自动化了这些繁琐的计算。

举个例子,标准正态分布和[0,1]上均匀分布的成绩的分布密度,很容易用mathematica代码得到:

PDF[TransformedDistribution[ u*v, {u \[Distributed] NormalDistribution[],  v \[Distributed] UniformDistribution[]}], x]

其公式为:

Γ(0,x22)22π=122πx22dttet

绘出图像:

Plot[Gamma[0, x^2/2]/(2 Sqrt[2 \[Pi]]), {x, -3, 3}, PlotRange -> Full, PlotStyle -> Red, Filling -> 0, FillingStyle -> Directive[Opacity[.5], Magenta],  AxesStyle -> {{Arrowheads[.035],  Directive[Black, 12]}, {Arrowheads[.035], Directive[Black, 12]}},  AxesOrigin -> {-3, -1}, Axes -> {True, True}]

这里写图片描述

显然不是正态分布。

场的变换

有些公式,在球面坐标下表达很方便,直角坐标则不知所云。
比如下面残缺部分的表达:

RegionPlot3D[ 2 > Sqrt[x^2 + y^2 + z^2] > 1 &&   Pi/2 > ArcTan[z, Sqrt[x^2 + y^2]] > 0 && \[Pi]/2 > ArcTan[x, y] >    0, {x, -2, 2}, {y, -2, 2}, {z, -2, 2}, PlotPoints -> 100,  Mesh -> None]

这里写图片描述
RegionPlot3D只支持直角坐标,转换为直角坐标用TransformedField就很方便。

球坐标下: 1<r<2,0<θ<π/2,0<ψ<π/2

用代码:

TransformedField["Spherical" -> "Cartesian",  1 < r < 2 && 0 < \[Theta] < Pi/2 &&   0 < \[Psi] < Pi/2, {r, \[Theta], \[Psi]} -> {x, y, z}]

容易得到:

1 < Sqrt[x^2 + y^2 + z^2] < 2 &&  0 < ArcTan[z, Sqrt[x^2 + y^2]] < \[Pi]/2 &&  0 < ArcTan[x, y] < \[Pi]/2

即:
1<x2+y2+z2<20<tan1(z,x2+y2)<π20<tan1(x,y)<π2