integration Question Matlab error

1 view (last 30 days)
Hi i am having trouble integrating a function for a program that i am writing, i have been trying to fix it for a while and i have had no luck im hoping someone here with a little bit more experience can help me. Basically i have a network and i am trying to figure out a function called a local function at each node in the network, thats a big vague but i dont want to bore you with too much detail, here the code i wrote.
for i=1:num
b = (distancePU(1,i)/distancePU(1,i))^(-pathloss);
q = randn(2) * sqrt(1) + 0;
PDFpu = ((1/abs(b))*(2*(q/b))/((((q/b)^2)+1)^2));
a = (RSSattacker(i)/RSSattacker(i))/pi;
PDFattacker = (1/(abs(a)))*((2*(q/a))/((((q/a)^2)+1)^2));
KL = @(q) PDFpu * log(PDFpu/PDFattacker);
KLint = integral(KL,0,1); % KL integral
end
I am basically computing all the terms one by one and then integrating them in the KLint function and i keep getting the same error "Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued' option to true." i cant really figure out what the problem is, any advice would be appreciated.

Accepted Answer

Star Strider
Star Strider on 7 Jul 2014
I don’t have all your data so I can’t run your code. However, q generates a (2x2) matrix (of normally-distributed random numbers) that is used in KL, therefore KL is also a (2x2) matrix, and your argument to integral.
You have to change KLint to:
KLint = integral(KL,0,1,'ArrayValued',true); % KL integral
KLint will also be a (2x2) array.
  2 Comments
Sasa
Sasa on 8 Jul 2014
Thank you so much your answer helped alot.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!