How do I display the terms of a binomial expansion (x+y)^n ?
7 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Matt J
on 19 Jun 2019
Edited: Matt J
on 19 Jun 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 Comments
Matt J
on 19 Jun 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 '
More Answers (0)
See Also
Categories
Find more on Startup and Shutdown 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!