Matlab'ın bu sayısal üç katlı integraline güvenebilir miyim?


15

Hesaplamalı Bilim insanları:

Ben aslen Matematik Stack Borsası bu soru haberi ve birisi ben "çok daha iyi" cevaplar burada olsun diye yorumladı:

Ben sayısal yöntemler ve Matlab bir acemi değilim. Aşağıdaki iki üç katlı integrallerin toplamını değerlendirmeye çalışıyorum (açıkçası daha basit bir şekilde yazılabilir, ancak yine de sembolik olarak değerlendiremezsiniz (?)). L'yi almakta zorlanıyorum burada çalışmak için, bu yüzden isteksizce burada parçalara ayrıldı: toplamını bulmak istiyorumLATEX

2((1/0.3)1)2(11/0.31r10r1r0F1(r0,r1,t)exp((0.3)2t24)dtdr0dr1),

ve

2((1/0.3)-1)2(11/0.31r1r1-r0r1+r0F2(r0,r1,t)tecrübe(-(0.3)2t24)dtdr0dr1),

nerede

F1(r0,r1,t)=t2r03(0.3)32r13π

ve

F2(r0,r1,t)=(0.3)3π3/2(r0+r1t)4(t2+2t(r0+r1)3(r1r0)2)2288(43πr03)(43πr13).

EDIT (2 Mart 2013): Birisi integralleri sembolik olarak yapmak için Mathematica'ya sahip olduklarını söyledi. Sadece bunu yapmaya çalıştım (integrallerin basitleştirilmiş sürümleriyle) ve Mathematica sadece ilkinin dış ikisini yapabilir ve ikincisinde durdu. Biraz yardım isterim. İşte yaptığım şey:

Değerlendirmeye çalıştım

ile

121r20r2r1r13t2exp(t2)r23dtdr1dr2

[R1 ^ 3 / r2 ^ 3 * t ^ 2 * Exp (-t ^ 2), {t, 0, r2 - r1}, {r1, 1, r2}, {r2, 1, 2}]

ve Mathematica geri dönüyor ( L ile sorun yaşadım burada, çünkü sonuç uzun. İki denkleme ayırdım. Herkes bunu görüntülemek için iyi bir yol biliyorsa lütfen söyle):LATEX

12164r22e1r22(2e2r2(25+r2(19+2r2(1+r2)))

e1+r22(32r2(2+r22))+π(11+4r22(9+r22))Erf[1r2])dr2.

Sonra değerlendirmeye çalıştım

121r2r2r1r2+r1

exp(t2)(r1+r2t)4(t2+2t(r1+r2)3(r2r1)2)2r13r23dtdrdr2

using

Integrate[(r1 + r2 - t)^4*(t^2 + 2*t*(r1 + r2) - 3*(r2 - r1)^2)^2* Exp[-t^2]/r1^3/r2^3, {r2, 1, 2}, {r1, 1, r2}, {t, r2-r1, r2 + r1}]

just now, and Mathematica has not returned an answer after about half an hour (but I am having computer network problems right now, and they may be to blame).

[END OF MARCH 2 EDIT]

I used Matlab's "triplequad" command, with no extra options. I handled the variable limits of integration by means of heaviside functions, because I didn't know any other way to do it. Matlab gave me 0.007164820144202.

I know Matlab is good software, but I have heard that numerical triple integrals are hard to do accurately, and mathematicians are supposed to be skeptical, so I want some way to verify the accuracy of this answer. The integrals give the expected value of a certain experiment (if anyone wants, I can edit this question to describe the experiment): I implemented the experiment in Matlab using appropriately randomly generated numbers, a million times, and averaged the results. I repeated this process four times. Here are the results (I apologize if I have used the word "trial" improperly):

Trial 1: 0.007133292603256

Trial 2: 0.007120455071989

Trial 3: 0.007062595022049

Trial 4: 0.007154940168452

Trial 5: 0.007215000289130

Although each trial used a million samples, the simulation values only agree in the first significant digit. They are not close enough to each to each other for me to determine whether the numerical triple integral is accurate.

So can anyone tell me whether I can trust the result of "triplequad" here, and under what circumstances one can trust it in general?

