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!