summation operation in matlab

2 ビュー (過去 30 日間)
joe khese
joe khese 2014 年 3 月 13 日
編集済み: Marta Salas 2014 年 3 月 14 日
hello, i am trying to write a code to implement the summation operation but having errors the equation is below. my code is
A=rand(1,10);
N = 6;
for b = 1:N
syms A;
Pb = (A.^N/factorial(N)) / symsum ((A.^i)/(factorial(i)),i,0,N);
% Bp = (Toi.^N)/(factorial(N)) / symsum(Toi.^[0:N]./ factorial([0:N]));
end
and i keep getting this error
??? Error using ==> factorial at 17
N must be a matrix of non-negative integers.
Error in ==> ERLANGB_TEST at 7
Pb = (A.^N/factorial(N)) / symsum ((A.^i)/(factorial(i)),i,0,N);
thanks for your anticipated help.
  2 件のコメント
Salaheddin Hosseinzadeh
Salaheddin Hosseinzadeh 2014 年 3 月 13 日
What is this in your quesion?
% Bp = (Toi.^N)/(factorial(N)) / symsum(Toi.^[0:N]./ factorial([0:N]));
end
thanks
joe khese
joe khese 2014 年 3 月 14 日
that is the code i wrote to implement the equation above but i keep getting this error N must be a matrix of non-negative integers.

サインインしてコメントする。

回答 (3 件)

Mischa Kim
Mischa Kim 2014 年 3 月 13 日
Joe, use
syms A ii
N = 6;
Pb = A^N/factorial(N)/(symsum(A^ii/factorial(ii),0,N)); % symbolic expression
sPb = subs(Pb,A,3); % substitute 3 for A to get numeric result
  1 件のコメント
Mischa Kim
Mischa Kim 2014 年 3 月 14 日
What release are you working with?
What happens when you replace in the equation
factorial(N)
by
sym('N!')

サインインしてコメントする。


joe khese
joe khese 2014 年 3 月 14 日
thanks Mischa. I tried what u suggested but still getting the same error. N must be a matrix of non-negative integers.

Marta Salas
Marta Salas 2014 年 3 月 14 日
編集済み: Marta Salas 2014 年 3 月 14 日
You must define i as a symbolic variable too, otherwise i is defined as the sqrt(-1)
syms A i
N = 6;
Pb = (A.^N/factorial(N)) / symsum ((A.^i)/factorial(i),i,0,N);

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by