MMA如何得到二重数值积分权重?
mathematica吧
全部回复
仅看楼主
level 1
sss668800 楼主
如题,我需要把一个数值积分写成对积分变量求和的形式(积分的本质也是求和),对一个变量的数值积分,我看到帖子讨论了NIntegrate`GaussRuleData或者"NumericalDifferentialEquationAnalysis`"包的GaussianQuadratureWeights,里面可以直接得到横坐标和权重。
但是二重积分怎么得到权重?
2018年04月23日 03点04分 1
level 1
sss668800 楼主
单变量积分代码如下:
xt = 3.7; yt = 1.3;
a = 0.5; b = 1; M = 50; pr = 20;
tt[\[Alpha]_] :=
Exp[-(\[Alpha]^2/4)] Exp[I (\[Alpha] xt + Sqrt[1 - \[Alpha]^2] yt)]
GaussQ1[f_, {x_, a_, b_}, n_Integer: 10, prec_: MachinePrecision] :=
Module[{nodes, weights}, {nodes, weights} =
Most[NIntegrate`GaussRuleData[n, prec]];
(b - a) weights.Map[Function[x, f], Rescale[nodes, {0, 1}, {a, b}]]]
GaussQ1[tt[x], {x, a, b}, M, pr]
NIntegrate[tt[x], {x, a, b}]
可以验证二者是相等的
2018年04月23日 03点04分 2
level 1
sss668800 楼主
自己问的自己来回答一下:
MMA在tutorial/NIntegrateIntegrationRules/"CartesianRule"里面有介绍,以二重高斯积分为例:
crule = NIntegrate`CartesianRuleData[{{"GaussKronrodRule",
"GaussPoints" -> nt}, {"GaussKronrodRule", "GaussPoints" -> nt}},
MachinePrecision]
pf = MapAt[Flatten[Outer[Times, Sequence @@#]] &, #, {1, 3}] &@
MapAt[Flatten[Outer[Times, Sequence @@ #]] &, #, {1, 2}] &@
MapAt[Flatten[Outer[List, Sequence @@
#], Length[#
] - 1] &, #, {1,
1}] &;
p0 = pf[crule][[1]]
分别得到横纵坐标+权重+误差
这个方法有个问题,每次积分"GaussKronrodRule"选nt点对应2nt+1个点,因此一共有(2nt+1)^2个点,如果积分维度高了,就非常困难了。
2018年04月24日 14点04分 3
所以Mathematica高维好像都是默认用蒙特卡洛法的……
2018年05月05日 05点05分
@xzcyr 多谢版主回复,蒙卡不提供采样点和权重,而是一个数值逼近的过程,无法用于我所需要的情况。。。
2018年05月06日 01点05分
1