Integration using quad(@myfun,a,b)
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Star Strider
2014-4-4
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.
14 个评论
Star Strider
2014-4-5
Definitely helps, but I’m a bit baffled by the implied recursion. You calculate
∆² = A²B²-C²
all of which are functions of x, and with
A² = ∑x²ʲ
then go back and integrate ∆/A² w.r.t. x.
Also, when I calculate (with EN the asymptotic expression), I get:
Q/(EN*pi) = 1.2031 1.3860 1.2943
perhaps accounted for by σ² not appearing anywhere, but just a guess on my part.
If there’s no recursion, and you treat ∆/A² essentially as a constant, then you pretty much have calculated Q about as well as can be expected, except for dividing it by pi. I am not convinced that using continuous functions and integrate would be of any significant benefit.
If there is recursion, then it seems to me you carry out the summations and calculate ∆/A² for each x(j), integrate from a to b, and repeat until you reach j=(n-1). Maybe I’m missing something.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!