Function Approximation and Interpolation

12 ビュー (過去 30 日間)
Sardor Butunboev
Sardor Butunboev 2021 年 10 月 11 日
回答済み: David Hill 2021 年 10 月 11 日
Given: f(x) = exp(-x^2) on the interval [-1; 1].
Need to:
  1. Approximate f(x) by a 9-degree monomial basis polynomial interpolant with equidistant nodes. Proceed as follows:
1.1. create a vector x containing the n = 9 interpolation nodes.
1.2. use the function 'vander' to create the interpolation matrix G.
1.3. compute yi = f(xi) at the n interpolation nodes.
1.4. compute the n basis coefficients c.
2. Evaluate the accuracy of the interpolant, say f1, as follows:
2.1. Use the Matlab function 'polyval' to evaluate f1 for 100 evenly distributed points on [-1; 1].
2.2. Compare these interpolated values with the 'true' values of f.
2.3. Plot the approximation error.
So far, could this. But no idea whether they are correct or not. Don't even understand what should do in 2.2 and 2.3
f = @(x) exp(-x.^2);
n = 9;
y = linspace(-1, 1, n);
z = [];
for i = 1:length(y)
z(i) = feval(f,y(i));
end
v = fliplr(vander(y));
a = v\z';
b = a(end:-1:1)';
%5
c = linspace(-1,1);
d = polyval(b, c);
p = polyfit(c,d);

採用された回答

David Hill
David Hill 2021 年 10 月 11 日
Something like this.
f = @(x) exp(-x.^2);
x = linspace(-1, 1, 9);
G=vander(x);
y=f(x);
c=G\y';
f1=@(x)polyval(c,x);
t=linspace(-1,1,100);
Error=(f(t)-f1(t))./f(t);
plot(t,Error)

その他の回答 (0 件)

カテゴリ

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