Using Matlab m 4. A function, C(n, K), which computes the number of different wa
ID: 3599664 • Letter: U
Question
Using Matlab
m 4. A function, C(n, K), which computes the number of different ways of uniquely choosing k objects from in ithout repetition, is commonly used in many statistics applications. For exam ple, how many three-flavored ice cream sundaes are there if there are 10 icecream flavors ? To solve this problem we would have to compute C10, 3), the number of ways of choosing three unique icecream flavors from 10. The function C is commonly called ºn choose K. " You may assume that n and k are 1 x 1 integer doubles. If n = k, then clearly c(n, K) = 1 because there is only way to choosen objects from an objects. If K = 1, then c(n, k) = n because choosing each of the n objects is a way of choosing one object from n. For all other cases, c(n, R) = C(n = 1, R) + C(n - 1, K– 1). Can you see why? Write a function with header [N] = myNChoosek (n, k) that computes the number of times k objects can be uniquely chosen from n objects without repetition. Test Cases: >> Nam myNChoosek (10, 1) N 10 >> N = myNChoosek (10, 10) >> N - myNChoosek (10, 3) N - 120Explanation / Answer
myNChooseK.m
function [N] = myNChooseK(n, k)
if n == k
N = 1;
elseif k == 1
N = n;
else
N = myNChooseK(n-1, k) + myNChooseK(n-1, k-1);
end
end
on console
N = myNChooseK(10, 1)
N = myNChooseK(10, 10)
N = myNChooseK(10, 3)
Sample output
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.