我正在尝试在Matlab中进行第四阶嵌套集成。功能如下:
second_integral = @(r_dash, phi_dash, r, phi) ( (exp(-1i * k * r_dash * cos(phi_dash) * sin(theta)) .* exp(-1i * k * sqrt(r.^2 + r_dash.^2 - 2*( r * r_dash .* cos (phi_dash - phi))))) / (2 .* pi .* sqrt(r.^2 + r_dash.^2 - 2.*( r .* r_dash .* cos (phi_dash - phi))) ) );
这个特定例子中的常量是:
a_1 = 7e-5;
a_2 = 5e-5;
k = 1;
theta = 0; % can also be 0.5, 1, 1.5
整合正在进行中
integrated_second_integral =integral(@(r_dash)integral3(@(phi_dash,r,phi)second_integral(r_dash,phi_dash,r,phi),0,(2*pi),0,a_2,0,(2*pi)),0,a_1,'ArrayValued',true);
运行集成命令时,出现以下错误:
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND = 2.725290e-19.
> In @(r_dash,phi_dash,r,phi)((exp(-1i*k*r_dash*cos(phi_dash)*sin(theta)).*exp(-1i*k*sqrt(r.^2+r_dash.^2-2*(r*r_dash.*cos(phi_dash-phi)))))/(2.*pi.*sqrt(r.^2+r_dash.^2-2.*(r.*r_dash.*cos(phi_dash-phi)))))
In @(phi_dash,r,phi)second_integral(r_dash,phi_dash,r,phi)
In integral3>@(y,z)FUN(x(1)*ones(size(z)),y,z) at 139
In funfun/private/integral2Calc>integral2t/tensor at 229
In funfun/private/integral2Calc>integral2t at 56
In funfun/private/integral2Calc at 10
In integral3>innerintegral at 138
In funfun/private/integralCalc>iterateScalarValued at 314
In funfun/private/integralCalc>vadapt at 133
In funfun/private/integralCalc at 76
In integral3 at 122
In @(r_dash)integral3(@(phi_dash,r,phi)second_integral(r_dash,phi_dash,r,phi),0,(2*pi),0,a_2,0,(2*pi))
In funfun/private/integralCalc>iterateArrayValued at 157
In funfun/private/integralCalc>vadapt at 131
In funfun/private/integralCalc at 76
In integral at 89
In this_matlab_script at 61
Error using integral2Calc>integral2t/tensor (line 242)
Integrand output size does not match the input size.
Error in integral2Calc>integral2t (line 56)
[Qsub,esub] = tensor(thetaL,thetaR,phiB,phiT);
Error in integral2Calc (line 10)
[q,errbnd] = integral2t(fun,xmin,xmax,ymin,ymax,optionstruct);
Error in integral3/innerintegral (line 138)
Q1 = integral2Calc( ...
Error in integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
Error in integralCalc/vadapt (line 133)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
Error in integralCalc (line 76)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral3 (line 122)
Q = integralCalc(@innerintegral,xmin,xmax,integralOptions);
Error in
@(r_dash)integral3(@(phi_dash,r,phi)second_integral(r_dash,phi_dash,r,phi),0,(2*pi),0,a_2,0,(2*pi))
Error in integralCalc/iterateArrayValued (line 157)
fxj = FUN(t(1)).*w(1);
Error in integralCalc/vadapt (line 131)
[q,errbnd] = iterateArrayValued(u,tinterval,pathlen);
Error in integralCalc (line 76)
[q,errbnd] = vadapt(@AtoBInvTransform,interval);
Error in integral (line 89)
Q = integralCalc(fun,a,b,opstruct);
Error in this_matlab_script (line 61)
integrated_second_integral
=integral(@(r_dash)integral3(@(phi_dash,r,phi)second_integral(r_dash,phi_dash,r,phi),0,(2*pi),0,a_2,0,(2*pi)),0,a_1,'ArrayValued',true);
这个错误的来源对我来说是一个完全的谜。有人可以对这里可能发生的事情以及我可以采取哪些措施来解决问题进行一些说明吗?
答案 0 :(得分:2)
抛出错误来自integral2Calc()的tensor()函数中的第242行。在那里设置断点表明VTSTIDX和Z1之间确实存在不匹配的大小。此外,还有以下提示:
% Check that FUN is properly vectorized. This is important here
% because we (otherwise) always pass in square matrices, which
% reduces the probability of the user generating an error by
% using matrix functions instead of elementwise functions.
查看你的函数:在你的函数的某些部分你使用r。* r_dash,在其他地方使用r * r_dash。此外,使用。和*代替./和。*来分割或乘以向量,同时使用。*与标量同时进行乘法运算。我会建议你在这方面更加一致。
无论如何,将功能改为:
second_integral = @(r_dash, phi_dash, r, phi) ( (exp(-1i * k * r_dash .* cos(phi_dash) * sin(theta)) .* exp(-1i * k * sqrt(r.^2 + r_dash.^2 - 2*( r .* r_dash .* cos (phi_dash - phi))))) ./ (2 * pi * sqrt(r.^2 + r_dash.^2 - 2.*( r .* r_dash .* cos (phi_dash - phi))) ) );
不再提供错误(而是许多警告),但由于我没有进行整合,我不知道上述内容是否解决了您的问题。