usage of cumprod function to write the code

To create a vector t, where
t = [1 u/1! u(u-1)/2! u(u-1)(u-2)/3! ... (u(u-1)..(u-(n-2)))/(n-1)!
I wrote the following code as
t(1)=1;
for i=2:n
t(i)=t(i-1)*(u-(i-2))/(i-1)
end
Is it possible to create the above vector using 'cumprod' function

 채택된 답변

Guillaume
Guillaume 2018년 10월 10일
편집: Guillaume 2018년 10월 10일

0 개 추천

cumprod([1, u-(0:n-2)]) ./ factorial(0:n-1)
edit: actually you can replace the factorial by another cumprod which should be faster:
cumprod([1, u-(0:n-2)]) ./ cumprod([1, 1:n-1])

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Linear Algebra에 대해 자세히 알아보기

태그

질문:

2018년 10월 10일

편집:

2018년 10월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by