How to remove error Matrix dimension must agree for double integration
1 回表示 (過去 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!