can any one help me in detecting an error in matlab code please ?

pih=[];
for im=1:0.1:20
n=15;
i=13;
k=8;
m=2;
h=3;
f=factorial(n)/(factorial(i)*factorial(n-i));
g=factorial((2^(k-(m*h)))*factorial(i)*factorial((2^(k-(m*h)))-i));
p=factorial((2^k))/factorial(i)*factorial((2^k)-i);
j=g/p;
o=factorial((2^k)-(2^(k-(m*h))))/factorial(n-i)*factorial((2^k) ...
-(2^(k-(m*h)))-(n-i));
u=factorial((2^k)-i)/factorial(n-i)*factorial((2^k)-i-(n-i));
z=o/u;
pih=f*j*z;
end
this is the code and this is the error message :
??? Error using ==> factorial at 17
N must be a matrix of non-negative integers.
Error in ==> marwa at 12
g=factorial((2^(k-(m*h)))*factorial(i)*factorial((2^(k-(m*h)))-i));
??? Error using ==> factorial at 17
N must be a matrix of non-negative integers.
Error in ==> marwa at 12
g=factorial((2^(k-(m*h)))*factorial(i)*factorial((2^(k-(m*h)))-i));

 Accepted Answer

The error message is telling you what is wrong. In this case the expression within the larger expression for finding g
factorial((2^(k-(m*h)))-i)
when the values of k, m, h, and i are substituted amounts to
factorial(-9)
and minus nine is not a value the factorial function can handle, as the error message indicates.
You need to rethink your code and decide what really belongs there.

2 Comments

ok thanks (y) i change some values and i dont find an error but any answer in the command window :/
#pih=[];
for im=1:0.1:20
n=15;
i=1;
k=8;
m=2;
h=3;
f=factorial(n)/(factorial(i)*factorial(n-i));
g=factorial((2^(k-(m*h)))*factorial(i)*factorial((2^(k-(m*h)))-i));
p=factorial((2^k))/factorial(i)*factorial((2^k)-i);
j=g/p;
o=factorial((2^k)-(2^(k-(m*h))))/factorial(n-i)*factorial((2^k)-(2^(k-(m*h)))-(n-i));
u=factorial((2^k)-i)/factorial(n-i)*factorial((2^k)-i-(n-i));
z=o/u;
pih=f*j*z;
end
#
"i dont find an error but any answer in the command window :/"
I interpret that to mean you changed the value 'i' and didn't get an error message, but the answer you receive does not look correct to you. If so, you would need to explain the purpose of your computations. I see that you have factorials within factorials. I cannot guess what purpose you have in mind with this.

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

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

Start Hunting!