Factorial in MATLAB
Last Updated :
28 Nov, 2022
MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. In this article, we’ll be calculating the factorial of a number n using MATLAB’s built-in function ‘factorial(number)’.
Factorial:
The factorial of a non-negative integer is the multiplication of all positive integers smaller than or equal to n. For example factorial of 6 is 6*5*4*3*2*1 which is 720. The factorial of a number n is represented as n!
0! = 1
1! = 1
Now suppose we want to find a Factorial of 6.
Example 1:
Matlab
ans = factorial(6);
disp(ans);
|
Output:
output
Now take another example to find a factorial of 22.
Example 2:
Matlab
format long;
ans = factorial(22);
disp(ans);
|
Output:
In the given below example, we find the factorial of matrix elements.
Example 3:
Matlab
input = [[1,5,8];[4,6,0]];
disp(input);
output = factorial(input);
disp(output);
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...