MATH661 HW06 -
Interpolation |
|
Posted: 10/11/23
Due: 10/18/23, 11:59PM
Beginning with this assignment, homework tasks are described at a
higher level. Apply your experience from previous assignments to
cogently formulate a solution.
1Track 1 & 2
Study the convergence of polynomial interpolation, ,
with increasing number of sample points
for the following functions:
-
, ;
-
, ;
-
, .
For each case consider both equidistant and Chebyshev sample points,
present plots of the function and interpolant, plots of the error as a
function of , and compare the observed
error with that predicted by the formula
Comment on what you observe.
Solution. Use functions from L19 to
obtain results in Fig. 1.
|
|
Figure 1. Interpolation results for
equidistant partitions of
|
∴ |
function MonomialBasis(t,n)
m=size(t)[1]; A=ones(m,1);
for j=1:n-1
A = [A t.^j]
end
return A
end; |
∴ |
function plotInterp(a,b,f,Basis,m,n,M,txt)
data=sample(a,b,f,m); t=data[1]; y=data[2]
Data=sample(a,b,f,M); T=Data[1]; Y=Data[2]
A = Basis(t,n); c = A\y; z = Basis(T,n)*c
plot(t,y,"ok",T,z,"-r",T,Y,"-b"); grid("on");
xlabel("t"); ylabel("y");
title(txt)
end; |
∴ |
function sample(a,b,f,m)
t = LinRange(a,b,m); y = f.(t)
return t,y
end; |
∴ |
c(t)=cos(pi*t/2); f(t)=1/(1+25*t^2); g(t)=exp(-(5*t)^2); |
∴ |
FigPrefix=homedir()*"/courses/MATH661/homework/H06/"; |
∴ |
clf(); plotInterp(-1,1,c,MonomialBasis,10,10,100,"Interpolant of c"); |
∴ |
plotInterp(-1,1,c,MonomialBasis,20,20,100,"Interpolant of c"); |
∴ |
savefig(FigPrefix*"Fig01a.eps") |
∴ |
clf(); plotInterp(-1,1,f,MonomialBasis,8,8,100,"Interpolant of f"); |
∴ |
plotInterp(-1,1,f,MonomialBasis,10,10,100,"Interpolant of f"); |
∴ |
plotInterp(-1,1,f,MonomialBasis,12,12,100,"Interpolant of f"); |
∴ |
savefig(FigPrefix*"Fig01b.eps") |
∴ |
clf(); plotInterp(-1,1,g,MonomialBasis,8,8,100,"Interpolant of g"); |
∴ |
plotInterp(-1,1,g,MonomialBasis,10,10,100,"Interpolant of g"); |
∴ |
plotInterp(-1,1,g,MonomialBasis,12,12,100,"Interpolant of g"); |
∴ |
savefig(FigPrefix*"Fig01c.eps") |
|
|
Figure 2. Interpolation results for
Chebyshev partitions of
|
∴ |
function MonomialBasis(t,n)
m=size(t)[1]; A=ones(m,1);
for j=1:n-1
A = [A t.^j]
end
return A
end; |
∴ |
function plotInterp(a,b,f,Basis,m,n,M,txt)
data=Csample(a,b,f,m); t=data[1]; y=data[2]
Data=sample(a,b,f,M); T=Data[1]; Y=Data[2]
A = Basis(t,n); c = A\y; z = Basis(T,n)*c
plot(t,y,"ok",T,z,"-r",T,Y,"-b"); grid("on");
xlabel("t"); ylabel("y");
title(txt)
end; |
∴ |
function Csample(a,b,f,m)
i = 1:m; θ = (2 .* i .- 1)*pi/(2*m) ;
t = (cos.(θ) .+ 1)*(b-a)/2 .+ a; y = f.(t)
return t,y
end; |
∴ |
function sample(a,b,f,m)
t = LinRange(a,b,m); y = f.(t)
return t,y
end; |
∴ |
c(t)=cos(pi*t/2); f(t)=1/(1+25*t^2); g(t)=exp(-(5*t)^2); |
∴ |
FigPrefix=homedir()*"/courses/MATH661/homework/H06/"; |
∴ |
clf(); plotInterp(-1,1,c,MonomialBasis,10,10,100,"Interpolant of c"); |
∴ |
plotInterp(-1,1,c,MonomialBasis,20,20,100,"Interpolant of c"); |
∴ |
savefig(FigPrefix*"Fig02a.eps") |
∴ |
clf(); plotInterp(-1,1,f,MonomialBasis,8,8,100,"Interpolant of f"); |
∴ |
plotInterp(-1,1,f,MonomialBasis,10,10,100,"Interpolant of f"); |
∴ |
plotInterp(-1,1,f,MonomialBasis,12,12,100,"Interpolant of f"); |
∴ |
savefig(FigPrefix*"Fig02b.eps") |
∴ |
clf(); plotInterp(-1,1,g,MonomialBasis,8,16,100,"Interpolant of g"); |
∴ |
plotInterp(-1,1,g,MonomialBasis,10,20,100,"Interpolant of g"); |
∴ |
plotInterp(-1,1,g,MonomialBasis,12,34,100,"Interpolant of g"); |
∴ |
savefig(FigPrefix*"Fig02c.eps") |
Observations. For both equidistant and Chebyshev
sampling interpolation converges with increasing
for . For both other functions the error
grows without bound away from the interpolation data points, albeit
slower for Chebyshev sampling. This is suggested from the error formula
by bounding derivatives and
for .
-
, has a readily determined
derivative bound ,
-
. The first few derivatives are
Notice that
has a local extremum at
for which ,
and
gives a rapidly increasing error bound.
-
As above, repeated differentiation suggests a rapidly increasing
upper bound .
2Track 1
For
equidistant sample points, explicitly write the Lagrange and Newton
forms of the interpolating polynomial.
Solution 1. Choose
for
to obtain interpolations of data
Construct table of divided differenes for Newton
form
3Track 2
Repeat the above convergence study for Hermite interpolation , ,
.
Solution. Modify functions from L19 to
obtain results in Fig. 3. Overall behavior is as in regular
interpolation in function values, but with more accurate results for
the Chebyshev points for the Runge function.
|
|
Figure 3. Interpolation results for
equidistant partitions of
|
∴ |
function MonomialBasis(t,n)
m=size(t)[1]; D0=ones(m,1); D1=zeros(m,1); a=[D0; D1]; A=a;
for j=1:2*n-1
D0=t.^j; D1=j*t.^(j-1); a = [D0; D1]
A = [A a]
end
return A
end; |
∴ |
function plotInterp(a,b,f,df,Basis,m,n,M,txt)
data=sample(a,b,f,df,m); t=data[1]; y=data[2]; yp=data[3];
Data=sample(a,b,f,df,M); T=Data[1]; Y=Data[2]; Yp=Data[3];
A = Basis(t,n); a = A\[y; yp]; z = Basis(T,n)*a
plot(t,y,"ok",T,z[1:M],"-r",T,Y[1:M],"-b"); grid("on");
xlabel("t"); ylabel("y");
title(txt)
end; |
∴ |
function sample(a,b,f,df,m)
t = LinRange(a,b,m); y = f.(t); yp = df.(t)
return t,y,yp
end; |
∴ |
c(t)=cos(pi*t/2); f(t)=1/(1+25*t^2); g(t)=exp(-(5*t)^2); |
∴ |
dc(t)=-pi/2*sin(pi*t/2); df(t)=-50*t/(1+25*t^2)^2; dg(t)=-50*t*exp(-(5*t)^2); |
∴ |
FigPrefix=homedir()*"/courses/MATH661/homework/H06/"; |
∴ |
clf(); plotInterp(-1,1,c,dc,MonomialBasis,10,10,100,"Interpolant of c"); |
∴ |
plotInterp(-1,1,c,dc,MonomialBasis,20,20,100,"Interpolant of c"); |
∴ |
savefig(FigPrefix*"Fig03a.eps") |
∴ |
clf(); plotInterp(-1,1,f,df,MonomialBasis,8,8,100,"Interpolant of f"); |
∴ |
plotInterp(-1,1,f,df,MonomialBasis,10,10,100,"Interpolant of f"); |
∴ |
plotInterp(-1,1,f,df,MonomialBasis,12,12,100,"Interpolant of f"); |
∴ |
savefig(FigPrefix*"Fig03b.eps") |
∴ |
clf(); plotInterp(-1,1,g,dg,MonomialBasis,8,8,100,"Interpolant of g"); |
∴ |
plotInterp(-1,1,g,dg,MonomialBasis,10,10,100,"Interpolant of g"); |
∴ |
plotInterp(-1,1,g,dg,MonomialBasis,12,12,100,"Interpolant of g"); |
∴ |
savefig(FigPrefix*"Fig03c.eps") |
|
|
Figure 4. Interpolation results for
Chebyshev partitions of
|
∴ |
function MonomialBasis(t,n)
m=size(t)[1]; D0=ones(m,1); D1=zeros(m,1); a=[D0; D1]; A=a;
for j=1:2*n-1
D0=t.^j; D1=j*t.^(j-1); a = [D0; D1]
A = [A a]
end
return A
end; |
∴ |
function plotInterp(a,b,f,df,Basis,m,n,M,txt)
data=Csample(a,b,f,df,m); t=data[1]; y=data[2]; yp=data[3];
Data=sample(a,b,f,df,M); T=Data[1]; Y=Data[2]; Yp=Data[3];
A = Basis(t,n); a = A\[y; yp]; z = Basis(T,n)*a
plot(t,y,"ok",T,z[1:M],"-r",T,Y[1:M],"-b"); grid("on");
xlabel("t"); ylabel("y");
title(txt)
end; |
∴ |
function Csample(a,b,f,df,m)
i = 1:m; θ = (2 .* i .- 1)*pi/(2*m) ;
t = (cos.(θ) .+ 1)*(b-a)/2 .+ a; y = f.(t); yp = df.(t)
return t,y,yp
end; |
∴ |
function sample(a,b,f,df,m)
t = LinRange(a,b,m); y = f.(t); yp = df.(t)
return t,y,yp
end; |
∴ |
c(t)=cos(pi*t/2); f(t)=1/(1+25*t^2); g(t)=exp(-(5*t)^2); |
∴ |
dc(t)=-pi/2*sin(pi*t/2); df(t)=-50*t/(1+25*t^2)^2; dg(t)=-50*t*exp(-(5*t)^2); |
∴ |
FigPrefix=homedir()*"/courses/MATH661/homework/H06/"; |
∴ |
clf(); plotInterp(-1,1,c,dc,MonomialBasis,10,10,100,"Interpolant of c"); |
∴ |
plotInterp(-1,1,c,dc,MonomialBasis,20,20,100,"Interpolant of c"); |
∴ |
savefig(FigPrefix*"Fig04a.eps") |
∴ |
clf(); plotInterp(-1,1,f,df,MonomialBasis,8,8,100,"Interpolant of f"); |
∴ |
plotInterp(-1,1,f,df,MonomialBasis,10,10,100,"Interpolant of f"); |
∴ |
plotInterp(-1,1,f,df,MonomialBasis,12,12,100,"Interpolant of f"); |
∴ |
savefig(FigPrefix*"Fig04b.eps") |
∴ |
clf(); plotInterp(-1,1,g,dg,MonomialBasis,8,16,100,"Interpolant of g"); |
∴ |
plotInterp(-1,1,g,dg,MonomialBasis,10,20,100,"Interpolant of g"); |
∴ |
plotInterp(-1,1,g,dg,MonomialBasis,12,34,100,"Interpolant of g"); |
∴ |
savefig(FigPrefix*"Fig04c.eps") |