One suggestion I got at Math Stack Exchange was to try other software like Mathematica, Octave, Maple, and SciPy. Is this good advice? Do people actually do numerical work in Mathematica and Maple? Octave is kind of a Matlab clone, so can I assume it uses the same integration algorithms? I haven't even heard of SciPy before and would appreciate any opinions about it.


UPDATE: Someone from Math Stack Exchange did it in Maple and got 0.007163085468. That is agreement to three significant figures. That is a good sign.

Also, I would appreciate suggestions on how to enter long, multi-line expression in LATEX in Stack Exchange. Can you use the "aligned" environment here? I tried, and I couldn't get it to work.


2
Your simulation results are perfectly consistent with the numerical value returned by Matlab: their mean of 0.00713726 is just 1.11 standard errors less than what Matlab returned. FWIW, Mathematica returns 0.00716308537. It can also evaluate these integrals symbolically in terms of polynomials and error functions.
whuber

@whuber Thanks. I could swear I tried it symbolically in Maple and Maple couldn't do it. I'll try again in Maple, and if it doesn't work, I'll try it in Mathematica. BTW, I did a similar integral in Maple, and I got a huge symbolic answer. It appeared to be a sum and difference of very large numbers whose grand total was quite small. I suspect roundoff error was likely in the final answer. In a problem like this, should you use the symbolic answer, or just do the integral numerically?
Stefan Smith

Symbolic answers have the advantage of being combinations of functions that (often) can efficiently be computed to arbitrary precision. Usually, too, the symbolic solution also lends itself to rapid recomputation when parameters are varied. For these reasons it's often worthwhile to seek a symbolic solution.
whuber

@whuber :I tried doing some essentially equivalent integrals (changing some of the constants and removing some multiplicative constants) in Mathematica, and Mathematica could only do the outer two integrations of the first integral, and seems to have stalled on the second one. I posted my code and results above.
Stefan Smith

1
Re The March 2 edit: By reducing the triple integral symbolically to a single integral (in the first half of your integrals) you have accomplished a lot. The integrand is very nicely behaved and can be numerically integrated to extremely high precision within a fraction of a second.
whuber

Yanıtlar:


9

First of all, it is not the software (or at least it shouldn't be) that determines the quality of the solution to a problem, it's the quality and appropriateness of the algorithm that is applied. You should check what algorithm is being used by triplequad in Matlab (I would guess it uses a nested adaptive Gaussian quadrature). And you should check what the requested tolerances are (required absolute and relative tolerance). Chances are that, by default, it only asks for 108 relative precision.

The answer coming from Maple is probably done by Computer Algebra and maybe it could find a closed solution which was then evaluated using double precision floating point. This has the advantage that you are not approximating the integral by a finite summation (and hence are introducing approximation errors) but the Computer Algebra System will find an expression for the integral which can then be evaluated. Of course, care must be taken when evaluating this expression (for round-off).

If you would want to do this with SciPy, you would also need to resort to nested adaptive Gaussian quadrature using the underlying Quadpack (Piessens et al.) routines. In Octave, you'll have the same approach. And I wouldn't be too surprised if Matlab also uses Quadpack as quadrature engine (since it is the reference).


@GretVdE : Thanks for the info. I tried evaluating the integral symbolically first, and Maple couldn't do it (so it was probably impossible, using standard functions), so I asked Maple to do it numerically. I don't know what algorithm it used.
Stefan Smith

@StefanSmith: Maple: içindeki infolevel'i ayarlayarak öğrenebilirsiniz infolevel[`evalf/int`] := 4. Mape'nin kapalı bir çözüm bulamadığından emin misiniz? İntegral çok karmaşık görünmüyor. Maple sayfanızı bir yerde herkese açık hale getirir misiniz?
GertVdE

@StefanSmith: Maple kodunu yukarıdaki soruya gönderirdim.
GertVdE

Maple'ı şu anda sistemim üzerinde çalıştıramıyorum, ancak Mathematica'da eşdeğer integralleri denedim ve Mathematica sadece ilk üç katlı integralin sadece iç ikisini yaptı ve ikinci üç katlı integralin üzerinde durdu. Lütfen düzenlenen soruya bakın.
Stefan Smith
Sitemizi kullandığınızda şunları okuyup anladığınızı kabul etmiş olursunuz: Çerez Politikası ve Gizlilik Politikası.
Licensed under cc by-sa 3.0 with attribution required.