Info

1 view (last 30 days)
meryem on 12 Dec 2014
Closed: MATLAB Answer Bot on 20 Aug 2021
Hi! I have a question on the quad2d function. When I run the code below ,it returns Q= 7.1754e-045. But it must be approximately 4.7399 e-043 . There is very little difference but it is very important for my project. When I decrease the value of 'AbsTol' ( for example 1e-85), it returns 4.867 e-043 but the code runs very slowly. I need another way to be fast and approximately 4.7399 e-043. Possible ?
fun = @(b,a) (b ./a).^19.* exp(-(439 ./ a).^b) .* ((439 ./ a).^(b-1)) ... .* 1./a .* 1./69.5391;
Geoff Hayes on 12 Dec 2014
Meryem - when I run the above code (R2014a, OS X 10.85) Q is 2.78617970352069e-21. Why is it necessary that your result be closer to 4.7399e-043? Please also elaborate on what you mean by the code runs very slowly - does this mean that it takes seconds, minutes, hours? Also, please indicate which version of MATLAB that you are using and the OS.

Mike Hosea on 13 Dec 2014
Is there a typo somewhere above? Here's a script I called "doit.m":
format short g
fun = @(b,a) (b ./a).^19.* exp(-(439 ./ a).^b) .* ((439 ./ a).^(b-1)) .* 1./a .* 1./69.5391;
tic;
toc
tic;
toc
tic;
QIterated = integral2(fun,6.00018,75.5392,248.063,1573.73,'RelTol',100*eps,'AbsTol',1e-50,'method','iterated')
toc
tic;
QTiled = integral2(fun,6.00018,75.5392,248.063,1573.73,'RelTol',100*eps,'AbsTol',1e-50,'method','tiled')
toc
% Break the region up into n^2 pieces and integrate over each piece.
n = 30;
x = linspace(6.00018,75.5392,n);
y = linspace(248.063,1573.73,n);
Q = 0;
for i = 1:numel(x)-1
for j = 1:numel(y)-1
Q = Q + integral2(fun,x(i),x(i+1),y(j),y(j+1),'RelTol',100*eps,'AbsTol',1e-50,'method','iterated');
end
end
QMIterated = Q
Q = 0;
for i = 1:numel(x)-1
for j = 1:numel(y)-1
Q = Q + integral2(fun,x(i),x(i+1),y(j),y(j+1),'RelTol',100*eps,'AbsTol',1e-50,'method','tiled');
end
end
QMTiled = Q
ULPs = (Max - Min)/eps(Max)
>> doit
2.0639e-18
Elapsed time is 0.763301 seconds.
2.0639e-18
Elapsed time is 1.608291 seconds.
QIterated =
2.0639e-18
Elapsed time is 0.519476 seconds.
QTiled =
2.0639e-18
Elapsed time is 1.408459 seconds.
QMIterated =
2.0639e-18
QMTiled =
2.0639e-18