Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write a code in Matlab for all of question #21. Thanks! 21) a) The factorial function n! can be coded as >> y =

Please write a code in Matlab for all of question #21. Thanks! image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Develop clear policy statements.

Answered: 1 week ago

Question

Draft a business plan.

Answered: 1 week ago

Question

Describe the guidelines for appropriate use of the direct plan.

Answered: 1 week ago