Question: Please write a code in Matlab for all of question #21. Thanks! 21) a) The factorial function n! can be coded as >> y =
21) a) The factorial function n! can be coded as >> y = prod(1:n) i.., n! = 1-2-3 . . . . . n. Find the largest value of n for which the result is not Inf by using a while loop. Check that the largest value of n you have calculated is the same as when calling factorial directly b) Calculate 1! directly as 1 12) 3 (5.12) using one statement, and find the largest value of n for which the product is positive, again using a for loop. (It is larger than in the previous part.) Note (this part only): Do the divisions inside the parentheses before doing the multiplications between the parentheses. c) As determined above, the factorial function can easily return oo. The floating-point overflow can be avoided by calculating n! in scientific notation, and returning the result as fx10m where f e [1,10) and m is an integer. This can be done by not calculating n! but, instead, logio n! log1o 1 + log1o 2+.+log1on, and logon! = logo f + m. (6) Write a script named logfact.m to do this calculation. The input is n, and the outputs are f and m. Verify that your code is correct. (i) Print the output for n 104 and then for 10 d) What is the approximate value of n for which logio n! is realmax? This is a question you must answer analytically, not numerically
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
