Effacer les filtres
Effacer les filtres

Why is triplequad not recommended? In my case it works better than integral3

1 vue (au cours des 30 derniers jours)
Diogo
Diogo le 22 Sep 2023
Hi, I have the following code:
% variables
D = 1;
alpha_laser = 5*pi/180;
L = 10;
A = 0.1;
o = A/2/tan(alpha_laser);
alpha_separativo = atan(D/2/(o+L));
% Elementary functions
h = @(alpha) (o+L)*tan(alpha);
P_53 = @(alpha, x) -1./2*1./sqrt(1+((h(alpha)-D./2)./(L-x)).^2).*(h(alpha)-D./2)./((L-x).^2+(h(alpha)-D./2).^2);
V_34_dif = @(x,x2) 1./2*1./sqrt(1+((x2-x)./D).^2).*D./(D.^2+(x2-x).^2);
V_30 = @(x) 1./2*(1./sqrt(1+((D-A)./(2.*x)).^2)-1./sqrt(1+((D+A)./(2.*x)).^2));
% Integration
integral3(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L)
Warning: Reached the maximum number of function evaluations (10000). The result fails the global error test.
Warning: The integration was unsuccessful.
ans = NaN
triplequad(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L)
ans = 8.8012e-05
As presented above, integral3 fails to calculate my integral whereas triplequad does it easily. My question is regarding if the reason triplequad is not recommended is for some reason such that I should not trust the value it gives back to me.
Moreover, in my code I have a lot of similar integrals to this one (this case specifically was the only which gave me trouble with integral3 and, thus, I found triplequad). The integral boundaries are always constant i.e. they never depend on any integration variable. Should I, therefore, prioritize triplequad and quad2d over integral3 and integral2, since the integration domain is always a rectangular form? Thanks in advance :)
  2 commentaires
Walter Roberson
Walter Roberson le 22 Sep 2023
% variables
D = 1;
alpha_laser = 5*pi/180;
L = 10;
A = 0.1;
o = A/2/tan(alpha_laser);
alpha_separativo = atan(D/2/(o+L));
% Elementary functions
h = @(alpha) (o+L)*tan(alpha);
P_53 = @(alpha, x) -1./2*1./sqrt(1+((h(alpha)-D./2)./(L-x)).^2).*(h(alpha)-D./2)./((L-x).^2+(h(alpha)-D./2).^2);
V_34_dif = @(x,x2) 1./2*1./sqrt(1+((x2-x)./D).^2).*D./(D.^2+(x2-x).^2);
V_30 = @(x) 1./2*(1./sqrt(1+((D-A)./(2.*x)).^2)-1./sqrt(1+((D+A)./(2.*x)).^2));
% Integration
integral3(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L, 'method', 'iterated')
ans = 9.5538e-06
triplequad(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L)
ans = 7.6805e-06
Walter Roberson
Walter Roberson le 22 Sep 2023
% variables
D = 1;
alpha_laser = 5*pi/180;
L = 10;
A = 0.1;
o = A/2/tan(alpha_laser);
alpha_separativo = atan(D/2/(o+L));
% Elementary functions
h = @(alpha) (o+L)*tan(alpha);
P_53 = @(alpha, x) -1./2*1./sqrt(1+((h(alpha)-D./2)./(L-x)).^2).*(h(alpha)-D./2)./((L-x).^2+(h(alpha)-D./2).^2);
V_34_dif = @(x,x2) 1./2*1./sqrt(1+((x2-x)./D).^2).*D./(D.^2+(x2-x).^2);
V_30 = @(x) 1./2*(1./sqrt(1+((D-A)./(2.*x)).^2)-1./sqrt(1+((D+A)./(2.*x)).^2));
syms alpha x x2
% Integration
III = vpaintegral(vpaintegral(vpaintegral( P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), alpha, 0, alpha_separativo), x, 0, L), x2, 0, L)
III = 
0.00000955377
double(III)
ans = 9.5538e-06
triplequad(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L)
ans = 7.6805e-06

Connectez-vous pour commenter.

Réponses (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov le 22 Sep 2023
Adjust absolute and relative tolerances for integral3 and you will get the resul for integral3 as well:
% variables
D = 1;
alpha_laser = 5*pi/180;
L = 10;
A = 0.1;
o = A/2/tan(alpha_laser);
alpha_separativo = atan(D/2/(o+L));
% Elementary functions
h = @(alpha) (o+L)*tan(alpha);
P_53 = @(alpha, x) -1./2*1./sqrt(1+((h(alpha)-D./2)./(L-x)).^2).*(h(alpha)-D./2)./((L-x).^2+(h(alpha)-D./2).^2);
V_34_dif = @(x,x2) 1./2*1./sqrt(1+((x2-x)./D).^2).*D./(D.^2+(x2-x).^2);
V_30 = @(x) 1./2*(1./sqrt(1+((D-A)./(2.*x)).^2)-1./sqrt(1+((D+A)./(2.*x)).^2));
% Integration
IN3 = integral3(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L, 'AbsTol', 1e-7,'RelTol',1e-5)
IN3 = 9.5537e-06
TQ3 = triplequad(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L, 1e-7)
TQ3 = 7.6805e-06

Walter Roberson
Walter Roberson le 22 Sep 2023
triplequad invokes dblquad which invokes quad .
Because quad() requires that the limits are finite, then dlbquad() and triplequad() require that the limits are finite.
The limits for triplequad() and doublequad() must be constants.
Any of the limits for integral3 may be infinite.
The limits for the first variable for integral3() must be constants, but the limits for the other two variables may be function handles.
integral3() is therefore more flexible than triplequad(), and the less flexible function is no longer recommended.

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by