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!