程序代写案例-OMEWORK 3

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
HOMEWORK 3 SOLUTIONS (MATH 170B, WINTER 2022)
DUE DATE: SEE CANVAS
REVISION NUMBER: 3.0
INSTRUCTOR: Prof. Michael Holst
BOOKS:
[1] D. Kinc
aid and W. Cheney. Numerical Analysis: Mathematics of Scientific Computing. Third. Providence, RI: American Mathematical
Society, 2017.
MATERIAL COVERED BY HOMEWORK 3: This homework covers mainly material from lectures in weeks three and four, covering roughly
the following sections of [1]: 6.4, 6.5, 6.6, 6.7, 6.8.
SUBMITTING HOMEWORK ON GRADESCOPE: For non-computer problems, create a PDF file of your work by whatever means you prefer
(scanning handwritten work with your phone, or using LaTeX to typeset your mathematics, either is fine), and upload that PDF to Gradescope. For
computer problems, take a screen shot of both your MATLAB functions (the code you write) and the output they produce, and upload that PDF to
Gradescope.
OUR HOMEWORK RULES ALWAYS APPLY: As discussed in detail on the syllabus, you are allowed (encouraged) to discuss homework
problems with other students in our class, but you must write up your own solutions yourself. You are not allowed to post these questions, or their
solutions, on homework help websites (such as Chegg.com) or other websites.
[Q1] (Section 6.4: Problem 6.4.7)
(a) Determine all the values of a, b, c, d, e for which the following function is a cubic
spline:
fpxq “
$&% apx´ 2q
2 ` bpx´ 1q3, x P p´8, 1s
cpx´ 2q2, x P r1, 3s
dpx´ 2q2 ` epx´ 3q3, x P r3,8s.
(b) Determine the values of the parameters so that the cubic spline interpolates this data:
x 0 1 4
y 26 7 25
(Hint: Just impose all the spline conditions.)
Solution:
(a) Denote S0pxq “ apx´2q2`bpx´1q3, S1pxq “ cpx´2q2, S2pxq “ dpx´2q2`epx´3q3.
Enforce
Si´1ptiq “ Siptiq, S 1i´1ptiq “ S 1iptiq and S2i´1ptiq “ S2i ptiq
for points t1 “ 1, t2 “ 3 and i “ 1, 2.
Then we obtain the result a “ c “ d. For any a “ c “ d and arbitrary values of b, e,
the function f is a cubic spline.
(b) Add the equations of interpolation fp0q “ 26, fp1q “ 7, fp4q “ 25, we have
4a` b “ 26
a “ c “ d “ 7
4d` e “ 25
Solve the above system we get the answer a “ 7, b “ ´2, c “ 7, d “ 7, e “ ´3.
1
2 REFERENCES
[Q2] (Section 6.4: Problem 6.4.11)
(a) Determine the values of a, b, c so this is a cubic spline having knots 0, 1, 2:
fpxq “
"
3` x´ 9x2, x P r0, 1s
a` bpx´ 1q ` cpx´ 1q2 ` dpx´ 1q3, x P r1, 2s
(b) Determine d so that
ş2
0
rf2pxqs2 dx is minimized.
(c) Find d so that f2p2q “ 0; why is d different from d in part (b)?
(Hint: The first part is just applying the spline conditions; the second part is first-quarter calculus,
and the last part is again appling a spline condition.)
Solution:
(a) Denote
S0pxq “ 3` x´ 9x2
S1pxq “ a` bpx´ 1q ` cpx´ 1q2 ` dpx´ 1q3.
Then
S 10pxq “ 1´ 18x S20pxq “ ´18
S 11pxq “ b` 2cpx´ 1q ` 3dpx´ 1q2 S21pxq “ 2c` 6dpx´ 1q
For f to be a cubic spline, we must have
S0p1q “ S1p1q ùñ ´5 “ a
and
S 10p1q “ S 11p1q ùñ ´17 “ b
and
S20p1q “ S21p1q ùñ ´18 “ 2c ùñ ´9 “ c.
So f is a cubic spline when a “ ´5 , b “ ´17 , c “ ´9 , and d is any real number.
(b) First, calculateż 2
0
rf2pxqs2 dx “
ż 1
0
rS20pxqs2 dx`
ż 2
1
rS21pxqs2 dx

