尝试积分时出现倍频程错误:"integrand F must return a single, real-valued vector of the same size as the input"



我已经确认这个问题是在试图计算GLonball_2时出现的,但是我不明白为什么会产生错误。函数funct_2应该只返回实数。至于"与输入大小相同"部分,我认为我没有正确解释错误信息。Funct_2接受两个参数并返回一个值,但funct_1也是如此,它没有引起错误,所以不是这个问题。有人能解释一下吗?这是我的代码:

function GLonball = GLonball(alpha)
epsilon = 1;
rmin = 0;
rmax = 1;
thmin = 0;
thmax = 2*pi;
funct_1 = @(r,th) (2).*(abs(alpha).^2-1).^(2)./abs(1-conj(alpha).*r.*exp(i.*th)).^4;
GLonball_1 = dblquad(funct_1, rmin, rmax, thmin, thmax);
funct_2 = @(r,th) (abs(alpha.-r.*exp(i.*th))/abs(1-conj(alpha).*r.*exp(i.*th))).^2;
GLonball_2 = dblquad(funct_2, rmin, rmax, thmin, thmax);
GLonball = .5*GLonball_1 + (1/((4).*epsilon^2))*GLonball_2;
end

下面是我在尝试对0到1(感兴趣的区域)之间的任何输入参数运行它时收到的错误:

error: quadcc: integrand F must return a single, real-valued vector of the same
size as the input
error: called from:
error:   C:SoftwareOctave-3.6.4shareoctave3.6.4mgeneraldblquad.m at line
 72, column 10
error:    at line -1, column -1
error: quadcc: integrand F must return a single, real-valued vector
error:   C:SoftwareOctave-3.6.4shareoctave3.6.4mgeneraldblquad.m at line
 65, column 5
error:   C:SoftwareOctave-3.6.4GLonball.m at line 10, column 13

如上所述,.-是不必要的,但它不会在Octave中引起任何错误。它会在Matlab中给出语法错误。同样,/而不是./是给你主要误差的。

在改变这两个函数后,您的函数在Octave 4.0.0和Matlab 2015a中都运行良好。

GLonball(1)
ans =     1.5708

相关内容

最新更新