Matlab question Write a function to implement nnk Name the f

Matlab question:

Write a function to implement n!/(n-k)!. Name the function perms. Design criteria:

a. The input n is bigger than or equal to k. Both are whole numbers.

b. Use exactly one for-loop to find the solution.

c. You can’t use the Matlab factorial function because it prevents the operation from working for large values of n. For example, Matlab can’t compute factorial(200) correctly - try it. No other Matlab functions should appear in your solution.

d. You will know your function works correctly when:

7,880,400. = perms(200,3)

Thank you for help

Solution

function [ x ] = perms(n,k)
if n<k
    disp(\'n should be bigger than or equal to k\')
else
    start=n;
    num=1;
    for i=1:(n-1)
        num1=start*(n-i);
        num=num*num1
        start=1;
    end
    d=n-k;
    start1=d;
        den=1;
      for j=1:(d-1)
        den1=start1*(d-j);
        den=den*den1;
        start1=1;
     end
end
output=num/den
end

Matlab question: Write a function to implement n!/(n-k)!. Name the function perms. Design criteria: a. The input n is bigger than or equal to k. Both are whole

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site