math 128a, summer 2019 - daniel suryakusuma · math 128a, pset #6 daniel suryakusuma, 24756460 math...

34
Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function [p,q] = pcoeff(t, n, k) 2 %t : solution times t(1) < t(2) < ... < t(n) < t (n+1) 3 % n+1 : new time step 4 %k : number of previous steps t(n-k+1) ... t(n) Problem 1. Write, test and debug a matlab function which computes coefficients p and q for the k-step predictor- corrector method v n+1 = u n + Z tn+1 tn p(t) dt = u n + p 1 f n + p 2 f n-1 + ··· + p n f n-k+1 , u n+1 = u n + Z tn+1 tn q(t) dt = u n + q 1 f (t n+1 ,v n+1 )+ q 2 f n + ··· + q k f n-k+2 Here p(t) is the degree k - 1 polynomial which interpolates the values f j = f (t j ,u j ) for n - k +1 j n and q(t) is the degree k - 1 polynomial which interpolates the values f j for n - k +2 j n and also the predicted slope f (t n+1 ,v n+1 ) at t n+1 . Thus p j = Z tn+1 tn Y i6=j t - t n-i+1 t n-j+1 - t n-i+1 , and q j = Z tn+1 tn Y i6=j t - t n-i+2 t n-j+2 - t n-i+2 for 1 j k. Tabulate the coefficients p, q with constant step size h = 1 and k 5 and verify against Adams-Bashforth and Adams-Moulton methods. (Hint: the integrands are polynomials of degree k - 1 for which ceiling(k/2) Gaussian integration points and weights will give an exact result.) Solution. Strain reminds that Adams-Bashforth is explicit Adams, and Adams-Moulton is implicit Adams. Taking the hint, we take Gaussian integration points given by https://keisan.casio.com/exec/system/1329114617 , which gives Legendre-Gaussian points and weights each to at least 50-digit accuracy (reflected in the appended code). Testing results gives (first list element is p, second is q): 1 > pcoeff(0:42,42,1) 2 [[1]] 3 [1] 1 4 [[2]] 5 [1] 1 6 7 > pcoeff(0:42,42,2) 8 [[1]] 9 [1] 1.5 -0.5 10 [[2]] 11 [1] 0.5 0.5 12 13 > pcoeff(0:42,42,3) 14 [[1]] 15 [1] 1.916666666666666074548 -1.333333333333332593185 16 [3] 0.416666666666666185570 17 [[2]] 18 [1] 0.4166666666666661855700 0.6666666666666676288600 19 [3] -0.0833333333333337866744 20 21 > pcoeff(0:42,42,4) 22 [[1]] 23 [1] 2.2916666666666656304585 -2.4583333333333303727386 1

Upload: others

Post on 29-Jul-2020

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

Math 128A, Summer 2019PSET #6 (due Wednesday 8/7/2019)

1 f unc t i on [ p , q ] = pco e f f ( t , n , k )2 % t : s o l u t i o n t imes t (1 ) < t (2 ) < . . . < t (n) < t (n+1)3 % n+1 : new time step4 % k : number o f prev ious s t ep s t (n−k+1) . . . t (n )

Problem 1. Write, test and debug a matlab function which computes coefficients p and q for the k-step predictor-corrector method

vn+1 = un +

∫ tn+1

tn

p(t) dt = un + p1fn + p2fn−1 + · · ·+ pnfn−k+1,

un+1 = un +

∫ tn+1

tn

q(t) dt = un + q1f(tn+1, vn+1) + q2fn + · · ·+ qkfn−k+2

Here p(t) is the degree k− 1 polynomial which interpolates the values fj = f(tj , uj) for n− k+ 1 ≤ j ≤ n and q(t)is the degree k − 1 polynomial which interpolates the values fj for n− k + 2 ≤ j ≤ n and also the predicted slopef(tn+1, vn+1) at tn+1. Thus

pj =

∫ tn+1

tn

∏i 6=j

t− tn−i+1

tn−j+1 − tn−i+1, and

qj =

∫ tn+1

tn

∏i 6=j

t− tn−i+2

tn−j+2 − tn−i+2

for 1 ≤ j ≤ k. Tabulate the coefficients p, q with constant step size h = 1 and k ≤ 5 and verify againstAdams-Bashforth and Adams-Moulton methods. (Hint: the integrands are polynomials of degree k − 1 for whichceiling(k/2) Gaussian integration points and weights will give an exact result.)

Solution. Strain reminds that Adams-Bashforth is explicit Adams, and Adams-Moulton is implicit Adams.Taking the hint, we take Gaussian integration points given by

https://keisan.casio.com/exec/system/1329114617 ,

which gives Legendre-Gaussian points and weights each to at least 50-digit accuracy (reflected in the appendedcode).Testing results gives (first list element is p, second is q):

1 > pco e f f ( 0 : 4 2 , 4 2 , 1 )2 [ [ 1 ] ]3 [ 1 ] 14 [ [ 2 ] ]5 [ 1 ] 16

7 > pco e f f ( 0 : 4 2 , 4 2 , 2 )8 [ [ 1 ] ]9 [ 1 ] 1 . 5 −0.5

10 [ [ 2 ] ]11 [ 1 ] 0 . 5 0 .512

13 > pco e f f ( 0 : 4 2 , 4 2 , 3 )14 [ [ 1 ] ]15 [ 1 ] 1 .916666666666666074548 −1.33333333333333259318516 [ 3 ] 0 .41666666666666618557017 [ [ 2 ] ]18 [ 1 ] 0 .4166666666666661855700 0.666666666666667628860019 [ 3 ] −0.083333333333333786674420

21 > pco e f f ( 0 : 4 2 , 4 2 , 4 )22 [ [ 1 ] ]23 [ 1 ] 2 .2916666666666656304585 −2.4583333333333303727386

1

Page 2: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

24 [ 3 ] 1 .5416666666666640761463 −0.374999999999999389377325 [ [ 2 ] ]26 [ 1 ] 0 .37499999999999933386619 0.7916666666666682949937727 [ 3 ] −0.20833333333333448056379 0.0416666666666669002760928

29 > pco e f f ( 0 : 4 2 , 4 2 , 5 )30 [ [ 1 ] ]31 [ 1 ] 2 .6402777777777810541693 −3.852777777777787626689632 [ 3 ] 3 .6333333333333439618684 −1.769444444444450148523633 [ 5 ] 0 .348611111111112315086334 [ [ 2 ] ]35 [ 1 ] 0 .34861111111111231508630 0.8972222222222190346485636 [ 3 ] −0.36666666666666369867045 0.1472222222222210330500037 [ 5 ] −0.02638888888888867370608