ż 1
0
r´18s2 dx`
ż 2
1
r2c` 6dpx´ 1qs2 dx

ż 1
0
324 dx`
ż 2
1
r4c2 ` 24cdpx´ 1q ` 36d2px´ 1q2s dx
“ 324x
ˇˇˇ1
0
` `4c2x` 12cdpx´ 1q2 ` 12d2px´ 1q3˘ˇˇˇ2
1
“ 324` 8c2 ` 12cd` 12d2 ´ 4c2
“ 324` 4c2 ` 12cd` 12d2.
To find d that minimizes this, set the derivative with respect to d equal to 0:
12c` 24d “ 0 ùñ 24d “ ´12c ùñ d “ ´ c
2
.
REFERENCES 3
Since c “ ´9 from part (a), d “ 9
2
minimizes
ş2
0
rf2pxqs2 dx.
(c) Note that
f2p2q “ 0 ùñ 2c` 6d “ 0 ùñ 6d “ ´2c ùñ d “ ´ c
3
.
Since c “ ´9 from part (a), d “ 3 gives f2p2q “ 0. Recall that a natural cubic spline
(where f2pt0q “ 0 “ f2ptnq) minimizes
ştn
t0
rf2pxqs2 dx. However, this function f
cannot be a natural cubic spline because f2p0q “ ´18 ‰ 0, which is why the d that
minimizes
ş2
0
rf2pxqs2 dx is not the same d that gives f2p2q “ 0.
[Q3] (Section 6.4: Problem 6.4.24)
If S is a linear spline interpolating f at the knots 0 “ t0 ă t1 ă ¨ ¨ ¨ ă tn “ 1, calculate:ż 1
0
Spxq dx.
(Hint: Use linearity of the integral and the fact that you know how to exactly integrate polynomials
of any order. What you compute is quite interesting, and will be studied in Chapter 7.)
Solution: ż 1
0
Spxq “
nÿ
i“1
ż ti
ti´1
Si´1pxq dx

nÿ
i“1
ż ti
ti´1
ai´1x` bi´1 dx

nÿ
i“1
rai´1
2
pt2i ´ t2i´1q ` bi´1pti ´ ti´1qs dx

nÿ
i“1
1
2
rpai´1ti´1 ` bi´1q ` ai´1ti ` bi´1spti ´ ti´1q
“ 1
2
nÿ
i“1
rSi´1ptiq ` Si´1pti´1qspti ´ ti´1q
4 REFERENCES
[Q4] (Section 6.4: Computer Problem 6.4.4)
Write (and test) a MATLAB program to compute the cubic spline function S having the
prescribed knots t0 ă t1 ă . . . ă tn and satisfying:
Sptiq “ yi, 0 ď i ď n,
S2pt0q “ α,
S2ptnq “ β.
(Hint: Note that setting α “ β “ 0 gives you the natural cubic spline; your program will be able to
compute that spline, but your program can also compute more general splines.)
Solution: This first MATLAB program computes the second derivatives S2ptiq “ zi.
1 function [z,h] = cubic_spline_z(t,y,alpha,beta)
2
3 n = length(t)-1;
4 h = zeros(n,1);
5 b = zeros(n,1);
6 for i=1:n
7 h(i) = t(i+1)-t(i);
8 b(i) = 6*(y(i+1)-y(i))/h(i);
9 end
10
11 u = zeros(n,1);
12 v = zeros(n,1);
13 u(2) = 2*(h(1)+h(2));
14 v(2) = b(2)-b(1);
15 for i=3:n
16 u(i) = 2*(h(i)+h(i-1)) - h(i-1)ˆ2/u(i-1);
17 v(i) = b(i)-b(i-1) - h(i-1)*v(i-1)/u(i-1);
18 end
19
20 z = zeros(n+1,1);
21 z(n+1) = beta;
22 for i=n:-1:2
23 z(i) = (v(i)-h(i)*z(i+1))/u(i);
24 end
25 z(1) = alpha;
REFERENCES 5
This second MATLAB program computes the coefficients in the nested formula Sipxq “
yi ` px´ tiq

