Filter löschen
Filter löschen

Chebyshev polynomials of the first kind

4 Ansichten (letzte 30 Tage)
Asli Merdan
Asli Merdan am 25 Mär. 2018
Bearbeitet: Walter Roberson am 25 Mär. 2018
Hello everyone. I've been writing Chebyshev code but I have problem.
function pol=cheby(n,x)
toplam=0;
if(n==0)
pol=1;
elseif(n==1)
pol=x;
else
for n=0:6
pol=toplam + 2.*(x).*cheby(n-1,x)-cheby(n-2,x);
end
end
It goes to infinite recursion. When I do it one by one with elseif it works. How can I work it ? (I want to work it for n=0,1,2,3,4,5,6)

Akzeptierte Antwort

David Goodmanson
David Goodmanson am 25 Mär. 2018
Hi Asli
If you get the do loop out of the code so that the three lines
for n=0:6
pol=toplam + 2.*(x).*cheby(n-1,x)-cheby(n-2,x);
end
are just
pol=toplam + 2.*(x).*cheby(n-1,x)-cheby(n-2,x);
then cheby(n,x) it works correctly. Then you can call it in a for loop for different values of n.
And if you replace
pol = 1 with pol=ones(size(x));
then the function will work with a vector of x values.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by