フィルターのクリア

How to make nPr formula as the perms function makes nPn only ?

10 ビュー (過去 30 日間)
Abdelrhman Nasr
Abdelrhman Nasr 2020 年 6 月 2 日
回答済み: Ayden Clay 2020 年 6 月 2 日
How to make nPr formula as the perms function makes nPn only ?

回答 (1 件)

Ayden Clay
Ayden Clay 2020 年 6 月 2 日
Hey Abdelrhman,
The nchoosek function ought to be what you're looking for.
It can provide the binomial coefficient for
b = nchoosek(n,k);
or every permutation for
C = nchoosek(v,k);
where v is a row or column vector (length < 15). For example, where v = [1,2,3,4]; and k = 2; we get:
C = nchoosek([1,2,3,4],2)
C =
1 2
1 3
1 4
2 3
2 4
3 4
and if you just want the number, you can ask for size(C,1).
sz1 = size(C,1)
sz1 =
6
Or you can do it in one move with:
sz1 = size(nchoosek([1,2,3,4],2),1)
sz1 =
6
I hope this helped!

カテゴリ

Help Center および File ExchangeDiscrete Math についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by