Homework Set 5 Solutions - Numerical Analysis | MATH 128A, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Material Type: Assignment; Class: Numerical Analysis; Subject: Mathematics; University: University of California - Berkeley; Term: Spring 2003;

Typology: Assignments

Pre 2010

Uploaded on 10/01/2009

koofers-user-pda-1
koofers-user-pda-1 🇺🇸

10 documents

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Homework set #5 solutions, Math 128A
J. Xia
Sec 3.4: 1, 7, 15, 17, 22*, 25
1. Let the free cubic spline
S(x) = ½S0(x) = a0+b0(x0) + c0(x0)2+d0(x0)3,0x1
S1(x) = a1+b1(x1) + c1(x1)2+d1(x1)3,1x2.
Then
S0(0) = f(0), S0(1) = f(1), S1(1) = f(1), S1(2) = f(2),
S0
0(1) = S0
1(1), S00
0(1) = S00
1(1),
S00
0(0) = 0, S00
1(2) = 0.
We then get a linear system of equations in the same order as the equations above
1
1 1 1 1
1
1 1 1 1
123 1
2 6 2
2
2 6
a0
b0
c0
d0
a1
b1
c1
d1
=
0
1
1
2
0
0
0
0
We get
a0= 0, b0= 1, c0= 0, d0= 0, a1= 1, b1= 1, c1= 0, d1= 0,
i.e.
S(x)x.
7. Use
S0
0(1) = S0
1(1), S00
0(1) = S00
1(1), S00
1(2) = 0
to get three equations with three unknowns. Solve them. b=1, c =3, d = 1.
15. Let f(x) = a+bx +cx2+dx3. For any point x,finterpolates itself. It’s easy
to verify that conditions (a-e), and (ii) of (f) in definition 3.10 hold. Thus fis its
own clamped cubic spline.
Now assume fis a natural cubic spline, then f00(x) = 2c+ 6dx = 0. This can
only hold at one single point x=c
3d, instead of two. Thus (i) of (f) cannot be
satisfied and fcannot be a natural cubic spline.
17. The linear interpolatng function through two points (0, f(0) and (0.05, f (0.05)
is
S0(x) = f(0)x0.05
00.05 +f(0.05) x0
0.05 0=20x+1+e0.120x, x [0,0.05].
1
pf3
pf4

Partial preview of the text

Download Homework Set 5 Solutions - Numerical Analysis | MATH 128A and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

Homework set #5 solutions, Math 128A

J. Xia

Sec 3.4: 1, 7, 15, 17, 22*, 25

  1. Let the free cubic spline

S(x) =

S 0 (x) = a 0 + b 0 (x − 0) + c 0 (x − 0)^2 + d 0 (x − 0)^3 , 0 ≤ x ≤ 1 S 1 (x) = a 1 + b 1 (x − 1) + c 1 (x − 1)^2 + d 1 (x − 1)^3 , 1 ≤ x ≤ 2

Then

S 0 (0) = f (0), S 0 (1) = f (1), S 1 (1) = f (1), S 1 (2) = f (2), S 0 ′(1) = S 1 ′(1), S′′ 0 (1) = S′′ 1 (1), S 0 ′′ (0) = 0, S′′ 1 (2) = 0.

We then get a linear system of equations in the same order as the equations above

       

a 0 b 0 c 0 d 0 a 1 b 1 c 1 d 1

We get

a 0 = 0, b 0 = 1, c 0 = 0, d 0 = 0, a 1 = 1, b 1 = 1, c 1 = 0, d 1 = 0,

i.e. S(x) ≡ x.

  1. Use S′ 0 (1) = S 1 ′(1), S 0 ′′ (1) = S 1 ′′ (1), S 1 ′′ (2) = 0

to get three equations with three unknowns. Solve them. b = − 1 , c = − 3 , d = 1.

  1. Let f (x) = a + bx + cx^2 + dx^3. For any point x, f interpolates itself. It’s easy to verify that conditions (a-e), and (ii) of (f) in definition 3.10 hold. Thus f is its own clamped cubic spline. Now assume f is a natural cubic spline, then f ′′(x) = 2c + 6dx = 0. This can only hold at one single point x = − 3 cd , instead of two. Thus (i) of (f) cannot be satisfied and f cannot be a natural cubic spline.
  2. The linear interpolatng function through two points (0, f (0) and (0. 05 , f (0.05) is

S 0 (x) = f (0) x − 0. 05 0 − 0. 05

  • f (0.05) x − 0
  1. 05 − 0

= − 20 x + 1 + e^0.^120 x, x ∈ [0, 0 .05].

Similarly the linear interpolatng function through two points (0. 05 , f (0.05) and (0. 1 , f (0.1)) is

S 1 (x) = 20(e^0.^2 − e^0.^1 )x + 2e^0.^1 − e^0.^2 , x ∈ (0. 05 , 0 .1].

The piecewise linear approximation F (x) to f is given by S 0 (x) and S 1 (x). Thus (^) ∫ (^0). 1

0

F (x)dx = 0. 1107936.

The actual integral (^) ∫

  1. 1

0

f (x)dx = 0. 1107014.

  1. Contitions (i) and (ii) lead to five equations with six variables

a 0 = f (x 0 ) a 1 = f (x 1 ) a 1 + b 1 (x 2 − x 1 ) + c 1 (x 2 − x 1 )^2 = f (x 2 ) a 0 + b 0 (x 1 − x 0 ) + c 0 (x 1 − x 0 )^2 − a 1 = 0 (⇐= S 0 (x 1 ) = S 1 (x 1 )) b 0 + 2c 0 (x 1 − x 0 ) − b 1 = 0 (⇐= S′ 0 (x 1 ) = S 1 ′(x 1 )).

So we need an additional condition to make the solution unique. Considering the condition S ∈ C^2 [x 0 , x 2 ], we get an extra condition

c 0 − c 1 = 0 (⇐= S′′ 0 (x 1 ) = S 1 ′′ (x 1 )).

Eliminate a 0 , a 1 , c 1 (= c 0 ) and write the rest equations in matrix form  

(x 2 − x 1 )^2 x 2 − x 1 x 1 − x 0 (x 1 − x 0 )^2 1 2(x 1 − x 0 ) − 1

b 0 c 0 b 1

f (x 2 ) − f (x 1 ) −f (x 0 ) + f (x 1 ) 0

The determinant of the coefficient matrix is (x 2 − x 1 )(x 1 − x 0 )(x 2 − x 0 ) 6 = 0 be- cause the three points are distinct. Thus the coefficient matrix is invertible. There is always a unique solution for the above linear system. And the problem has a meaningful solution then.

  1. a. Program the clampled cubic spline. Or do it in matlab. Suppose the spline is Si(x) = ai + bi(x − xi) + ci(x − xi)^2 + di(x − xi)^3 , x ∈ [xi, xi+1].

Run

x = [0 3 5 8 13]; y = [0 225 383 623 993]; cs = spline(x,[75 y 72]) This will give the output of the infomation about the cubic spline. cs = form: ’pp’ breaks: [0 3 5 8 13] coefs: [4x4 double] pieces: 4

(^11 2 3 4 5 6 7 )

2

3

4

5

6

7

8

a1(nn)=3(xgpl(nn)-x(nn)); b1(nn)=3(ygpl(nn)-y(nn)); a2(nn)=3(x(nn)+xgpr(nn+1)-2xgpl(nn)); b2(nn)=3(y(nn)+ygpr(nn+1)-2ygpl(nn)); a3(nn)=x(nn+1)-x(nn)+3xgpl(nn)-3xgpr(nn+1); b3(nn)=y(nn+1)-y(nn)+3ygpl(nn)-3ygpr(nn+1); end syms t for i = 1: [’x(i):’ a0(i)+a1(i)t+a2(i)t.^2+a3(i)t.^ ... ’y(i):’ b0(i)+b1(i)t+b2(i)t.^2+b3(i)t.^3] end

This will output the Bezier polynomial. The polynomials are(the original output is in fractional form)

i x(i) y(i) 0 3 + 9. 9 t − 30. 3 t^2 + 19. 4 t^3 6 + 19. 5 t − 58. 5 t^2 + 35t^3 1 2 + 8. 4 t − 19. 8 t^2 + 15. 4 t^3 2 + 9t − 23. 4 t^2 + 18. 4 t^3 2 6 + 17. 4 t − 51. 3 t^2 + 32. 9 t^3 6 + 15t − 49. 5 t^2 + 30. 5 t^3 3 5 + 16. 5 t − 47. 7 t^2 + 32. 7 t^3 2 + 6. 6 t − 18. 6 t^2 + 13t^3

Use the following command to plot the curve(I’m keeping the format of output of the previous code for the polynomials). Note for each piece, the interval for t is always [0, 1]. The curve is as above. t = 0:0.1:1; plot(3+99/10t-303/10t.^2+97/5t.^3, 6+39/2t-117/2t.^2+35t.^3, ... 2+42/5t-99/5t.^2+77/5t.^3, 2+9t-117/5t.^2+92/5t.^3, ... 6+87/5t-513/10t.^2+329/10t.^3, 6+15t-99/2t.^2+61/2t.^3, ... 5+33/2t-477/10t.^2+327/10t.^3, 2+33/5t-93/5t.^2+13t.^3, ... x(1:5),y(1:5),’O’)