Ci ` px´ tiq

Bi ` px´ tiqAi
‰ı
.
1 function [A,B,C] = cubic_spline_ABC(t,y,alpha,beta)
2
3 [z,h] = cubic_spline_z(t,y,alpha,beta);
4
5 n = length(t)-1;
6 A = zeros(n,1);
7 B = zeros(n,1);
8 C = zeros(n,1);
9 for i=1:n
10 A(i) = (z(i+1)-z(i))/(6*h(i));
11 B(i) = z(i)/2;
12 C(i) = -h(i)*z(i+1)/6 - h(i)*z(i)/3 + (y(i+1)-y(i))/h(i)
;
13 end
This final MATLAB program computes and plots Spxq.
1 function S = cubic_spline(t,y,alpha,beta,x)
2
3 [A,B,C] = cubic_spline_ABC(t,y,alpha,beta);
4
5 n = length(t)-1;
6 m = length(x);
7 S = zeros(m,1);
8 for j=1:m
9 % determine which interval
10 if x(j)11 i = 1;
12 elseif x(j)>=t(n)
13 i = n;
14 else
15 i = find(x(j)=t(1:n)));
16 end
17 S(j) = y(i) + (x(j)-t(i))*(C(i) + (x(j)-t(i))*(B(i) + (x(
j)-t(i))*A(i)));
18 end
19
20 figure
21 hold on
22 plot(x,S,'r','linewidth',2)
23 plot(t,y,'b+','linewidth',2)
6 REFERENCES
Here is an example of testing the program.
1 t = [0 1 3 7 10];
2 y = [4 2 8 5 1];
3 alpha = 1;
4 beta = -3;
5 x = -1:0.25:11;
6 S = cubic_spline(t,y,alpha,beta,x)
REFERENCES 7
[Q5] (Section 6.6: Related to Problem 6.5.20)
Show that the modulus of continuity used in Chapter 6 (and elsewhere), which is defined as
ωpf ; δq “ max
|s´t|ďδ
|fpsq ´ fptq|,
has these useful properties:
(a) ωpf ; δ1q ď ωpf ; δ2q, when 0 ă δ1 ď δ2.
(b) ωpf ; δ1 ` δ2q ď ωpf ; δ1q ` ωpf ; δ2q.
(c) ωpf ; kδq ď kωpf ; δq, k P N.
(Hint: These properties of the modulus of continuity of a function are used to prove various things
about splines and other types of approximation. This is a fun little self-contained exercise like a
push-up, and doing it makes us stronger. To show these, try breaking up the intervals.)
Solution:
(a) Since δ1 ď δ2, we know |s ´ t| ď δ1 ď δ2, so that |s ´ t| ď δ2. Thus, we have a very
clear inclusion relationship between the following two sets of differences of f , where
the set on the left is drawing s and t from a subinterval of where the set on the right is
drawing them from:
t|fpsq ´ fptq| : |s´ t| ď δ1 ď δ2u Ď t|fpsq ´ fptq| : |s´ t| ď δ2u.
Since the modulus is defined as the maximum value from these sets:
ωpf ; δq “ max
|s´t|ďδ
|fpsq ´ fptq|,
we can conclude that: ωpf ; δ1q ď ωpf ; δ2q.
(b) To begin, if we know that if s, t P R and |s ´ t| ď δ1 ` δ2, then a property of real
numbers is that there must exist a third point u P R such that:
|s´ u| ď δ1, and |u´ t| ď δ2.
(A related fact is that equality holds in the triangular inequality, |a ` b| “ |a| ` |b|,
when a, b have the same sign; a fun little problem is to prove that.) Let’s now look at
the variation of f at s and t, but insert this third point u and use the triangle inequality:
|fpsq ´ fptq| ď |fpsq ´ fpuq| ` |fpuq ´ fptq|.
Let’s now take the max of this difference over the combined interval:
ωpf ; δ1 ` δ2q “ max|s´t|ďδ1`δ2 |fpsq ´ fptq|
“ max
|s´u|ďδ1, |u´t|ďδ2
|fpsq ´ fpuq ` fpuq ´ fptq|
ď max
|s´u|ďδ1, |u´t|ďδ2
r|fpsq ´ fpuq| ` |fpuq ´ fptq|s
“ max
|s´u|ďδ1
|fpsq ´ fpuq| ` max
|u´t|ďδ2
|fpuq ´ fptq|
“ ωpf ; δ1q ` ωpf ; δ2q.
8 REFERENCES
(c) The easiest proof uses part (b) together with induction.
Case of k “ 0: We can confirm easily that ωpf ; 0 ¨ δq “ 0 “ 0 ¨ ωpf ; δq, so that the
inequality holds for k “ 0.
Case that k “ n ùñ k “ n` 1: Now suppose the inequality holds when k “ n:
ωpf ;nδq ď nωpf ; δq.
We now show that this implies is also holds for k “ n` 1:
ωpf ; pn` 1qδq “ ωpf ;nδ ` δq
ď ωpf ;nδq ` ωpf ; δq (using part (b) here)
ď nωpf ; δq ` ωpf ; δq (using that it holds for k “ n)
“ pn` 1qωpf ; δq,
where we have used the result from part (b) for the first inequality, and then assumption
that the inquality holds for k “ n for the second inequality.
Induction: Finally, by induction on k, the result holds for all k P N.
[Q6] (Section 6.7: Problem 6.7.1)
Show that
ř8
k“0 akx
k and
ř8
k“0 akpx´cqk have the same radius of convergence. For p P N
a (finite) natural number, what about
ř8
k“0 akpx´ cqk`p ?
(Hint: Background for this question is Section 6.7; relevant material is also in your calculus text.)
Solution: Define fpxq “ ř8k“0 akxk and suppose f has radius of convergence r. Also
define gpxq “ ř8k“0 akpx´ cqk. Note that
gpxq “
8ÿ
k“0
akpx´ cqk “ fpx´ cq
for all x. So, if |x ´ c| ă r then gpxq converges because fpx ´ cq converges (since f has
radius of convergence r). Similarly, if |x ´ c| ą r then gpxq diverges because fpx ´ cq
diverges. This shows that gpxq “ ř8k“0 akpx´ cqk also has radius of convergence r.
Next, define hpxq “ ř8k“0 akpx´ cqk`p. Note that
hpxq “
8ÿ
k“0
akpx´ cqk`p “ px´ cqp
8ÿ
k“0
akpx´ cqk “ px´ cqpgpxq
for all x. So, if |x´ c| ă r then hpxq converges because gpxq converges (since g has radius
of convergence r). Similarly, if |x´ c| ą r then hpxq diverges because gpxq diverges. This
shows that hpxq “ ř8k“0 akpx´ cqk`p also has radius of convergence r.
REFERENCES 9
[Q7] (Section 6.7: Problem 6.7.5)
Let fpxq “ ř8k“0 akpx ´ cqk have radius of convergence r. Use Theorem 2 on page 389
of [1] to prove that f then possesses derivatives of all orders in the interval |x´ c| ă r, and
f pnqpxq “
8ÿ
k“n
akk!
pk ´ nq!px´ cq
k´n, |x´ c| ă r.
(This justifies term-by-term differentiating the series for f to get a series for f pnq.)
(Hint: Just use Theorem 2 repeatedly.)
Solution: By Theorem 2, we know that f 1pxq “

k“1
kakpx ´ cqk´1. Suppose f pnqpxq “

k“n
akk!
pk´nq!px´ cqk´n, then we differentiate it one more time, we have
f pn`1qpxq “
8ÿ
k“n`1
akk!
pk ´ nq!pk ´ nqpx´ cq
k´n´1

8ÿ
k“n`1
akk!
pk ´ n´ 1q!px´ cq
k´n´1.
[Q8] (Section 6.7: Problem 6.7.8)
Show that the linear ODE, y1 “ xy, has a solution given by:
ypxq “
8ÿ
k“0
x2k
k!2k
.
(Hint: Use [Q7].)
Solution: By [Q7], we can do term-by-term differentiation on ypxq “ ř8k“0 x2kk!2k . This
gives
y1pxq “
8ÿ
k“1
2kx2k´1
k!2k

8ÿ
k“1
x2k´1
pk ´ 1q!2k´1

8ÿ
k“0
x2k`1
k!2k
“ x
8ÿ
k“0
x2k
k!2k
“ xypxq.
Therefore ypxq “ ř8k“0 x2kk!2k is a solution to y1 “ xy.

欢迎咨询51作业君
51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468