this code is for calculating the probability of attack success represent for the equation A, i need to change it to calculate the probability of attack success for the equation B:where q =[0.1 ,0.2 , 0.3, 0.4 , 0.5] and p= 1-q and Z= 6

4 views (last 30 days)
the code for the Eq.A in the follwing:
function y=AttackerSuccessProbability(q,z)
p=1-q;
lambda=z.*q./p;
sum=1;
for k=0:max(z)
poisson=exp(-lambda);
for i=1:k
poisson= poisson.*lambda./i;
end
sum=sum-poisson.*(1-((q/p).^(z-k)));
end
y=array2table(sum);
end
i need to change this code to calculate the AttackerSuccessProbability for the Eq.B
and i need the result for Eq.B appears like the following table
:
  2 Comments
Rik
Rik on 15 Jul 2019
The main issue for me with your question is that I have no clue whatsoever what you mean with your equations and your code, nor how they are related. I did notice you're using sum as a variable, preventing its use as a function. It also looks like sum is supposed to be a scalar, in which case array2table seems out of place.
Do you have a function, which takes the q1 and q2 parameters and returns a scalar? Or is that what you need?
And once you have that grid, do you already know how to convert that to a table? Or is that your actual question?
Sofy
Sofy on 16 Jul 2019
Edited: Sofy on 16 Jul 2019
The code is for the first equation, coz there's one value of lambda, the second equation has two values of lambda depends on the condition of odd and even values for the array index of the probabilities .which means lambda for the odd array index when q1= 0.1, 0.3,0.5 the probabilities =q1/p1= (0.1/0.9)+(0.3/0.7)+(0.5/0.5) that the first value of lambda .the second value of lambda for the even array index which =q2/p2=(0.2/0.8)+(0.4/0.6) for the column of q2=0.2,0.4 .that means i need to calculate the values for the column of q2=0.1, 0.3, 0.5 with lambda of an odd condition and the column of q2= 0.2, 0.4 with lambda of an even condition .
i just need to calculate the values for column headed by q2=0.1 ,0.2 ,0.3 when lamda =sum of q1/p1 as i mentioned above and calculate the values for column headed by q2= 0.2 ,0.4 when lambda =q2\q2

Sign in to comment.

Accepted Answer

Torsten
Torsten on 16 Jul 2019
Edited: Torsten on 16 Jul 2019
function main
q1a = [0.1 0.2 0.3 0.4 0.5];
q2a = [0.1 0.2 0.3 0.4 0.5];
z = 6;
vec = zeros(1,z);
for i = 1:numel(q1a)
q1 = q1a(i)
p1 = 1 - q1;
for j = 1:numel(q2a)
q2 = q2a(j);
p2 = 1 - q2;
vec(1:2:end) = q1/p1;
vec(2:2:end) = q2/p2;
lambda = sum(vec);
terms_left = cumprod([1,lambda*ones(1,z)]./[1,(1:z)]);
terms_right = [1-fliplr(cumprod(vec)), 0];
P_z(i,j) = 1 - exp(-lambda)*sum(terms_left.*terms_right);
end
end
P_z
end
Now you should be able to make a table from the matrix P_z.

More Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

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

Start Hunting!