Why is triplequad not recommended? In my case it works better than integral3
1 回表示 (過去 30 日間)
古いコメントを表示
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)
triplequad(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L)
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 件のコメント
Walter Roberson
2023 年 9 月 22 日
% 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')
triplequad(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L)
Walter Roberson
2023 年 9 月 22 日
% 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)
double(III)
triplequad(@(alpha,x,x2) P_53(alpha,x).*V_34_dif(x,x2).*V_30(x2), 0, alpha_separativo, 0, L, 0, L)
回答 (2 件)
Sulaymon Eshkabilov
2023 年 9 月 22 日
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)
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)
0 件のコメント
Walter Roberson
2023 年 9 月 22 日
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.
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.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Calculus についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!