1 MatlabOctave a Write an OctaveMatlab program that given a

1. (Matlab/Octave) (a) Write an Octave/Matlab program that, given a function f, an interval [a,b], and a positive integer n, returns the rootse x1, ...,e xn of the n–th Chebychev polynomial shifted to the interval [a,b], and also f(e x1), ..., f(e xn), the values of the function f at those points. In other words, the program gives the best possible n interpolation points for f over [a,b].

(b) Find the optimal 4 points for interpolating f(x) = xln(x) over [1,3].

Solution

% Given nonnegative integer n, compute the
% Chebyshev polynomial T_n. Return the result as a column vector whose mth
% element is the coefficient of x^(n+1-m).
% polyval(ChebyshevPoly(n),x) evaluates T_n(x).


function tk = ChebyshevPoly(n)

if n==0
tk = 1;
elseif n==1
tk = [1 0]\';
else
  
tkm2 = zeros(n+1,1);
tkm2(n+1) = 1;
tkm1 = zeros(n+1,1);
tkm1(n) = 1;

for k=2:n
  
tk = zeros(n+1,1);

for e=n-k+1:2:n
tk(e) = 2*tkm1(e+1) - tkm2(e);
end
  
if mod(k,2)==0
tk(n+1) = (-1)^(k/2);
end
  
if k<n
tkm2 = tkm1;
tkm1 = tk;
end
  
end
  
end

(b)


function v = polyinterp(x,y,u)
n = length(x); % enter n = 3 for the given interval
v = zeros(n);
for k = 1:n
w = ones(size(u));
for j = [1:k-1 k+1:n]
w = x(j)ln(x(k)-x(j)).*w;
end
v = v + w*y(k);
end

1. (Matlab/Octave) (a) Write an Octave/Matlab program that, given a function f, an interval [a,b], and a positive integer n, returns the rootse x1, ...,e xn of
1. (Matlab/Octave) (a) Write an Octave/Matlab program that, given a function f, an interval [a,b], and a positive integer n, returns the rootse x1, ...,e xn of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site