Write function for complicated recurrence relation.
조회 수: 16 (최근 30일)
이전 댓글 표시
Hi all!
I'm trying to learn myself how to write some code in Matlab to solve some involved recurrence relations. But I'm not a great programmer and I have a very hard time to go from the simple examples (of calculating a factorial), to something more complicated.
I'm now trying to solve the equation below for a given value of n, using functions in Matlab. But to be honest, I have no clue how to make sure the correct (intermediate) values should get passed along, by calling a function. At this point I'm just very confused and didn't get any code to actually run in a way that produced any results.

I know it's quite an ask, but would be amazing if someone could show me how to solve an example like this.
Greetings,
John
답변 (1개)
Torsten
2023년 10월 26일
편집: Torsten
2023년 10월 26일
I modified your formula slightly, and after this modification, it seems to give correct results:
N = 14;
L = zeros(N);
L(1,1:N) = 1;
for n = 2:N
for k = 2:n-1
sum1 = 0.0;
for j = 1:floor(n/k)
sum2 = 0.0;
for t = 1:min(k-1,max(1,n-k*j))
sum2 = sum2 + L(t,max(1,n-k*j));
end
sum1 = sum1 + sum2 * factorial(n)/(factorial(j)*(k^j)*factorial(n-k*j));
end
L(k,n) = sum1;
end
L(n,n) = factorial(n-1);
end
int64(L(:,N))
int64(sum(L(:,N)))
int64(factorial(N))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
