Why am I getting this error? The integrand function must return an output vector of the same length as the input vector.
显示 更早的评论
Hi
I have the following function
function AW1= AW_int(x,N)
N=[10 100 1000 10000 100000];
x=[0.9 0.99 0.999 0.9999 0.99999 0.999999 0.9999999];
ASqr=aSqrSum(x,N);
BSqr=bSqrSum(x,N);
C=CSum(x,N);
delta2=(ASqr.*BSqr)-(C.^2);
delta=delta2.^(1/2);
AW1=delta./ASqr;
format long e
delta2;
delta;
AW1
end
With the following functions for aSqrSum, bSqrSum and CSum:
function ASqr =aSqrSum(x,N)
N=[10 100 1000 10000 100000];
x=[0.9 0.99 0.999 0.9999 0.99999 0.999999 0.9999999];
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
format long e
ASqr;
end
function BSqr =bSqrSum(x,N)
N=[10 100 1000 10000 100000];
x=[0.9 0.99 0.999 0.9999 0.99999 0.999999 0.9999999];
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
function C = CSum(x,N)
N=[10 100 1000 10000 100000];
x=[0.9 0.99 0.999 0.9999 0.99999 0.999999 0.9999999];
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
I want to integrate the function AW_int with respect to x between 0 and 0.9999. However when I run the following in the command line:
quad(@AW_int,0,0.9999)
I get the following error:
Error using quad (line 75)
The integrand function must return an output vector of the same length as the input
vector.
Would anyone be able to explain to me what this error means? As im unsure of where I am going wrong and how to fix it.
Thank you in advanced for any possible help!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!