Checking against wikipedia ( https://en.wikipedia.org/wiki/Linear_multistep_method ) suggests that ourresults are accurate, modulo some error.

Figure 1: Adams-Bashforth

Figure 2: Adams-Moulton

This gives the following errors:

1 ## ADAMS BASHFORTH2 > e r r . ab13 [ 1 ] 04 > e r r . ab25 [ 1 ] 0 06 > e r r . ab37 [ 1 ] −4.44089209850e−16 6.66133814775 e−16 −4.44089209850e−168 > e r r . ab49 [ 1 ] −8.88178419700e−16 2.66453525910 e−15 −2.44249065418e−15

10 [ 4 ] 6 .10622663544 e−1611 > e r r . ab512 [ 1 ] 3 .10862446895 e−15 −9.76996261670e−15 1.06581410364 e−1413 [ 4 ] −5.55111512313e−15 1.16573417586 e−1514

15 ## ADAMS MOULTON16 > e r r . am117 [ 1 ] 018 > e r r . am219 [ 1 ] 0 020 > e r r . am321 [ 1 ] −4.44089209850e−16 9.99200722163 e−16 −4.57966997658e−16

2

Page 3: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

22 > e r r . am423 [ 1 ] −6.66133814775e−16 1.66533453694 e−15 −1.16573417586e−1524 [ 4 ] 2 .35922392733 e−1625 > e r r . am526 [ 1 ] 1 .16573417586 e−15 −3.21964677141e−15 2.99760216649 e−1527 [ 4 ] −1.19348975147e−15 2.15105711021 e−16

Plotting the interesting (k = 5) results, we have the following digits of accuracy:

and we conclude this is close enough to floating-point accuracy. To generate these plots:

1 # ab : adams−bashforth , e x p l i c i t ( ∗h=1 )2 ab1 <− c (1 )3 ab2 <− 1/2 ∗ c (3 , −1)4 ab3 <− 1/12 ∗ c (23 , −16, 5)5 ab4 <− 1/24 ∗ c (55 , −59, 37 , −9)6 ab5 <− 1/720 ∗ c (1901 , −2774 , 2616 , −1274 , 251)7

8 # adams−moulton , imp l i c i t ( ∗h=1 )9 am1 <− c (1 )

10 am2 <− 1/2∗ c (1 , 1)11 am3 <− 1/12 ∗ c (5 , 8 , −1) # compare to q o f 312 am4 <− 1/24 ∗ c (9 , 19 , −5, 1)13 am5 <− 1/720∗ c (251 , 646 , −264, 106 , −19)14

15 pq1 <− pco e f f ( 0 : 4 2 , 42 , 1)16 pq2 <− pco e f f ( 0 : 4 2 , 42 , 2)17 pq3 <− pco e f f ( 0 : 4 2 , 42 , 3)18 pq4 <− pco e f f ( 0 : 4 2 , 42 , 4)19 pq5 <− pco e f f ( 0 : 4 2 , 42 , 5)20

21 # e r r o r s without abso lu t e va lue22 e r r . ab1 <− pq1 [ [ 1 ] ] − ab123 e r r . ab2 <− pq2 [ [ 1 ] ] − ab2

3

Page 4: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

24 e r r . ab3 <− pq3 [ [ 1 ] ] − ab325 e r r . ab4 <− pq4 [ [ 1 ] ] − ab426 e r r . ab5 <− pq5 [ [ 1 ] ] − ab527

28 e r r . am1 <− pq1 [ [ 2 ] ] − am129 e r r . am2 <− pq2 [ [ 2 ] ] − am230 e r r . am3 <− pq3 [ [ 2 ] ] − am331 e r r . am4 <− pq4 [ [ 2 ] ] − am432 e r r . am5 <− pq5 [ [ 2 ] ] − am533

34 p lo t (− l og ( abs ( e r r . ab5 ) , base=10) , main=’Comparing Against Adams−Bashforth ’ , y lab=’ d i g i t s o faccuracy ’ )

35 p lo t (− l og ( abs ( e r r . am5) , base=10) , main=’Comparing Against Adams−Moulton ’ , y lab=’ d i g i t s o f accuracy’ )

And of course, our code for pcoeff is as follows:

1 pco e f f <− f unc t i on ( t , n , k ) {2 # output l i s t . p . q <− l i s t (p , q )3 # t : s o l u t i o n times , t (1 ) < t (2 ) < . . . < t (n) < t (n+1)4 # n+1 : new time step5 # k : = 1 ,2 ,3 ,4 ,5 : number o f prev ious steps , t (n−k+1) . . . t (n )6

7 # gauss−l e g endre po in t s and weights to 50− d i g i t accuracy f o r fun8 t1 <− c (0 ) ;9 w1 <− c (2 ) ;

10 t2 <− c (−0.57735026918962576450914878050195745564760175127013 ,0.57735026918962576450914878050195745564760175127013) ;

11 w2 <− c (1 , 1 ) ; t3 <− c (−0.77459666924148337703585307995647992216658434105832 , 0 ,0.77459666924148337703585307995647992216658434105832) ;

12 w3 <− c (0.55555555555555555555555555555555555555555555555556 ,0.88888888888888888888888888888888888888888888888889 ,0.55555555555555555555555555555555555555555555555556) ;

13 t4 <− c (−0.86113631159405257522394648889280950509572537962972 ,−0.33998104358485626480266575910324468720057586977091 ,0.33998104358485626480266575910324468720057586977091 ,0.86113631159405257522394648889280950509572537962972) ;

14 w4 <− c (0.3478548451374538573730639492219994072353486958339 ,0.65214515486254614262693605077800059276465130416611 ,0.6521451548625461426269360507780005927646513041661 ,0.34785484513745385737306394922199940723534869583389) ;

15 t5 <− c (−0.90617984593866399279762687829939296512565191076253 ,−0.53846931010568309103631442070020880496728660690556 , 0 ,0.53846931010568309103631442070020880496728660690556 ,0.90617984593866399279762687829939296512565191076253) ;

16 w5 <− c (0.23692688505618908751426404071991736264326000221241 ,0.47862867049936646804129151483563819291229555334314 ,0.5688888888888888888888888888888888888888888888889 ,0.47862867049936646804129151483563819291229555334314 ,0.23692688505618908751426404071991736264326000221241) ;

17 t6 <− c (−0.93246951420315202781230155449399460913476573771229 ,−0.66120938646626451366139959501990534700644856439517 ,−0.23861918608319690863050172168071193541861063014 ,0.23861918608319690863050172168071193541861063014002 ,0.66120938646626451366139959501990534700644856439517 ,0.93246951420315202781230155449399460913476573771229) ;

18 w6 <− c (0.17132449237917034504029614217273289352682250148404 ,0.3607615730481386075698335138377161116615218927467 ,0.46791393457269104738987034398955099481165560576921 ,0.4679139345726910473898703439895509948116556057692 ,0.3607615730481386075698335138377161116615218927467 ,0.17132449237917034504029614217273289352682250148404) ;

19

20 h <− 1/2 ∗ ( t [ n+1] − t [ n ] ) # ha l f−s tep l ength21 m <− 1/2 ∗ ( t [ n+1] + t [ n ] ) # midpoint to s e t c ent e r weight22

23 ## lazy case−work handl ing c e i l ( k/ 2) ass ignment24 c e i l k 2 <− c e i l i n g (k/ 2)25 i f ( k == 1) {26 r e turn ( l i s t (h∗ 2 , h∗ 2) ) # p , q27 } e l s e i f ( k == 2) {

4

Page 5: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

28 t . gauss <− t1 ∗ h + m29 w. gauss <− w1 ∗ h30 } e l s e i f ( c e i l k 2 == 2) {31 t . gauss <− t2 ∗ h + m32 w. gauss <− w2 ∗ h33 } e l s e i f ( c e i l k 2 == 3) {34 t . gauss <− t3 ∗ h + m35 w. gauss <− w3 ∗ h36 } e l s e i f ( c e i l k 2 == 4) {37 t . gauss <− t4 ∗ h + m38 w. gauss <− w4 ∗ h39 } e l s e i f ( c e i l k 2 == 5) {40 t . gauss <− t5 ∗ h + m41 w. gauss <− w5 ∗ h42 } e l s e i f ( c e i l k 2 == 6) {43 t . gauss <− t6 ∗ h + m44 w. gauss <− w6 ∗ h45 }46

47 # p <− matrix ( data = 42 , nrow = 1 , nco l = k )48 # q <− matrix ( data = 42 , nrow = 1 , nco l = k )49 p <− c ( )50 q <− c ( )51 f o r ( j in 1 : k ) { # go through k prev ious s t ep s52 p . t o t a l <− 053 q . t o t a l <− 054 f o r ( order in (1 : c e i l i n g (k/ 2) ) ) { # gauss i n t t n to t {n+1}55 t . eva l <− t . gauss [ order ]56 p . prod <− w. gauss [ order ]57 q . prod <− w. gauss [ order ]58 f o r ( i in 1 : k ) { # eva l \prod expr e s s i on59 i f ( i != j ) {60 p . prod <− p . prod ∗ ( t . eva l − t [ n−i +1]) / ( t [ n−j +1] − t [ n−i +1])61 q . prod <− q . prod ∗ ( t . eva l − t [ n−i +2]) / ( t [ n−j +2] − t [ n−i +2])62 }63 }64 p . t o t a l <− p . t o t a l + p . prod65 q . t o t a l <− q . t o t a l + q . prod66 }67 p <− c (p , p . t o t a l )68 q <− c (q , q . t o t a l )69 }70 r e turn ( l i s t (p , q ) )71 }

5

Page 6: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

Problem 2. Write, test and debug a matlab function which uses pcoeff to approximate the solution vector y(t)of the vector initial value problem

y′ = f(t, y, r)

y(a) = ya

by the family of methods you derive in Problem 1, with u1 = ya. Start with k1 = 1 and a tiny step size

h1 = (b− a)

(h

b− a

)k/2which brings the one-step error in line with the O(hk) error. Increase the step size smoothly (e.g. by h1 ←(1 + 1

k

)h1) and increase k1 (e.g. by steps of 1 up to k) until h1 ≥ h = b−a

N−1 and then continue with uniform stepsizes.(Notice that to save CPU time,(i) when the most recent k step sizes are uniform, the predictor-corrector coefficients p, q can be frozen and(ii) many values of f can be saved rather than re-evaluated.)

(a) Use pcode.m with odd k = 1, 3, 5, . . . , 11 (requires 6-point Gaussian Quadrature, or Strain says we can go to 9and call it a day) and N = 10000, 20000, 40000, 80000, 160000 to approximate the final solution vector u(T ) of theintial value problem derived in Problem 4 of PSET 5 (satellite orbit around the earth and moon). Tabulate theerrors

EkN = max1≤j≤4

|uj(T )− uj(0)|.

Estimate the constant Ck such that the error behaves like Ckhk.

Solution. From the following errors, we estimate Ck via h = − log n linear slope:

C1 =1.36891− 0.33039

log1 0160000− log1 010000= 0.862472 seconds

C3 = 8.62472× 103 seconds

C9 = 8.62472× 1017 seconds

Our errors for k = 1 across N are:

1 > e r r o r s . 2 a # k = 12 [ 1 , ] 1 .368913 [ 2 , ] 2 .488314 [ 3 , ] 1 .485635 [ 4 , ] 0 .798386 [ 5 , ] 0 .33039

Our errors for k = 3 across N are:

1 >> e r r o r s . 2 a # k = 32 [ , 1 ]3 [ 1 , ] 2 .006314 [ 2 , ] 1 .943715 [ 3 , ] 1 .761086 [ 4 , ] 1 .411307 [ 5 , ] 1 .23706

Our errors for k = 9 across N are:

1 > e r r o r s . 2 a # k = 92 [ 1 , ] 1 .398403 [ 2 , ] 1 .094924 [ 3 , ] 0 .603555 [ 4 , ] 0 .292186 [ 5 , ] 0 .14075

6

Page 7: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

To generate plots and tabulate errors and CPU cost:

1 per iod .T <− 17.065216560157962 ua . 2 a <− c ( 0 . 994 , 0 , 0 , −2.00158510637908) # s t a r t i n g pos3 N.2 a <− 1e4∗c (1 , 2 , 4 , 8 , 16 )4 e r r o r s . 2 a <− matrix ( data=NA, nrow = length (N.2 a ) , nco l = 1)5

6 k = 9 # se t k7

8 cpu . t imes . 2 b <− c ( )9 f o r (N. index in 1 : l ength (N. 2 a ) ) {

10 N <− N.2 a [N. index ]11 time . s t a r t <− Sys . time ( )12 tu <− pcode (0 , per iod .T, ua . 2 a , sa t . o rb i t , r , k , N) # se t k13 u . a l l <− tu [ [ 2 ] ]14 u . f i n a l <− u . a l l [ , nco l (u . a l l ) ]15 time . stop <− Sys . time ( )16 cpu . t imes . 2 b <− c ( cpu . t imes . 2 b , time . stop − time . s t a r t )17 e r r o r s . 2 a [N. index ] <− max( abs (u . f i n a l − u . a l l [ , 1 ] ) )18 p lo t (u . a l l [ 1 , ] , u . a l l [ 3 , ] , type=’ l ’ ,19 main=paste ( ’ Pred i c to r Corrector ODE \n k=’ ,k , ’N=’ ,N. 2 a [N. index ] ) )20 }21 l og .N. 2 a <− l og (N. 2 a , base=10)22 p lo t ( l og .N. 2 a , e r r o r s . 2 a )23 p lo t ( l og .N. 2 a , cpu . t imes . 2 b)

7

Page 8: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(b) Measure the CPU time for each run and estimate the total CPU time necessary to obtain an orbit that isperiodic to 3, 6, 12-digit accuracy.

Solution. For k = 1, our cpu times across N are:

1 > cpu . t imes . 2 b2 [ 1 ] 0 .317155 0.319249 0.529587 0.792668 1.193514

For k = 9, our cpu times across N are:

1 > cpu . t imes . 2 b2 [ 1 ] 0 .562517 0.193649 0.408006 0.827510 1.659895

Now, our cpu times are extremely erratic as can be seen by the plots. However, assuming a linear log relationshipas we have in homework 5, we can get a (very bad) set of estimates for k = 9:

3-digit accuracy = 0.671929

6-digit accuracy = 1.44763

12-digit accuracy = 7.62813

8

Page 9: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(c) Plot some inaccurate solutions and some accurate solutions, and draw conclusions about values of k that give3, 6, 12-digit accuracy for minimal CPU time.

Solution. To exhibit some (very) inaccurate solutions, we first show the results for k = 1 across N =10000, 20000, 40000, 80000, 16000, then k = 3 across N , and finally k = 9 to show the accuracy, and then wecall it a day (and give the cpu a rest). It appears that k = 3 gives the best spread of accuracy for 3, 6, 12-digitaccuracy. At k = 9, it starts to look the same across N , so k = 9 may be unnecessarily high.

9

Page 10: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

and we call it a day (yeehaw).

10

Page 11: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(d) Compare to the results of euler.m and idec.m.

Solution. Recall that idec with p = 1 is simply euler, so inherently, we showed that given the same step size,idec generally (for p > 1) gives more accurate results. It is true that we may approach the exact solution byspamming smaller step sizes in euler, but cpu cost explodes to catch up to idec performance.Personally and objectively, it appeared that idec gave better results than predictor-corrector, but it may be becauseI programmed pcode inoptimally. However, I will say that for k ≥ 3, our predictor-corrector scheme pcode appearsto perform more consistently across the N number of steps that we tested, as opposed to the largely varying resultsfor a fixed p in idec.To compare to our resulting plots in part (c) on the previous page, we include some plots from idec that wegenerated for Homework 5:

Figure 3: Equivalent to euler, very bad

11

Page 12: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

Our pcode is as follows:

1 pcode <− f unc t i on (a , b , ua , f , r , k , N) {2 # Pred i c to r Code ODE3 # a , b : i n t e r v a l endpoints with a < b4 # ua : vec to r u 1 = y( a ) o f i n i t i a l c ond i t i on s # c (x , x , x , x )5 # func t i on handle f ( t , u , r ) to i n t e g r a t e6 # r : parameters to f7 # k : number o f prev ious s t ep s to use at each r e gu l a r time step8 # N : t o t a l number o f time s t ep s9 # t : output t imes f o r numerica l s o lu t i on , u n : y ( t n) , t (1 ) = a , t (N) = b

10 # u : numerica l s o l u t i o n at t imes t11

12 t <− matrix ( data=0, nrow = N, nco l = 1) ; t [ 1 ] <− a ;13 u <− matrix ( data=0, nrow = length ( ua ) , nco l = N) ; f . eva l <− u ;14 h <− (b − a ) / (N − 1)15 s t o r e . u <− matrix ( data=0, nrow = length ( ua ) , nco l = 1)16 u [ , 1 ] <− matrix ( data = ua , nrow = length ( ua ) , nco l = 1)17

18 i f ( k == 1) { # degenerate , j u s t use 1 s tep19 f o r ( i in 1 : (N−1) ) {20 t [ i +1] <− t [ i ] + h21 s t o r e . u <− u [ , i ]22 s t o r e . u <− s t o r e . u + h ∗ f ( t [ i ] , s t o r e . u , r )23 u [ , i +1] <− u [ , i ] + h ∗ f ( t [ i +1] , s t o r e . u , r )24 }25 } e l s e {26 # inc r e a s e s tep s i z e smoothly27 t [ 1 ] <− a28 theta <− 1 + 1/k # given s c a l i n g29 h1 <− (b−a ) ∗ ( ( h/ (b−a ) ) ∗∗ ( k/ 2) )30 i <− 1 # i n i t index31 whi le ( h1 < h) { # sp e c i f i e d cond i t i on32 t [ i +1] <− t [ i ] + h133 i <− i + 1 # cont inue34 h1 <− theta ∗ h1 # s c a l i n g f a c t o r35 }36 # h1 >= h , so resume uniform s t e p s i z e37 h <− (b − t [ i ] ) / (N−i ) # new step s i z e38 f o r ( j in ( i +1) :N) {39 t [ j ] <− t [ i ] + h ∗ ( j−i )40 }41 u [ , 1 ] <− matrix ( data=ua , nrow = length ( ua ) , nco l = 1)42 f . eva l [ , 1 ] <− f ( t [ 1 ] , ua , r )43 f r e e z e . idx <− i + 2 ∗ k # f r e e z e be f o r e index ing through again44 f o r ( i in 1 : (N−1) ) {45 k . min <− min( i , k ) # co r r e c t i o n s t ep s46 i f ( i < f r e e z e . idx ) {47 pq <− pco e f f ( t , i , k . min )48 p <− pq [ [ 1 ] ]49 q <− pq [ [ 2 ] ]50 }51 ## bet t e r to do 2 separa t e loops , suggested by St ra in52 # Pred i c to r53 s t o r e . pred <− u [ , i ] + p [ 1 ] ∗ f . eva l [ , i ]54 f o r ( x in 1 : ( k . min−1) ) {55 s t o r e . pred <− s t o r e . pred + p [ x+1] ∗ f . eva l [ , i−x ]56 }57 # Corrector58 s t o r e . c o r r <− u [ , i ] + q [ 1 ] ∗ f ( t [ i +1] , s t o r e . pred , r )59 f o r ( x in 1 : ( k . min−1) ) {60 s t o r e . c o r r <− s t o r e . c o r r + q [ x+1] ∗ f . eva l [ , i + 1 − x ]61 }62 u [ , i +1] <− s t o r e . co r r63 f . eva l [ , i +1] <− f ( t [ i +1] , s t o r e . corr , r )64 }65 }66 l i s t ( t , matrix ( data=u , nrow = length ( ua ) ) )67 }

12

Page 13: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

Problem 3. Consider a differential equation

y′(t) = f(t, y(t)),

where f satisfies the condition

(u− v)[f(t, u)− f(t, v)] ≤ 0

for all u, v.

(a) Suppose U(t) and V (t) are exact solutions. Show that

|U(t)− V (t)| ≤ |U(0)− V (0)|

for all t ≥ 0.

Solution. Here we want to show that the distances between two exact solutions does not increase over time.Given that U(t), V (t) are exact solutions, then U ′(t) = f(t, U(t)) and V ′(t) = f(t, V (t)). Consider:

(u− v) [f(t, u)− f(t, v)] ≤ 0, ∀u, v (given)

(u− v) [u′ − v′] ≤ 0 (substituting)∫(u− v)d[u− v] ≤ 0

1

2(u− v)2 ≤ C (not good enough),

and although this does not directly give us the desired result (we don’t know C), it gives us intuition to work inthe opposite direction.

Now define g(t) :=√

(u(t)− v(t))2 (coercing a positive result–although we only consider g(t)2 anyway), and noticeif we show g(t) is monotonic nonincreasing, then we are done. To supply the desired product gg′ with the aboveintuition, take:

d

dt[g(t)]2 =

d

dt[u(t)− v(t)]2

=d

dt

(√(u(t)− v(t))2

)2= 2[u(t)− v(t)][u′(t)− v′(t)] (chain rule)

= 2(u− v)[f(t, u)− f(t, v)] (substituting)

≤ 0 (given dissipative condition),

which means that the square function g(t)2 is monotonically nonincreasing. Because g(t) =√

(u(t)− v(t))2 =√(v(t)− u(t))2 (symmetric), we conclude that g(t) is monotonically nonincreasing. This gives for all t ≥ 0,

g(t) ≤ g(0), which equivalently is:

∀t≥0 |U(t)− V (t)| ≤ |U(0)− V (0)| ,

precisely our desired result.

13

Page 14: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(b) Suppose W satisfies a perturbed differential equation

W ′(t) = f(t,W (t)) + r(t)

for t ≥ 0. Show that for t ≥ 0,

|U(t)−W (t)| ≤ |U(0)−W (0)|+∫ t

0

|r(s)| ds

Solution. We want some expression or inequality for the perturbing term r(t) with respect to U,W , so that wecan derive the desired inequality. Although the structure here is similar to that in part (a), notice that W is notan exact solution to the original differential equation in (a). However, we do have:

[U(t)−W (t)][f(t, U(t))− f(t,W (t))] = [U(t)−W (t)][U ′(t)−W ′(t) + r(t)] ≤ 0 (1)

from the condition given in part (a) which holds for all u, v, namely with v = W with r(t) = 0.Now, we already know from (a) we can get this expression via some d

dtg(t)2, so again let g(t) :=√

(U(t)−W (t))2

to coerce nonnegative values. Then we have:

d

dtg(t)2 =

d

dt

(√(U(t)−W (t))2

)2= 2g(t)g′(t)

= 2[U(t)−W (t)][U ′(t)−W ′(t)]= 2[U(t)−W (t)][f(t, U(t))− f(t,W (t))− r(t)︸ ︷︷ ︸

W ′(t)

]

= 2[U(t)−W (t)][f(t, U(t))− f(t,W (t))]︸ ︷︷ ︸≤0 by (1) above

−2[U(t)−W (t)]r(t)

≤ −2[U(t)−W (t)]r(t) ≤ |−2[U(t)−W (t)]r(t)|≤ 2g(t)|r(t)|

and because our construction for g(t) asserts it is nonnegative (handling the g(t) = 0 case separately below), weperform separation of variables on our result above, which gives:

1

2g(t)[g(t)2]′ ≤ |r(t)|

and integrating both sides from 0 to t (and changing the variable name of the integrands as Strain conditions us tonot forget), ∫ t

0

1

���2g(s)

[���2g(s)g′(s)] ds =

∫ t

0

|r(s)| ds

g(t)− g(0) ≤∫ t

0

|r(s)| ds

g(t) ≤ g(0) +

∫ t

0

|r(s)| ds

√(U(t)−W (t))2 ≤

√(U(0)−W (0))2 +

∫ t

0

|r(s)| ds

which brings us precisely to our desired expression:

|U(t)−W (t)| ≤ |U(0)−W (0)|+∫ t

0

|r(s)| ds

Now we consider the case when g(t) = 0 and we cannot perform the separation of variables above by dividing across

by g(t). Notice that |g(t)| ≤ |g(0)|+∫ t0|r(s)| dt is trivially true when g(t) = g(0) = 0.

14

Page 15: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(c) Show that two numerical solutions un and vn generated by implicit Euler (e.g. with different initial values)satisfy, for all n ≥ 0,

|un − vn| ≤ |u0 − v0|.

Solution. Consider the set U ⊂ N of natural number indices i for which our implicit Euler iteration solutions hasthis desired property. Trivially, 0 ∈ U because |u0 − v0| ≤ |u0 − v0| in the i = 0 case. Now we assume (inductionhypothesis) that n− 1 ∈ U and wish to show this implies n ∈ U .Recall that implicit euler is simply:

un = un−1 + hf(tn, un), vn = vn−1 + hf(tn, vn),

Consider:We are given the condition

(un − vn)[f(t, un)− f(t, vn)] ≤ 0, (2)

(f dissipative) where this holds for all u, v and hence must hold for u := un and v := vn.Intuitively, in the end (or so I thought) we want to use the condition the product of two elements, which we canwrite as:

2ab = (a2 + b2)− (a− b)2.

Now we set a := (un − vn) and b := h[f(t, un)− f(t, vn)], so that

a− b = (un − vn)− h[f(t, un)− f(t, vn)] = un−1 − vn−1,

which by n − 1 ∈ U (strong induction induction assumption), we have |a − b| = |un−1 − vn−1| ≤ |u0 − v0|. Thislooks promising! Now plugging into our expression gives:

0 ≥ 2ab = a2 + b2 − (a− b)2

= (un − vn)2︸ ︷︷ ︸a2

+h2[f(t, un)− f(t, vn)]2︸ ︷︷ ︸b2

− (un−1 − vn−1)2︸ ︷︷ ︸(a−b)2

=⇒ (un − vn)2 ≤ (un−1 − vn−1)2 − h2[f(t, un)− f(t, vn)]2

≤ |un−1 − vn−1|2 (trivial inequality)

≤ |u0 − v0|2 (induction hypothesis, n− 1 ∈ U)

which by taking the positive square root (via absolute value) precisely gives us:

|un − vn| ≤ |u0 − v0|,

so we conclude n− 1 ∈ U =⇒ n ∈ U , so by induction, U = N and we have |un − vn| ≤ |u0 − v0|,∀n ∈ N .

This was my first solution, but further review led me to believe I found a neater solution that did not use the givencondition and thus publicly shamed the above solution. It turns out that I invented an incorrect triangle inequality,and hence the following is incorrect:

|un(t)− vn(t)| − |un−1(t)− vn−1(t)| = |[un−1(t) + hf(t, un)]− [vn−1(t) + hf(t, vn)]| − |un−1(t)− vn−1(t)|

≤(((((((((|un−1(t)− vn−1(t)| − |hf(t, un)− hf(t, vn)|︸ ︷︷ ︸

≥0 abs val

−(((((((((|un−1(t)− vn−1(t)| ≤ 0

=⇒ |un − vn|︸ ︷︷ ︸ ≤ |un−1 − vn−1| ≤ |u0 − v0|︸ ︷︷ ︸,and we have 0, n− 1 ∈ U =⇒ n ∈ U , so by induction we have U = N and we are finished (not really).

15

Page 16: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(d) Show that the local truncation error τn+1 of the implicit Euler method

un+1 = un + hf(tn+1, un+1)

is given by

τn+1 =yn+1 − yn

h− f(tn+1, yn+1) = −h

2y′′(ξ)

where yn = y(tn) is the exact solution and ξ is an unknown point.

Solution. Recall from lecture (Lecture 18, Tuesday 7/23), we defined the local truncation error for the explicitEuler method (un+1 = un + hf(tn, un)) as:

τn :=yn+1 − yn

h− f(tn, yn),

where we have f(tn, yn) = y′n, so Taylor expanding gives:

τn =yn+1 − yn

h− y′n

=yn + hy′n + 1

2h2y′′(ξn)− yn

h− y′n

=h

2y′′(ξn) = O(h).

Now we do something similar for our given implicit Euler method of the form un+1 = un + hf(tn+1, un+1).Consider:

τn+1 =yn+1 − yn

h− f(tn+1, yn+1)

=yn+1 − yn

h− y′(tn+1)

=yn+1 −

[yn+1 − hy′(tn+1) + h2

2 y′′(ξ)

]h

− y′(tn+1)

= −h2y′′(ξ),

which was to be shown.

16

Page 17: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(e) Show that the numerical solution un generated by implicit Euler with u0 := y0 satisfies:

|un − yn| ≤ nhτ

for 0 ≤ nh <∞, where τ = Mh2 and |y′′| ≤M .

Solution. First, we explicitize a few things. From the given, |y′′| ≤ M so y is twice-differentiable and Lipschitz,and M is nonnegative (as is h), so τ = Mh

2 is also nonnegative. Additionally, 0 ≤ nh <∞ so n is finite and positive.Again, we formalize via induction for all n ∈ N. Consider the set U ⊂ N of indices i for which |un− yn| ≤ nhτ . Weestablished that nhτ ≥ 0. For i = 0, we have |u0 − y0| = 0 = 0 · nτ , so 0 ∈ U . Now suppose (induction) n− 1 ∈ U .That is, assume that we have:

|un−1 − yn−1| ≤ (n− 1)hτ = (n− 1)Mh2

2.

Now, consider:

|un − yn| =∣∣∣∣[un−1 +���

��hf(tn, un)]− [yn−1 +�����hf(tn, yn)− h2

2y′′(ξ)]

∣∣∣∣≤∣∣∣∣un−1 − yn−1 +

h2

2y′′(ξ)

∣∣∣∣≤ |un−1 − yn−1|︸ ︷︷ ︸

≤(n−1)Mh2

2

+

∣∣∣∣h22 M∣∣∣∣ (y′′ is Lipschitz bounded by M)

= nMh2

2,

where in the first line we cross these out in absolute value inequality to the next line because we’re given thecondition (u− v)[f(t, u)− f(t, v)] ≤ 0 for all u, v, and this argument is identical by multiplying across by |un− yn|.Notice that if un = yn, then a division across by |un−yn| = 0 is not legal; however, in this case |un−yn| = 0 ≤ nhτ,as desired.

We conclude n− 1 ∈ U =⇒ n ∈ U , so by induction, U = N and we have:

|un − yn| ≤ nhτ, ∀n∈N ,

as required.

17

Page 18: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

Problem 4. Consider the linear initial value problem

y′ = −L(y(t)− ϕ(t)) + ϕ′(t)

y(0) = y0

where ϕ(t) := cos(30t).

(a) Solve the initial value problem exactly.

Solution. First notice that this is essentially the same problem presented in Lecture 23 (Wednesday July 31) inexamining stiff equations, linear stability and nonlinear stability:

y′ = λ(y − φ(t)) + φ′(t),

where we inserted the forcing term φ′(t) so that our problem is solvable. Strain notes that −L ∈ C is the dampeningconstant if it’s negative, with Re(−L) << 0, and ϕ(t) describes something that oscillates smoothly (like a massagechair). Essentially, −L describes how we want to get to that smooth oscillation.We proceed directly as given by Strain (changing λ→ −L and φ→ ϕ as needed).

y′(t) = −L(y(t)− ϕ(t)) + ϕ′(t)

(y(t)− ϕ)′ = −L(y(t)− ϕ(t))

y(t)− ϕ = e−Lt[y(0)− ϕ(0)]

y(t) = ϕ(t) + e−Lt [y(0)− ϕ(0)]︸ ︷︷ ︸transient

,

and we insert our initial conditions ϕ(0) = cos(30 · 0) = 1 and y(0) = y0 and ϕ(t) := cos(30t) to get:

y(t) = cos(30t) + (y0 − 1)e−Lt

as our exact solution to the IVP.

18

Page 19: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(b) Use euler.m to solve the initial value problem with y(0) = 2 for 0 ≤ t ≤ 1 with L := 10k for k := 1:5. For eachL use h = 10−j with j = 1:6. Tabulate the errors.

Solution. Here we use the familiar euler.m that we made and used in a previous problem set (HW 5). Our errorsare as follows:

1 > # h=10e−1, 10e−2, 10e−3, 10e−4, 10e−5, 10e−6 :2 [ 1 ] 2 .02695 1.92223 1.91369 1.91286 1.91277 1.91277 # T = 103 [ 1 ] 1 .96567 1.83300 1.82375 1.82291 1.82282 1.82282 # T = 10ˆ24 [ 1 ] 1 .96566 1.82715 1.81482 1.81391 1.81382 1.81382 # T = 10ˆ35 [ 1 ] 1 .96566 1.82714 1.81424 1.81301 1.81292 1.81292 # T = 10ˆ46 [ 1 ] 1 .96566 1.82714 1.81424 1.81296 1.81283 1.81283 # T = 10ˆ5

Our code to tabulate data and generate plots:

1 L.4 b <− 10ˆ c (1 , 2 , 3 , 4 , 5 )2 h . 4 b <− 10ˆ(−1∗c ( 1 , 2 , 3 , 4 , 5 , 6 ) )3 ya . 4 b <− 2 ;4

5 f o r (L in L . 4 b) {6 abse r r . 4 b <− c ( )7 f o r (h in h . 4 b) {8 n <− 1/h9 t . 4 b <− seq (0 , 1 , by=h)

10 # crea t e L , n−s p e c i f i c v i b r a t o r func t i on11 f . v i b r a t o r <− f unc t i on ( t , y , r ) {12 # sum smal l b e f o r e l a r g e r13 ( y − 1) ∗ exp(−L ∗ t ) + cos (30 ∗ t )14 }15

16 path . vib <− e u l e r f a s t (0 , 1 , ya . 4 b , f . v ib rator , r=1, n+1)17 t rue . 4 b <− f . v i b r a t o r (1 , ya . 4 b , 0 )18 abse r r . 4 b <− c ( abse r r . 4 b , abs ( t rue . 4 b − path . vib ) )19 # plo t ( t . 4 b , path . vib , main=paste ( ’ h= ’ ,h , ’ L= ’ ,L) )20 }21 p lo t ( abse r r . 4 b , main=paste ( ’ Absolute Error f o r each h , with L=’ ,L) , xlab=’ va lue s o f k with h

:=10ˆ(−k ) ’ )22 p lo t ( h . 4 b , l og ( abse r r . 4 b , base=10) , main=paste ( ’ Log Error Against S t ep s i z e h , with L=’ ,L) , xlab

=’ s tep s i z e h ’ , type=’ l ’ )23 pr in t ( abse r r . 4 b , d i g i t s =6) # d i sp l ay24 }25

26 # from PSET 527 e u l e r f u l l <− f unc t i on (a , b , ya , f , r , n ) {28 # RETURNS FULL HISTORY UP TO SOLUTION29 h <− (b − a ) /n # f i x ed time−s tep30 u <− ya # i n i t i a l c ond i t i on s31 ### u . s t o r e used to generate movement p l o t a long un i t c i r c l e32 u . s t o r e <− matrix ( data=NA, nrow = length ( ya ) , nco l = n+1)33 u . s t o r e [ , 1 ] <− ya34 t <− a # s t a r t o f i n t e r v a l35 f o r ( j in 1 : n ) {36 u <− u + h ∗ f ( t , u , r )37 u . s t o r e [ , j +1] <− u38 t <− t + h39 }40 u . s t o r e # outputs matrix o f path , used f o r p l o t t i n g l a t e r41 }42

43 e u l e r f a s t <− f unc t i on (a , b , ya , f , r , n ) {44 # i n i t45 h <− (b − a ) /n # f i x ed time−s tep46 u <− ya # i n i t i a l c ond i t i on s47 t <− a # s t a r t o f i n t e r v a l48 f o r ( j in 1 : n ) {49 u <− u + h ∗ f ( t , u , r )50 t <− t + h51 }52 u # outputs u without path53 }

19

Page 20: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

20

Page 21: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(c) Write a matlab script ieuler which uses the implicit euler method to solve the initial value problem withy(0) = 2 for 0 ≤ t ≤ 1 with L := 10k for k := 1:5. For each L, use h := 10−j with j := 1:6. Tabulate the errors.

Solution. As expected, for each value of L, the smallest stepsize h = 10−6 gives the best results. Our errors are,for h <- 10**(-1*c(1:6)) :

1 > # h = 10e−1, h = 10e−2, h = 10e−3, h = 10e−4, h = 10e−5, h = 10e−6 :2 [ 1 ] 8 .79621 e−01 1.19086 e−01 1.25677 e−02 1.26388 e−03 1.26460 e−04 1.26469 e−05 # L = 103 [ 1 ] 2 .12317 e−01 9.05436 e−03 6.21552 e−04 5.90387 e−05 5.87235 e−06 5.87152 e−07 # L = 10ˆ24 [ 1 ] 2 .47184 e−02 1.13853 e−04 5.15422 e−05 5.55761 e−06 5.59851 e−07 5.57860 e−08 # L = 10ˆ35 [ 1 ] 2 .51304 e−03 2.32978 e−05 6.36230 e−06 6.76338 e−07 6.80910 e−08 6.57281 e−09 # L = 10ˆ46 [ 1 ] 2 .51724 e−04 2.44988 e−06 6.48281 e−07 6.88378 e−08 6.98033 e−09 4.58059 e−10 # L = 10ˆ5

To tabulate data and generate plots, we use:

1 ## Test ing i e u l e r2 # same cond i t i on s as above in 4b3 ya . 4 c <− 24 L.4 c <− 10ˆ c ( 1 : 5 )5 h . 4 c <− 10ˆ(−1∗c ( 1 : 6 ) )6

7 ## tabu la t e e r r o r s8 f o r (L in L . 4 c ) {9 abse r r . 4 c <− c ( )

10 f o r (h in h . 4 c ) {11 n <− 1/h12 t . 4 c <− seq (0 , 1 , by=h)13 # crea t e L , n−s p e c i f i c v i b r a t o r func t i on14 f . v i b r a t o r <− f unc t i on ( t , y , r ) {15 − 30 ∗ s i n (30 ∗ t ) − L ∗ ( y − cos (30 ∗ t ) )16 }17 # df . v i b r a t o r <− f unc t i on ( t , y , r ) {18 # −L ∗ ( y − cos (30 ∗ t ) ) − 30 ∗ s i n (30 ∗ t )19 # }20 df . v i b r a t o r <− f unc t i on ( t , y , r ) { −L }21 path . vib <− i e u l e r f a s t (0 , 1 , ya . 4 c , f . v ib rator , df . v ib rator , r=1, n+1)22 t rue . 4 c <− exp(−L) + cos (30)23 abse r r . 4 c <− c ( abse r r . 4 b , abs ( t rue . 4 c − path . vib ) )24 }25 p lo t ( abse r r . 4 c , main=paste ( ’ Imp l i c i t Euler \n Absolute Error f o r each h , with L=’ ,L) , xlab=’

va lue s o f k with h:=10ˆ(−k ) ’ )26 p lo t ( l og (h . 4 c ) , l og ( abse r r . 4 c , base=10) , main=paste ( ’ Imp l i c i t Euler \n Log Error Against Log

S t ep s i z e h , with L=’ ,L) , type=’ l ’ )27 pr in t ( abse r r . 4 c , d i g i t s =6) # d i sp l ay28 }29

30 i e u l e r f a s t <− f unc t i on (a , b , ya , f , df , r , n ) {31 h <− (b − a ) /n # f i x ed time−s tep32 u <− ya # i n i t i a l c ond i t i on s33 t <− a # s t a r t o f i n t e r v a l34 # to l <− 10ˆ(−12)35 f o r ( j in 1 : n ) {36 u0 <− u37 u1 <− u0 − ( u0 − u − h ∗ f ( t + h , u0 , r ) ) /38 (1 − h ∗ df ( t + h , u0 , r ) )39 f o r ( spam in 1 : ( 3 ∗n/4) ) {40 # whi le ( abs ( u0ˆ2 − u1ˆ2) > t o l ) {41 u0 <− u142 u1 <− u0 − ( u0 − u − h ∗ f ( t + h , u0 , r ) ) /43 (1 − h ∗ df ( t + h , u0 , r ) )44 # }45 u <− u146 t <− t + h47 }48 }49 r e turn (u) # outputs u without path50 }

21

Page 22: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

And our plots (combining per L value) are:

22

Page 23: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

1 f unc t i on [ t , u ] = s o l v e i n t e q ( a , b , kerne l , rhs , p , n )2 % a , b : endpoints o f i n t e r v a l3 % kerne l : f unc t i on handle f o r k e rne l K = ke rne l ( t , s ) o f i n t e g r a l equat ion4 % rhs : f unc t i on handle f o r r i ght−hand s i d e f = rhs ( t , p ) o f i n t e g r a l equat ion5 % p : parameters f o r rhs6 % n : number o f quadrature po in t s and weights7 % t : eva lua t i on po in t s in [ a , b ]8 % u : s o l u t i o n va lues at eva lua t i on po in t s

Problem 5. Write, test and debug a matlab code solveinteq which uses n-point Gaussian quadrature points tiand weights wi on [a, b] (generated by gaussint.m) to approximate the solution y(t) of the integral equations

y(t) +

∫ b

a

K(t, s)y(s) ds = f(t, p) (3)

on the interval a ≤ t ≤ b. Your code should set up the n× n linear system

ui +

n∑j=1

K(ti, tj)wjuj = f(ti, p) (4)

for approximate values ui ≈ y(ti) and solve it by Gaussian elimination with partial pivoting.

Aside. Recall from Lecture 28, Thursday August 8, that Strain considers

u(x) +

∫ 1

0

K(x, y)︸ ︷︷ ︸u(y) dy = g(x)

as a rank 1 perturbation of the identity, as opposed to the Volterra equation

y(t) = y(0) +

∫ t

0

f(s, y(s)) ds

where xi+∑nj=1Aij = bi gives (I+A)x = b, so that x = b−Ax. Strain notes that Fredholm equations are generally

harder than Volterra, but this problem is about having a special kernel

K(x, y) = cos(x) sin(y)

so that ∫ 1

0

cos(x) sin(y) u(y) dy = cos(x)

∫ 1

0

sin(y) u(y) dy.

(a) Suppose [a, b] :=[0, 1] and the kernel K is given by K(t, s) := cos(t) sin(s). For any positive real number m,find a right-hand side f(t,m) such that the exact solution y(t) of the integral equation (3) above is given byym(t) = cos(mt).

Solution. Before solving this rank 1 perturbation problem via matrices, we analytically solve for the case [a, b] :=[0, 1] and K(t, s) := cos(t) sin(s), finding a RHS

f(t,m)

so that the exact solution y(t) to the equation

y(t) +

∫ 1

0

cos(t) sin(s)y(s) ds = f(t, p)

gives ym(t) = cos(mt).

23

Page 24: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

That is, setting the condition y(t) := cos(mt), y(s) := cos(ms) into (3) above, we want some f(t,m) that satisfies:

y(t) +

∫ b

a

K(t, s)y(s) ds = f(t, p)

cos(mt)︸ ︷︷ ︸y(t)

+

∫ 1

0

cos(t) sin(s)︸ ︷︷ ︸K(t,s)

cos(ms)︸ ︷︷ ︸y(s)

ds = f(t, p)

cos(mt) + cos(t)

∫ 1

0

cos(ms) sin(s) ds︸ ︷︷ ︸ = f(t, p),

where we first treat the case m = 1 (recall we’re given m > 0 in the problem) and then use Wolfram Alpha (I havea small brain) to compute this integral otherwise (m 6= 1) :First suppose we have positive real number m = 1, in which case this equation simply becomes (using2 cos(s) sin(s) = sin(2s)):

f(t, p) = cos(t) + cos(t)

∫ 1

0

1

2sin(2s) ds = cos(t) + cos(t)

[−1

4cos(2s)

]10

=

[1 +

1− cos(2)

4

]cos(t)

Now suppose m 6= 1:

Taking the first form and using the trigonometric angle-addition identity cos(a− b) = cos(b− a) = cos(a) cos(b)−sin(a) sin(b), we have:

f(t, p) = cos(mt) + cos(t)

[m sin(s) sin(ms) + cos(s) cos(ms)

m2 − 1

]10

= cos(mt) + cos(t)

[m sin(1) sin(m) + cos(1) cos(m)

m2 − 1−((

(((((

m sin(0) sin(0) =0 +((((((cos(0) cos(0) =1

m2 − 1

]= cos(mt) +

[(m− 1) sin(1) sin(m) + cos(m− 1)− 1

m2 − 1

]cos(t)

So in total, we conclude:

f(t, p) =

[1 + 1−cos(2)

4

]cos(t), m = 1

cos(mt) +[(m−1) sin(1) sin(m)+cos(m−1)−1

m2−1

]cos(t), m ∈ (0, 1) ∪ (1,∞)

24

Page 25: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(b) Solve the problem in (a) numerically by solveinteq, using even n := 2, 4, 6, . . . , 16 and odd integers m =1, 3, 5, . . . , 9. Tabulate the errors at integration points

En := max1≤1≤n

|ui − ym(ti)|

versus m and n.

Solution. Firstly, we were instructed to use a gaussint from a previous homework, which has many dependencieson prior homeworks (i.e. bisection, pleg, ectr). Instead, we use library(‘statmod’) in R for the gauss.quad

function, which should work exactly like the gaussint function we developed. Tabulating errors at integrationpoints, we have:

1 > errTable . 5 b2 > # each row i s m = 1 ,3 ,5 ,7 , 93 > # going down a column ( f i x ed m) g i v e s n = 2 ,4 ,6 ,8 , 10 ,12 ,14 ,164 [ , 1 ] [ , 2 ] [ , 3 ] [ , 4 ] [ , 5 ]5 [ 1 , ] 1 .08252012687 e−03 1.55007669495 e−02 −4.32074948065e−03 −1.03078391278e−01 −9.84097473300e−026 [ 2 , ] 4 .35395013376 e−08 1.11368748568 e−05 2.80552542121 e−05 −1.07699687069e−03 −5.24719093355e−037 [ 3 , ] 2 .35034214313 e−13 9.86015047388 e−10 1.71740159871 e−08 −1.55168634197e−06 −2.25845809637e−058 [ 4 , ] 1 .11022302463 e−16 2.28705943073 e−14 2.17870166352 e−12 −5.96305671507e−10 −2.30101551146e−089 [ 5 , ] 0 .00000000000 e+00 3.33066907388 e−16 5.55111512313 e−16 −8.52651282912e−14 −8.33000335376e−12

10 [ 6 , ] 4 .44089209850 e−16 1.11022302463 e−16 1.11022302463 e−16 5.55111512313 e−16 −1.11022302463e−1511 [ 7 , ] 6 .66133814775 e−16 1.11022302463 e−16 2.22044604925 e−16 2.22044604925 e−16 3.33066907388 e−1612 [ 8 , ] 3 .33066907388 e−16 5.55111512313 e−16 2.22044604925 e−16 4.44089209850 e−16 4.44089209850 e−16

The above matrix is neat as is, but we plot for the visual appeal. Keeping m constant and varying n, we have:

25

Page 26: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

Now holding n constant and varying m, we have:

26

Page 27: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

To tabulate errors and generate plots:

1 ke rne l . 5 b <− f unc t i on ( t , s ) {2 r e turn ( cos ( t ) ∗ s i n ( s ) )3 }4 rhs . 5 b <− f unc t i on ( t , p ) {5 i f e l s e ( p == 1 ,6 (1 + (1 − cos (2 ) ) / 4) ∗ cos ( t ) , # m = 17 cos (p∗ t ) + cos ( t ) ∗ ( (p−1)∗ s i n (1 ) ∗ s i n (p) + cos (p−1) − 1 ) / (p∗∗2 − 1)8 )9 }

10

11 getErr . 5 b <− f unc t i on (n , p) {12 # n : number o f gauss po in t s13 # p : parameter , constant m \ in \R14 tu <− s o l v e i n t e q (0 , 1 , k e rne l . 5 b , rhs . 5 b , p , n)15 t <− tu [ [ 1 ] ] # eva l po in t s16 u <− tu [ [ 2 ] ] # computed so ln17

18 t rue . s o l <− matrix ( nrow = n , nco l = 1)19 f o r ( i in 1 : n ) {20 t rue . s o l [ i ] <− cos ( p ∗ t [ i ] ) # y m( t ) := cos (mt) as d i c t a t ed in part ( a )21 }22 r e turn (max( u − t rue . s o l ) ) # tabu la t e max e r r o r s E n23 }24

25 maxerr . 5 b <− c ( )26 f o r (n in seq (2 ,16 , by=2) ) {27 f o r (m in seq (1 , 9 , by=2) ) {28 maxerr . 5 b <− c (maxerr . 5 b , getErr . 5 b(n ,m) )29 }30 }31

32 errTable . 5 b <− matrix ( data = maxerr . 5 b , nrow= 8 , byrow = TRUE)33

34 ## plo t errTable . 5 b35 f o r (m in 1 : 5 ) {36 p lo t ( seq (2 ,16 , by=2) , l og ( abs ( errTable . 5 b [ ,m] ) , base=10) ,37 main=paste ( ’ Log Error f o r m=’ ,2 ∗m−1) , xlab=’n ’ , y lab=’ Log10 Abs Val Max Err ’ )38 }39

40 f o r (n in 1 : 8 ) {41 p lo t ( seq (1 , 9 , by=2) , l og ( abs ( errTable . 5 b [ n , ] ) , base=10) ,42 main=paste ( ’ Log Error f o r n=’ ,2 ∗n) , xlab=’m’ , ylab=’ Log10 AbsVal Max Err ’ )43 }44

27

Page 28: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

And our solveinteq:

1 s o l v e i n t e q <− f unc t i on ( a , b , kerne l , rhs , p , n ) {2 # return ˜3 # t : eva lua t i on po in t s in [ a , b ]4 # u : s o l u t i o n va lue s at eva l pts5 # a , b : endpoints o f i n t e r v a l6 # kerne l : f unc t i on handle f o r k e rne l7 # K = kerne l ( t , s ) o f i n t e g r a l equat ion8 # rhs : func t i on handle f o r RHS9 # f = rhs ( t , p ) o f i n t e g r a l equat ion

10 # p : parameters f o r rhs11 # n : number o f quadrature po in t s and weights12

13 l i b r a r y ( ’ statmod ’ ) # use f o r gauss . quad func t i on14

15 t <− matrix ( nrow = n , nco l = 1)16 w <− matrix ( nrow = n , nco l = 1)17 B <− matrix ( nrow = n , nco l = 1)18 A <− matrix ( nrow = n , nco l = n)19

20 h <− (b−a ) / 221 m <− ( a+b) / 222

23 wt <− gauss . quad (n) # bu i l t−in ; not gau s s i n t24 gauss .w <− wt$weights25 gauss . t <− wt$nodes26

27 f o r ( i in 1 : n ) {28 w[ i ] <− h ∗ gauss .w[ i ]29 t [ i ] <− m + h ∗ gauss . t [ i ]30 }31 f o r ( i in 1 : n ) {32 B[ i ] <− rhs ( t [ i ] , p )33 f o r ( j in 1 : n ) {34 A[ i , j ] <− w[ j ] ∗ ke rne l ( t [ i ] , t [ j ] )35 }36 }37 r e turn ( l i s t ( t , s o l v e (A + diag (n) ,B) ) ) # t , u38 }39

28

Page 29: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(c) For an arbitrary right-hand side f and the specific kernel K(t, s) = cos(t) sin(s) in part (a) above, find a formulafor the exact solution u of the linear system of equations (4).

Solution. Just as we programmed in part (b), above, here we (analytically) set up the n× n linear system:

ui +

n∑j=1

K(ti, tj)wjuj = f(ti, p),

now for some arbitrary f(ti, p) and only given the kernel K(ti, tj) := cos(ti) sin(tj) and solve for exact solution u.Recall in Lecture on Thursday, Strain gives the following approach to solving a rank-1 perturbation problem:

Let A be a rank-1 matrix, and express A as a row vector left-multiplied by a column vector. That is,

A = abT =

a1...an

[b1 · · · bn]

=

a1b1 · · · a1bn...

...anb1 · · · anbn

Then let (I +A)x = v, so that:

v = x+ a (bTx)︸ ︷︷ ︸scalar

=⇒ x = v − (bTx)︸ ︷︷ ︸ aWe have an idea: let’s take the dot product across the equation with b.

bTx = bT v − (bTx)(bTa)

(1 + bTa)bTx = bT v

and hence if bTa 6= −1,

bTx =bT v

1 + bTa.

To set this up (actually it turns out we reach the same conclusion independently), we set:

f(ti, p)︸ ︷︷ ︸=:v

= ui +

n∑j=1

K(ti, tj)wjuj

= ui +

n∑j=1

[cos(ti) sin(tj)]wjuj

= ui︸︷︷︸=:x

+

n∑j=1

sin(tj)wjuj

︸ ︷︷ ︸

=:bT x, scalar

cos(ti)︸ ︷︷ ︸=:a

,

where this summation gives a constant (scalar) once we know uj . To use the above, we need the appropriateassignments. Namely, we need some b such that

n∑j=1

sin(tj)wjuj = bTx = bT f(ti, p)

To do this, we recall that GEPP (Gaussian Elimination with Partial Pivoting) gives entries of the matrix on themain diagonal, namely i = j. So we write, from the above:

x := ui = v − bTxa = f(ti, p)−

n∑j=1

sin(tj)wj uj︸︷︷︸ cos(ti), (5)

29

Page 30: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

and accordingly, for i = j,

uj = f(tj , p)−

n∑j=1

sin(tj)wjuj

cos(tj).

Now, bringing this into the expression for bTx =∑nj=1 sin(tj)wjuj , we get:

bTx =

n∑j=1

sin(tj)wj[f(tj , p)−

(bTx

)cos(tj)

]=

n∑j=1

sin(tj)wjf(tj , p)− (bTx)

n∑j=1

sin(tj) cos(tj)wj

(bTx)

1 +

n∑j=1

wj2

sin(2tj)

=

n∑j=1

sin(tj)wjf(tj , p)

bTx =

∑nj=1 sin(tj)wjf(tj , p)

1 + 12

∑nj=1 wj sin(2tj)

,

where our trigonometric identity sin(2x) = 2 sin(x) cos(x) actually obscured the fact that we reached the sameconclusion as Strain rather than use his result. Consider:

bTx =

∑nj=1 sin(tj)wjf(tj , p)

1 + 12

∑nj=1 wj sin(2tj)

=

[∑nj=1 sin(tj)wj

]Tf(tj , p)

1 +[∑n

j=1 sin(tj)wj

]Tcos(tj)

=bT v

1 + bTa.

Now with twice the confidence (2 · 0 = 0), we conclude:

ui = f(ti, p)−∑nj=1 sin(tj)wjf(tj , p)

1 + 12

∑nj=1 wj sin(2tj)

cos(ti)

30

Page 31: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(d) Use the error formula for Hermite interpolation to show that the local truncation error in (a)

τi = y(ti) +

n∑j=1

[wjK(ti, tj)y(tj)]− f(ti)

is bounded by

| cos(ti)|

(∫ 1

0

n∏i=1

(t− ti)2 dt

)∣∣∣∣v(2n)(ξ)(2n)!

∣∣∣∣as n→∞, where v(s) := sin(s)y(s).

Solution. At the start of the problem, we are given:

y(t) +

∫ b

a

K(t, s)y(s) ds = f(t, p), (we use this here)

ui +n∑j=1

K(ti, tj)wjuj = f(ti, p) (we use this in part (e))

and in part (a), we found:

f(t, p) =

[1 + 1−cos(2)

4

]cos(t), m = 1

cos(mt) +[(m−1) sin(1) sin(m)+cos(m−1)−1

m2−1

]cos(t), m ∈ (0, 1) ∪ (1,∞)

Now we consider for [a, b] := [0, 1], with t = ti, s = tj for discretization, the local truncation error in (a) is given as:

τi = y(ti) +

n∑j=1

[wjK(ti, tj)y(tj)]− f(ti, p)︸ ︷︷ ︸=��

�y(ti) +

n∑j=1

[wjK(ti, tj)y(tj)]−

[���y(ti) +

∫ b

a

K(ti, s)y(s) ds

]

=

n∑j=1

[wj cos(ti) sin(tj)y(tj)]−∫ 1

0

cos(ti) sin(s)y(s) ds

= cos(ti)

n∑j=1

[wj sin(tj)y(tj)]−∫ 1

0

sin(s)y(s) ds

,where our chosen interpolation points are gaussian integration points. Recall from the Gaussian Integration handoutposted online by Strain (gauss.pdf), ‘We use Hermite interpolation to build integration rules with degree ofprecision 2n + 1 and points tj ’. So the bracketed expression is the interpolation error via our familiar Hermiteinterpolation error expression, which from our Homework 4, we proved precisely that each of the three factors inthe following error estimate is inevitable:∫ b

a

f(x) dx−5∑j=1

ujf(yj) =1

(2 · 5)!f (10)(ξ)

∫ b

a

5∏i=1

(y − yi)2 dy.

Because we showed one example in class and now one more in a previous homework, by Strain induction, we havea theorem for all n ∈ N:Theorem. ∫ b

a

f(x) dx−n∑j=1

ujf(yj) =f (2n)(ξ)

(2n)!

∫ b

a

n∏i=1

(y − yi)2 dy

31

Page 32: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

Using this theorem on our previous equations for local truncation error, setting v(s) := sin(s)y(s) as instructed, wehave:

|τi| =

∣∣∣∣∣∣cos(ti)

n∑j=1

[wj sin(tj)y(tj)]−∫ 1

0

sin(s)y(s) ds

∣∣∣∣∣∣= |cos(ti)|

∣∣∣∣∣∣n∑j=1

[wjv(tj)]−∫ 1

0

v(s) ds

∣∣∣∣∣∣= |cos(ti)|

∣∣∣∣v(2n)(ξ)(2n)!

∣∣∣∣∣∣∣∣∣∫ 1

0

n∏i=1

(t− ti)2 dt

∣∣∣∣∣ ,which was to be shown.

32

Page 33: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

(e) Assume that all the derivatives of the exact solution y in (a) are bounded by

|y(n)(t)| ≤ mn

for some fixed m > 0. Use parts (d) and (c) to prove that

En ≤ 2 maxi|τi| → 0

as n→∞.

Solution. Let i ∈ 1 : n. Suppose that En is as we defined in lecture to be a relaxed error bound:

En := maxi|y(ti)− ui| .

Now instead of comparing against the integral, we use (as given in the beginning of the question):

ui +

n∑j=1

K(ti, tj)wjuj = f(ti, p).

Expecting to not cancel y(ti) but instead get an error term ei := y(ti) − ui, we use the given expression for localtruncation error from (d) to write:

τi = y(ti) +

n∑j=1

[wjK(ti, tj)y(tj)]− f(ti)

= y(ti) +

n∑j=1

wjK(ti, tj)y(tj)−

ui +

n∑j=1

wjK(ti, tj)uj

= y(ti)− ui +

n∑j=1

wjK(ti, tj)[y(tj)− uj ]

= ei +

n∑j=1

wjK(ti, tj)ej =⇒ ei = y(ti)− ui = τi −n∑j=1

wjK(ti, tj)ej

From part (c), we showed:

ui = f(ti, p)−∑nj=1 sin(tj)wjf(tj , p)

1 + 12

∑nj=1 wj sin(2tj)

cos(ti)

= f(ti, p)−∑nj=1 cos(ti) sin(tj)wjf(tj , p)

1 + 12

∑nj=1 wj sin(2tj)

= f(ti, p)−∑nj=1 wjK(ti, tj)f(tj , p)

1 + 12

∑nj=1 wj sin(2tj)

so bringing τj into our boxed expression above as f(ti, p) gives:

ei = τi −wjK(ti, tj)τj

1 + 12

∑nj=1 wj sin(2tj)

Now because the factors in the fraction are nonnegative (to see this, consider the weights are nonnegative, and∀tj∈[0,1], sin(tj), sin(2tj) ≥ 0), we conclude that a relaxed (but valid) error bound is to take

|ei| ≤ |τi| ≤ maxi|τi|, and

∣∣∣∣∣ wjK(ti, tj)τj

1 + 12

∑nj=1 wj sin(2tj)

∣∣∣∣∣ ≤ maxi|τi|

33

Page 34: Math 128A, Summer 2019 - Daniel Suryakusuma · Math 128A, PSET #6 Daniel Suryakusuma, 24756460 Math 128A, Summer 2019 PSET #6 (due Wednesday 8/7/2019) 1 function[p,q] = pcoeff (t

Math 128A, PSET #6 Daniel Suryakusuma, 24756460

Recall that we defined En := maxi |y(ti)− ui| at the beginning of the problem, so we have:

En = maxi|y(ti)− ui| = max

i|ei|

= maxi

∣∣∣∣∣τi − wjK(ti, tj)τj

1 + 12

∑nj=1 wj sin(2tj)

∣∣∣∣∣≤ max

i|τi|+ max

i

∣∣∣∣∣− wjK(ti, tj)τj

1 + 12

∑nj=1 wj sin(2tj)

∣∣∣∣∣≤ max

i|τi|+ max |τi|

= 2 ·maxi|τi| ,

as desired.

34