Chebyshev polynomials of the first kind
4 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
David Goodmanson
2018-3-25
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!