Lab 01b Summary M. M. Sussman $Id: summary.txt,v 1.10 2016/12/22 21:03:18 mike Exp $ {@(#) Wed Dec 30 16:16:05 2015 } EXERCISE 1 1. q_elt.m 2. following are zero or roundoff q_elt(@(x,y) 1,0,0,1)-1 q_elt(@(x,y) 4*x*y,0,0,1)-1 q_elt(@(x,y) 6*x^2*y,0,0,1)-1 q_elt(@(x,y) 9*x^2*y^2,0,0,1)-1 q_elt(@(x,y) 16*x^3*y^3,0,0,1)-1 3. q_elt(@(x,y) 25*x^4*y^4,0,0,1)-1=-0.054784 .NE. 0 CHECK they have the correct integral! EXERCISE 2 1. qerr_elt.m (using q_elt.m) 2. [q,errest]=qerr_elt(inline('16*x^3*y^3'),0,0,1);q-1,errest both zero 3. [q,errest]=qerr_elt(inline('25*x^4*y^4'),0,0,1); q-1=-0.0034692, errest=-0.0034210, rel diff=1.4% CHECK pct diff in errors EXERCISE 3 1. q_total.m with: h=H/n; elt(elt_count).x=x+(k-1)*h; elt(elt_count).y=y+(j-1)*h; elt(elt_count).h=h; 2. area [0,1]X[0,1]=1 using 10 per side 3. area [-1,1]X[-1,1]=4 using 13 per side 4. add qerr_elt calls for q, errest 5. q=1, errest=roundoff for @(x,y)9*x^2*y^2 over [0,1]X[0,1] and n=1 6. q=4, errest=roundoff for @(x,y)9*x^2*y^2 over [-1,1]X[-1,1] and n=1 7. q=1, errest=roundoff for @(x,y)16*x^3*y^3 and n=2 8. n integral estimated error true error 2 0.99978 2.1681e-04 -2.1700e-04 4 0.99999 1.3563e-05 -1.3563e-05 8 1.00000 8.4771e-07 -8.4771e-07 16 1.00000 5.2982e-08 -5.2982e-08 9. 8.4771e-07/5.2982e-8=16: yes, O(h^4). EXERCISE 4 1. copy three_peaks.m 2. n integral estimated error true error 10 1.7553 1.4612e-04 5.4743e-05 20 1.7552 4.6100e-06 7.2122e-08 40 1.7552 4.2841e-07 1.3603e-09 80 1.7552 2.6741e-08 8.5084e-11 160 1.7552 1.6985e-09 5.3602e-12 3. 8.5084e-11/5.3602e-12=15.9, consistent with O(h^4) 4. q_total_noabs.m w/o abs: for n=80, esterr=8.5015e-11, almost same as true EXERCISE 5 1. q_adaptive.m 2. 16*x^3*y^3 over [0,1]X[0,1] exactly 1 3. 9*x^2*y^2 over [-1,1]X[-1,1] exactly 4 4. 25*x^4*y^4 over [0,1]X[0,1]: q = 0.99978 errest = 2.1681e-04 q-1 = -2.1700e-04, length(elt)=4 5. 25*x^4*y^4 over [0,1]X[0,1], tol=2.e-4: q-1 =-1.184587e-04 errest = 1.18317e-04 length(elt)=7 EXERCISE 6 1. Download plotelt.m 2. 25*x^4*y^4, tolerance=1.e-6: q-1 = -9.5015e-07 q = 0.99999 errest = 9.5001e-07 length(elt) = 55 3. plot: red at UR corner, some red along top and right two big reds near lower left corner 4. tol=9.e-7 two big reds are gone, refined once 5. tol=5.e-7, many smaller blocks along top and right are refined. EXERCISE 7 Integrate three_peaks over [-1,1]X[-1,1], tolerance=1.e-5 q=1.7552, errest=9.7671e-06, q-1.75522375591726=-5.2826e-6, 145 elts, PLOT EXERCISE 8 1. A*Ainv=identity 2. B*Binv, upper 5x5 is 5 reps of the line: 4194304 4194304 131072 0 0 A(1,:)*Ainv(:,1)=1 B(1,:)*Binv(:,1)=4194304 A(1,6)*Ainv(6,1)=-120 A(1,5)*Ainv(5,1)= 240 A(1,4)*Ainv(4,1)=-180 A(1,3)*Ainv(3,1)= 80 A(1,2)*Ainv(2,1)= -25 A(1,1)*Ainv(1,1)= 6 sum = 1 B(1,24)*Binv(24,1)=-2.5852e+22 B(1,23)*Binv(23,1)= 5.1704e+22 B(1,22)*Binv(22,1)=-3.8778e+22 B(1,21)*Binv(21,1)= 1.7235e+22 B(1,20)*Binv(20,1)=-5.3858e+21 B(1,16)*Binv(16,1)=-5.7705e+18 B(1,11)*Binv(11,1)= 5.8122e+13 B(1,6) *Binv(6,1) =-76719720 B(1,1) *Binv(1,1) = 24 EXERCISE 9 1. copy exer9.m: CHECK comments 2. exer9(160) error=0.055250 + plot 3. exer9(10) error=84.772 + plot 4. nsteps error ratio 10 84.772164 122.3186 20 0.693044 2.6850 40 0.258120 2.2281 80 0.115845 2.0967 160 0.055250 first order: p=1 EXERCISE 10, extra credit 1. x=single(0.9999) 2. S=formula for sum= 9997.8877 3. a=9994.9707 4. b=9997.8994 5. a and S agree to 3 sig digits, b and S to 6 or 7 6. rel err a=2.9176e-04, rel err b=1.1721e-06 7. a1000=952.6, x^1001=.90 8. Why is b better?