Effacer les filtres
Effacer les filtres

A question about for loop

2 vues (au cours des 30 derniers jours)
Mnr
Mnr le 22 Déc 2014
Hello all,
I have a vector p=[.5 .7 .2]; I have a quantity d that is equal to (1-p(1))*(1-p(2))*p(3)+(1-p(1))*p(2)*(1-p(3))+p(1)*(1-p(2))*(1-p(3))
Can anybody tell me how I can use for loop to get d instead of writing the formula of that?
Thanks.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 22 Déc 2014
p=[.5 .7 .2];
idx=nchoosek(1:3,2)
out=0;
for k=1:size(idx,1)
m=setdiff(1:3,idx(k,:));
out=out+p(m)*(1-p(idx(k,1)))*(1-p(idx(k,2)))
end

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Aucun tag saisi pour le moment.

Community Treasure Hunt

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

Start Hunting!

Translated by