MATLAB: Integration using quad(@thefun,a,b)

integrationquad

I have the following function
function AW1= AW_int()
ASqr=aSqrSum();
BSqr=bSqrSum();
C=CSum();
delta2=(ASqr.*BSqr)-(C.^2);
delta=delta2.^(1/2);
AW1=delta./ASqr;
format long e
delta2;
delta;
%delta2; delta;
AW1;
end
Using the following functions for ASqr, BSqr and C
function ASqr =aSqrSum(x,N)
N=[1000 10000 100000];
x=[0.9 0.99 0.999 0.9999];
ASqr = zeros(length(N), length(x));
for ii = 1:length(N)
for n = 0:N(ii)-1
ASqr(ii,:) = ASqr(ii,:) + (x.^(2*n));
end
end
function C = CSum(x,N)
N=[1000 10000 100000];
x=[0.9 0.99 0.999 0.9999];
C = zeros(length(N), length(x));
for ii = 1:length(N)
for n = 0:N(ii)-1
C(ii,:) = C(ii,:) + (n.*x.^(2.*(n)-1)) ;
end
end
format long e
C;
end
format long e
ASqr;
end
function BSqr =bSqrSum(x,N)
N=[1000 10000 100000];
x=[0.9 0.99 0.999 0.9999];
BSqr = zeros(length(N), length(x));
for ii = 1:length(N)
for n = 0:N(ii)-1
BSqr(ii,:) = BSqr(ii,:) + ((n.^2).*x.^(2.*(n)-2));
end
end
format long e
BSqr;
end
When i try to integrate the function AW_int using
Q = quad(@AW_int,0,0.9999)
The following error is returned:
Error using AW_int
Too many input arguments.
Error in quad (line 72)
y = f(x, varargin{:});
Would anyone be able to help me fix this? As I have tried a few different things but the same error is still be returned.
Thanks

Best Answer

Your AW_int function doesn’t take any input arguments:
function AW1= AW_int()
Also, you are not passing any arguments to these functions within AW_int, so they will likely throw a similar error when AW_int executes:
ASqr=aSqrSum();
BSqr=bSqrSum();
C=CSum();
They all require x and N as inputs, so pass those to AW_int and then to the other functions.
Related Question