BGreen
BGreen

Reputation: 450

Octave error when trying to integrate: "integrand F must return a single, real-valued vector of the same size as the input"

I've confirmed that the issue is in attempting to compute GLonball_2, but I don't see why it's producing an error. The function funct_2 should be returning only real numbers. As for the "same size as input" part, I don't think I'm interpreting the error message correctly. funct_2 takes two arguments and returns one value, but so does funct_1, which caused no error, so that's not it. Could someone explain this? This is my code:

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

Here's the error I receive when attempting to run it for any input argument between 0 and 1 (the area of interest):

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\3.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\3.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

Upvotes: 1

Views: 1144

Answers (1)

Nick J
Nick J

Reputation: 1610

The .- is unnecessary as mentioned in the comment above, but it doesn't cause any errors in Octave. It will give a syntax error in Matlab. Similarly, the / instead of ./ is what's giving you the primary error.

After changing both of those your function ran fine in both Octave 4.0.0 and Matlab 2015a.

GLonball(1)
ans =     1.5708

Upvotes: 1

Related Questions