フィルターのクリア

Interpolating Polynomials Question Code

2 ビュー (過去 30 日間)
Kaylene Widdoes
Kaylene Widdoes 2015 年 11 月 9 日
回答済み: Walter Roberson 2015 年 11 月 10 日
I'm having some trouble getting this to run. Any suggestions are appreciated. This is what I have done so far and I am getting an error with Y = f(X)
% HW5 - Problem 2
% Chebyshev versus Newton
clear all
f = @(x) exp^(-(x^2)); % function
% Newton
X = -5:5; % equidistant points to compute the interpolating polynomial
Y = f(X); % corresponding y values
x = 0:0.01:10; % points to plot
y = f(x);
C = divdiff(X,Y); % computes the diagonal from the divided difference table
N = zeros(1,length(x));
for i=1:length(x)
N(i) = newtval(C,X,x(i)); % evaluates the newton polynomial at x(i)
end
subplot(1,2,1)
plot(X,Y,'o',x,y,'k',x,N,'r'),title('Newton Interpolation'),
legend('Data','Exact','Newton')
axis([0 10 -2 15])
% Chebyshev
N = length(X); % same number of points as in Newton;
t = zeros(1,N);
c = zeros(1,N);
for k=1:N
t(k) = cos( (2*k-1)*pi/(2*N) ); % Chebyshev points
c(k) = t(k)*(10-0)/2 + (10+0)/2; % Chebyshev points in [0,10]
end
Y = f(c);
C = divdiff(c,Y);
Ch = zeros(1,length(x));
for i=1:length(x)
Ch(i) = newtval(C,c,x(i));
end
subplot(1,2,2)
plot(c,Y,'o',x,y,'k',x,Ch,'r'),title('Chebyshev Interpolation'),
legend('Data','Exact','Chebyshev')
axis([0 10 -2 15])

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 11 月 10 日
f = @(x) exp(-(x.^2)); % function

カテゴリ

Help Center および File ExchangePolynomials についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by