How to find factorial(c) of an array of numbers?

2 views (last 30 days)
Respected all
I have successfully got the values for j and v. I have got stuck in solving t due to the problem in finding factorial(c). My question is how to code for factorial term in the expression? Is it possible or I am on the wrong path? As without solving factorial, t cannot be determined. What should I do?
Code attached:
A = linspace(1,10)
C = linspace(1, 11)
[k, c] = ndgrid(A, C)
j=gammainc(c,(0.85));
v=gamma(c.^(-1));
t=0.85.*(1-(((0.85).^5.*(1-(((0.85))./(1-(((0.85)).^6)))))).*1.*(1-((0.85).^5.*(factorial(c)).^-1.*(c.^(5-c).^-1)./(exp(0.85).*k.*v+(0.85).^c.*(1-(0.85./c).^(5-c+1)))/factorial(c).*(1-(0.85./c)))));
The following error is being encountered
Error using factorial
N must be an array of real non-negative integers.
How can this error be removed?
Please help
Regards
Surabhi

Accepted Answer

Adam Danz
Adam Danz on 26 May 2020
Edited: Adam Danz on 26 May 2020
N must be an array of real non-negative integers.
To troubleshoot that error message, let's go through the list of possibilities.
% Is c an array or real numbers?
all(isreal(c(:))) % = 1, true
% Is c all non-negative?
all(c(:)>=0) % = 1, true
% Is c all integers?
all(isinteger(c(:))) % = 0! FALSE
There's the problem. C contains non-integers. It makes sense that this would cause an error, right? Factorials are functions of intergers.
factorial(3) = 24
4 * 3 * 2 * 1 = 24
How could that be done with non-integers?
  9 Comments
Adam Danz
Adam Danz on 27 May 2020
Glad I could help. If you get stuck again with this topic, leave a comment to loop me back in.

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!