


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Numerical Analysis; Subject: Mathematics; University: University of California - Berkeley; Term: Spring 2003;
Typology: Assignments
1 / 4
This page cannot be seen from the preview
Don't miss anything!



J. Xia
Sec 3.4: 1, 7, 15, 17, 22*, 25
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.
to get three equations with three unknowns. Solve them. b = − 1 , c = − 3 , d = 1.
S 0 (x) = f (0) x − 0. 05 0 − 0. 05
= − 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 (^) ∫
0
f (x)dx = 0. 1107014.
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.
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’)