尝试积分时出现八度错误:"integrand F must return a single, real-valued vector of the same size as the input"
Octave error when trying to integrate: "integrand F must return a single, real-valued vector of the same size as the input"
我已经确认问题出在尝试计算 GLonball_2 上,但我不明白为什么它会产生错误。函数 funct_2 应该只返回实数。至于 "same size as input" 部分,我认为我没有正确解释错误消息。 funct_2 有两个参数,returns 有一个值,但 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:\Software\Octave-3.6.4\share\octave.6.4\m\general\dblquad.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:\Software\Octave-3.6.4\share\octave.6.4\m\general\dblquad.m at line
65, column 5
error: C:\Software\Octave-3.6.4\GLonball.m at line 10, column 13
.-
如上面评论所述是不必要的,但它不会导致 Octave 出现任何错误。它会在 Matlab 中给出语法错误。同样,/
而不是 ./
是给您带来主要错误的原因。
更改这两个函数后,您的函数 运行 在 Octave 4.0.0 和 Matlab 2015a 中都很好。
GLonball(1)
ans = 1.5708
我已经确认问题出在尝试计算 GLonball_2 上,但我不明白为什么它会产生错误。函数 funct_2 应该只返回实数。至于 "same size as input" 部分,我认为我没有正确解释错误消息。 funct_2 有两个参数,returns 有一个值,但 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:\Software\Octave-3.6.4\share\octave.6.4\m\general\dblquad.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:\Software\Octave-3.6.4\share\octave.6.4\m\general\dblquad.m at line
65, column 5
error: C:\Software\Octave-3.6.4\GLonball.m at line 10, column 13
.-
如上面评论所述是不必要的,但它不会导致 Octave 出现任何错误。它会在 Matlab 中给出语法错误。同样,/
而不是 ./
是给您带来主要错误的原因。
更改这两个函数后,您的函数 运行 在 Octave 4.0.0 和 Matlab 2015a 中都很好。
GLonball(1)
ans = 1.5708