Numerical Analysis

Midterm Problem Set 2 Solutions

II.

> with(CurveFitting);

[BSpline, BSplineCurve, LeastSquares, PolynomialInt...
[BSpline, BSplineCurve, LeastSquares, PolynomialInt...

> xlist:=[0.0,0.04,0.14,0.21,1.22,1.5,1.93];

xlist := [0., .4e-1, .14, .21, 1.22, 1.5, 1.93]

> ylist:=[0.0,.849,1.894,1.986,1.895,1.5,.694];

ylist := [0., .849, 1.894, 1.986, 1.895, 1.5, .694]...

> IP:=PolynomialInterpolation(xlist,ylist,x);

IP := .4364997009e-1*x^6+15.81479567*x^5+25.0094581...
IP := .4364997009e-1*x^6+15.81479567*x^5+25.0094581...

free spline:

> FSp:=Spline(xlist,ylist,x);

FSp := PIECEWISE([22.51547262*x-806.5453890*x^3, x ...

> plot({FSp,IP},x=0..2);

[Maple Plot]

clamped spline: use forward difference at x[0] and a backward difference at x[6]

> df0:=(ylist[2]-ylist[1])/(xlist[2]-xlist[1]);

df0 := 21.22500000

> dfn:=(ylist[7]-ylist[6])/(xlist[7]-xlist[6]);

dfn := -1.874418605

> read "/home/fac/little/public_html/Num01/ClampedSpline.map";

> CSp:=clampedspline(xlist,ylist,df0,dfn,x);

CSp := PIECEWISE([21.22500000*x+52.59482560*x^2-131...
CSp := PIECEWISE([21.22500000*x+52.59482560*x^2-131...
CSp := PIECEWISE([21.22500000*x+52.59482560*x^2-131...
CSp := PIECEWISE([21.22500000*x+52.59482560*x^2-131...
CSp := PIECEWISE([21.22500000*x+52.59482560*x^2-131...
CSp := PIECEWISE([21.22500000*x+52.59482560*x^2-131...

> plot({CSp,IP},x=0..2);

[Maple Plot]

IV.

> f:=x->sqrt(1+cos(x)^2);

f := proc (x) options operator, arrow; sqrt(1+cos(x...

> plot(abs(diff(f(x),x$2)),x=0..48);

[Maple Plot]

> plot(abs(diff(f(x),x$4)),x=0..48);

[Maple Plot]

Error bound for composite Trapezoidal Rule:

> fsolve(1/12*48*h^2=.0001,h);

-.5000000000e-2, .5000000000e-2

> nvaltrap:=200*48;

nvaltrap := 9600

Error bound for composite Simpson's Rule:

> hvalsimp:=fsolve(7/180*48*h^4=.0001,h);

hvalsimp := -.8555261858e-1, .8555261858e-1

> nvalsimp:=48/hvalsimp[2];

nvalsimp := 561.0582211

> with(student):

> approx:=evalf(simpson(f(x),x=0..48,562));

approx := 58.47046966

> exact:=evalf(Int(f(x),x=0..48));

exact := 58.47046915

> simperror:=abs(exact-approx);

simperror := .51e-6

>