Matlab, Octave code for Chebyshev Polynomial visualization
% Chebyshev polynomial function
% Author Sumant
% December 1, 2007
% About function cheby(n) the parameter n controls
% the degree of the polynomial
% I have also included y = 0 so one can see the roots of the
% polynomial of the plot
% The accuracy of plot can be increased or decreased by changing
% the number of division in x
% Use just copy and paste the code and make a .m file and it
% should run in both matlab and octave, I tested it on octave
function cheby(n)
x = -1:.001:1; % Change subdivision here for more accuracy
ln = length(x);
t0 = ones(1,ln);
y0 = zeros(1,ln);
t1 = x;
if n < 0
disp('n should be greater than 0');
else
for j = 1:n
t2 = 2.*x.*t1 -t0;
t0 = t1;
t1 = t2;
plot(x,t2);%hold on;
end; % end of for statement
plot(x,t0,x,y0);
end; % end of if statement
% Author Sumant
% December 1, 2007
% About function cheby(n) the parameter n controls
% the degree of the polynomial
% I have also included y = 0 so one can see the roots of the
% polynomial of the plot
% The accuracy of plot can be increased or decreased by changing
% the number of division in x
% Use just copy and paste the code and make a .m file and it
% should run in both matlab and octave, I tested it on octave
function cheby(n)
x = -1:.001:1; % Change subdivision here for more accuracy
ln = length(x);
t0 = ones(1,ln);
y0 = zeros(1,ln);
t1 = x;
if n < 0
disp('n should be greater than 0');
else
for j = 1:n
t2 = 2.*x.*t1 -t0;
t0 = t1;
t1 = t2;
plot(x,t2);%hold on;
end; % end of for statement
plot(x,t0,x,y0);
end; % end of if statement
0 Comments:
Post a Comment
<< Home