How to remove error Matrix dimension must agree for double integration

2 Ansichten (letzte 30 Tage)
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.

Antworten (1)

Walter Roberson
Walter Roberson am 17 Nov. 2017
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 Kommentare
Shweta Rajoria
Shweta Rajoria am 21 Nov. 2017
Bearbeitet: Walter Roberson am 21 Nov. 2017
sir, i am using x.^q in the program, still error is coming,by mistake i have written x^q here. After using arrayfun program may be went to infinite loop , output does not come and on stopping the program, error is as follows:
Operation terminated by user during sym/privBinaryOp (line 820)
In sym/igamma (line 10)
Y = privBinaryOp(nu, Z, 'symobj::vectorizeSpecfunc', 'igamma', 'infinity');
In useSymForDouble (line 10)
res = double(fn(args{:}));
In double/igamma (line 10)
Y = useSymForDouble(@igamma, nu, Z);
In
@(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
In @(w)fun(w,x)
In integralCalc/iterateScalarValued (line 323)
fx = FUN(t).*w;
In integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
In integralCalc (line 83)
[q,errbnd] = vadapt(@AToInfInvTransform,interval);
In integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
In @(x)integral(@(w)fun(w,x),0,Inf)
In @(x)arrayfun(@(x)integral(@(w)fun(w,x),0,Inf),x)
In @(x)((1/2)-((1/pi).*c(x))).*2.*pi.*lambdam.*x.*exp(-pi.*u.*x.^2)
In integralCalc/iterateScalarValued (line 314)
fx = FUN(t);
In integralCalc/vadapt (line 132)
[q,errbnd] = iterateScalarValued(u,tinterval,pathlen);
In integralCalc (line 83)
[q,errbnd] = vadapt(@AToInfInvTransform,interval);
In integral (line 88)
Q = integralCalc(fun,a,b,opstruct);
In qqq (line 20)
c1 = integral(fun1, 0,Inf)
i have send the code above, after running that you will be able to get these error.
Walter Roberson
Walter Roberson am 21 Nov. 2017
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Numerical Integration and Differential Equations finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by