How do I display the terms of a binomial expansion (x+y)^n ?
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I want to display the terms in terms of x and y i.e nCr x^(n-r) y^r with r going from 0 to n
0 Commenti
Risposta accettata
Matt J
il 19 Giu 2019
Modificato: Matt J
il 19 Giu 2019
One way,
n=4;
e=0:n;
C=arrayfun(@(i)nchoosek(n,i),e);
sprintf('%d*x^%d*y^%d ',[C;e;n-e])
'1*x^0*y^4 4*x^1*y^3 6*x^2*y^2 4*x^3*y^1 1*x^4*y^0 '
3 Commenti
Matt J
il 19 Giu 2019
Just call sprintf() differently
sprintf('%d*x^%d*y^%d ',[C;e;n-e])
'1*x^0*y^4 4*x^1*y^3 6*x^2*y^2 4*x^3*y^1 1*x^4*y^0 '
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!