Borrar filtros
Borrar filtros

Chebyshev Polynomial functions of the first kind

4 visualizaciones (últimos 30 días)
Katerina Polykarpou
Katerina Polykarpou el 14 de Feb. de 2020
Comentada: Katerina Polykarpou el 14 de Feb. de 2020
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.

Respuestas (1)

Patrick Gipper
Patrick Gipper el 14 de Feb. de 2020
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 comentarios
Patrick Gipper
Patrick Gipper el 14 de Feb. de 2020
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
Katerina Polykarpou
Katerina Polykarpou el 14 de Feb. de 2020
thank you so much

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by