Try   HackMD

Lecture - Approximating functions

Approximating functions

多項式事實上是一個很好的函數, 我們完全知道他的微分以及積分.

所以通常任意一個函數我們會想要把它以多項式取代. 然後我們以此多項式的微分積分來估計原函數的微分積分值.


而事實上在分析導論這門課中也知道, 有以下這個定理告訴我們這樣的多項式一定找得到, 而且跟原函數的距離可以任意小:

Weierstrass Approximation Theorem:

If

f is continuous on
[a,b]
and if
ϵ>0
, then there is a polynomial
p
satisfying
f(x)p(x)ϵ
on the interval
[a,b]
.


Question: 以上定理中的

f(x)p(x) 是怎麼定義的?

Exercise

任意給定兩個函數

f(x),
g(x)
,
x[a,b]
, 計算出
f(x)g(x)
.


Exercise

試求出一個最佳的多項式

PN(x) 來取代
f(x)=sin(x)
,
x[0,1]
.

Possible idea 1:
  • 均勻在
    [0,1]
    取點, 並得到
    (xi,f(xi)),i=1,,N
    . 利用 polyfit 找到一個多項式通過逼近這些點. 並以此多項式來當
    PN(x)
    .
  • 隨機在
    [0,1]
    取點, 並得到
    (xi,f(xi)),i=1,,N
    . 利用 polyfit 找到一個多項式通過逼近這些點. 並以此多項式來當
    PN(x)
    .

Question 1:

PN(x)
f(x)
的距離有多遠?
PN(x)f(x)=maxx[0.1]{|PN(x)f(x)|}

Question 2:

PN(x)
f(x)
的距離有多遠?

Question 3: 任意給

ϵ>0, 要如何找到
PN(x)
?


Runge's phenomenon

均勻取點無法收斂

f(x)=11+25x2,1x1

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

function InterpolateRungeFunction2 % Select interpolation points by right clicking. % When you get bored, left or double click to finish. F = @(x) 1./(1+25*x.^2); % initialise x = []; t = linspace(-1, 1, 1000); LW = 'LineWidth'; MS = 'MarkerSize'; fv = F(t); afv = max(fv)+1; ifv = min(fv)-1; % loop figure plot(t,fv,'-k',LW,2); axis([-1 1 ifv afv]) hold on h1 = plot(t, fv, '-b', LW, 2); h2 = plot(t, F(t)*0, '-r', LW, 2); shg legend('original function', 'interpolant', 'difference') while 1 % keep clicking! if ( ~isempty(x) ) plot(x,F(x),'.b',MS,20,'HandleVisibility','off') % plot interpolation points plot(x,0,'*k',MS,6,'HandleVisibility','off') % plot x values alone p = polyfit(x, F(x), length(x)-1); f = polyval(p, t); h1.YData = f; h2.YData = f-fv; axis([-1 1 ifv afv]) drawnow shg end [gx, ~, button] = ginput(1); % input new interpolation point if ( button == 3 ) break, end % if right button, stop x = unique([x; gx]); % #ok<AGROW> end end

Assignment

讓使用者任意在螢幕上按順序以滑鼠指定六個點, 並將此六點以直線連線. 找到一條多項式曲線

γ(t)=(P1(t),P2(t)) 使此多項式曲線很接近六點的直線連線.