Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The factorial of a positive real integer is defined as follows: Subsequent facto

ID: 3812167 • Letter: T

Question

The factorial of a positive real integer is defined as follows:

Subsequent factorial numbers are related according to:

A. Write a function that takes a positive real integer as input and returns the factorial result. Ensure that your function checks for wrong inputs such as non-integers or n < 1.
B. Write an m-file which uses your function from part A to calculate the 9 factorial (i.e. 9!)
C. The mathematical constant e can be obtained using the infinite series:

Using your function written in part A, write an m-file that calculates the value of e to 6 decimal places (i.e. a precision of 10-6). You should calculate the error as the difference between the new value and the old value.

Note: Do not use the MATLAB inbuilt function “factorial”.

n! n x (n -1) x (n 2)... x 3 x 2 x 1, n 1

Explanation / Answer

[1]
function y = fact(n)

   f = 1;
   while n > 1
         n = n-1;
         f = f*n;
   end
   y = f;

end

[2]
clear all;
clase all;
n = 9;
disp('Factorial of 9 is : ' fact(n))

[3]

e = 0;
for m = 1:6
    e = e + m/fact(m);
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote