I'm trying to replace "t" in the code with ti=a + (b−a)*((xi+1)/2) to plot the Lagrange polynomial interpolation with Chebyshev points.

조회 수: 1 (최근 30일)
clear
n = 8; % the order of the polynomial
a = 1; % left end of the interval
b = -1; % right end of the interval
h = (b - a)/n; % interpolation grid size
t = a:h:b; % interpolation points
f = 1./(1 + 25*t.^2); % f(x) = 1./(1 + 25*t.^2), This is the function evaluated at interpolation points
%%%% pn(x) = \sum f(t_i)l_i(x)
hh = 0.01; % grid to plot the function both f and p
x = a:hh:b;
fexact = 1./(1 + 25*x.^2); %exact function f at x
l = zeros(n+1, length(x)); %%%% l(1,:): l_0(x), ..., l(n+1): l_n(x)
nn = ones(n+1, length(x));
d = ones(n + 1, length(x));
for i = 1:n+1
for j = 1:length(x)
nn(i,j) = 1;
d(i,j) = 1;
for k = 1:n+1
if i ~= k
nn(i,j) = nn(i,j) * (x(j) - t(k));
d(i,j) = d(i,j) * (t(i) - t(k));
end
end
l(i,j) = nn(i,j)/d(i,j);
end
end
fapp = zeros(length(x),1);
for j = 1:length(x)
for i=1:n+1
fapp(j) = fapp(j) + f(i)*l(i,j);
end
end
En = 0;
Ed = 0;
for i = 1:length(x)
Ed = Ed + fexact(i)^2;
En = En + (fexact(i) - fapp(i))^2;
end
Ed = sqrt(Ed);
En = sqrt(En);
E = En/Ed;
display(E)
plot(x,fexact,'b*-')
hold on
plot(x,fapp,'ro-' )
  댓글 수: 1
ebtisam almehmadi
ebtisam almehmadi 2021년 7월 29일
I have no clue how to code xi to make the code works, where xi=−cosθi, θi=ih,h=π/n, i= 0:n.
the plot for n=8 should be the same as above figure.
code must give nine chebychev points for n=8

댓글을 달려면 로그인하십시오.

답변 (1개)

Ashutosh Singh Baghel
Ashutosh Singh Baghel 2021년 8월 6일
편집: Ashutosh Singh Baghel 2021년 8월 6일
Hi ebtisam,
I understand you faced issue with 'plot', please update the variable 'hh' with proper value as a decrement, instead of increment.
example =
hh = -0.01; %provide a negative sign as a>b
Also, from the comment you provided, try to write the equation into a code format.
The reference guide for creating a linear, equally spaced vector can be found here.

카테고리

Help CenterFile Exchange에서 Digital and Analog Filters에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by