Store recursive intermediate values
Ältere Kommentare anzeigen
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 Kommentare
KALYAN ACHARJYA
am 7 Sep. 2018
@Cedric Which intermediate values?, What are X and K?
Stephen23
am 7 Sep. 2018
"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
am 8 Sep. 2018
"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.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Polynomials finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!