How to remove error Matrix dimension must agree for double integration
2 次查看(过去 30 天)
显示 更早的评论
I am calculation the coverage probability of a heterogeneous network. At the time of integration i am getting error. I think the error is basically due to using (x^q) in the denomination of fun. The code is given below:
clear all;
close all;
R=0.5; %bits /hz/sec
Pm= 10; Ps=2;t=1; q=4;
M=50; S=20; k = 15; al =0.3;
mu = 1; sigma= 2;
%mean of lognormaldistribution
Es= exp((2*mu/q) + 0.5* (2*sigma/q));
lambdas1 = 40;
lambdam1 = lambdas1/4;
lambdas= Es * lambdas1;
lambdam = Es* lambdam1;
u= (lambdam +(lambdas*(Ps/Pm)^(2/q)));
ga1=1;
fun = @(w,x) imag(exp(-2.*pi.*lambdas.*((1i.*w.*Ps).^(2/q)).*gamma(2-2/q).*gamma(2/q)./(q-2)).*exp(-1i.*w.*Pm./(ga1.*x.^q)).*exp(-pi.*lambdam.*(((gamma(1-2/q)+(2/q).*igamma(-(2/q),(-1i.*w.*Pm./x.^q)))./(-1i.*w.*Pm).^(-2/q))-x.^2)))./w;
c = @(x)integral(@(w) fun(w,x), 0,Inf)
fun1= @(x)((1/2)-((1/pi).*c(x))).*2.*pi.*lambdam.*x.* exp(-pi.*u.*x.^2);
c1 = integral(fun1, 0,Inf)
I am new in matlab. If any body have any idea. Please help. Any advice will be appreciated.
0 个评论
回答(1 个)
Walter Roberson
2017-11-17
c = @(X) arrayfun(@(x) integral(@(w) fun(w,x), 0,Inf), X)
integral() calls the target function with a vector of varying length, so fun1 would be called with a vector x. That would cause c to be called with a vector x. The integral() call inside c is going to call fun with a w of varying length that will have nothing to do with the length of x. You then have problems inside fun because your x and w vectors are not the same size.
The change I show causes the inner integral() call to be processed with only one of the x values at a time.
4 个评论
Walter Roberson
2017-11-21
You have nested integrals. The calculation can take a long time.
You might want to consider switching from igamma, which calculates symbolically for higher precision, to gammainc, which calculates numerically but would be faster.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Numerical Integration and Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!