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.

3 visualizzazioni (ultimi 30 giorni)
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 Commento
ebtisam almehmadi
ebtisam almehmadi il 29 Lug 2021
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

Accedi per commentare.

Risposte (1)

Ashutosh Singh Baghel
Ashutosh Singh Baghel il 6 Ago 2021
Modificato: Ashutosh Singh Baghel il 6 Ago 2021
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.

Categorie

Scopri di più su Digital and Analog Filters in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by