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

This is matlab A factorial is the product of all positive integers less than or

ID: 3804847 • Letter: T

Question

This is matlab

A factorial is the product of all positive integers less than or equal to a given positive number. Write a function that will receive as input either a single positive number or a vector of positive numbers and return the factorials as a vector. For example, if 5! is passed to the function, the returned value would be 120 (1*2*3*4*5). Likewise, if a vector [6 4 2 1] is passed, the function will return a vector with the factorial of every element in the input vector. Make sure you use a for loop in your solution.

Explanation / Answer

in matlab we can write the factorial of number via iteration as:-

if the number entered is 5 then

First iteration

The value of i is 1 and this is multiplied to the result which will give the value as 1*1 = 1

Second iteration

The value of i is 2 and this is multiplied to the result which will give the value as 1*2 = 2.

Third iteration

The value of i is 3 and this is multiplied to the result which will give the value as 2*3 = 6.

Fourth iteration

The value of i is 4 and this is multiplied to the result which will give the value as 2*3*4 = 24.

Fifth iteration (final iteration)

The value of i is 5 and this is multiplied to the result which will give the value as 2*3*4*5 = 120.


So finally when we combine all the iterations, the calculations that take place iteration by iteration are as follows:

1*2*3*4*5 = 5*4*3*2*1 = 120.

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