Chebyshev polynomials of the first kind
11 views (last 30 days)
Show older comments
Asli Merdan
on 25 Mar 2018
Edited: Walter Roberson
on 25 Mar 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)
0 Comments
Accepted Answer
David Goodmanson
on 25 Mar 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.
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!