Chebyshev Polynomial functions of the first kind
2 次查看(过去 30 天)
显示 更早的评论
function y = myChebyshevPoly1(n,x)
%y = myChebyshevPoly1(n,x)
%y is the vector for the first n Chebyshev numbers
if n == 0
out = 1; %first base case
else if n == 1
out = x; %second base case
else
out = 2*x*myChebyshevPoly1((n-1),x)-myChebyshevPoly1((n-2),x);%recursive call
end
end % end myChebyshevPoly1
>>x = myvec/26;
>> n = 5;
>> y = myChebyshevPoly1(n,x)
when i run it and apply the following commands it will appear as error can someone explain to me what am i doing wrong?
also how can i ensure that expression above works for the case when x is a vector.
0 个评论
回答(1 个)
Patrick Gipper
2020-2-14
You just need to replace "out" with "y". Maybe you already caught this?
function y = myChebyshevPoly1(n,x)
%y = myChebyshevPoly1(n,x)
%y is the vector for the first n Chebyshev numbers
if n == 0
y = 1; %first base case
else if n == 1
y = x; %second base case
else
y = 2*x*myChebyshevPoly1((n-1),x)-myChebyshevPoly1((n-2),x);%recursive call
end
end % end myChebyshevPoly1
3 个评论
Patrick Gipper
2020-2-14
Oh right, I just used a scalar test case. One change fixes that.
function y = myChebyshevPoly1(n,x)
%y = myChebyshevPoly1(n,x)
%y is the vector for the first n Chebyshev numbers
if n == 0
y = 1; %first base case
else if n == 1
y = x; %second base case
else
y = 2*x.*myChebyshevPoly1((n-1),x)-myChebyshevPoly1((n-2),x);%recursive call
end
end % end myChebyshevPoly1
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!