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)
Show older comments
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
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?
Accepted Answer
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)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!