Store recursive intermediate values
이전 댓글 표시
I'm trying to save intermediate values when calling recursive function without using global variables. I don't find anything suiting my issue on mathworks topics and I'd need help.
I'm trying to replicate Legendre polynomials. For example I have to compute the 6-th order polynomial, but to compute so I need the first 5-th orders. But I'd like to keep the intermediates polynomails/results instead of only the 6-th polynom.
Here's the funcion I'm using and that I need to adjust:
function Y = Laguerre(X, k)
if (k==0)
Y=1;
elseif (k==1)
Y=1-X;
else
Y=(1/k)*((2*k-1-X).*Laguerre(X,k-1)-(k-1)*Laguerre(X,k-2));
end
end
Any clue could be appreciated !
댓글 수: 4
KALYAN ACHARJYA
2018년 9월 7일
@Cedric Which intermediate values?, What are X and K?
Stephen23
2018년 9월 7일
"But I'd like to keep the intermediates polynomails/results instead of only the 6-th polynom."
Do you want to keep all of them, or just some of them?
Stephen23
2018년 9월 8일
"Keep all of the intermediate values"
It is not clear what you mean by this. Which of these do you mean?:
- keep intermediate Y values that occur within the recursive function, that are otherwise discarded when the function returns.
- keep all output values (i.e. the final Y value) from the function, over a range of X.
- some other definition of "intermediate value".... ?
You might know what you want, but we don't. Please explain exactly which values you are talking about, with examples.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Polynomials에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!