% this saves the entire matlab session into a file called "diary" which % you can then edit: >> diary on % this finds the root for the function f, using the bisection method % starting on the interval [-1000,1000]. It prints the length of the % interval to the screen >> [root,value,steps,A] = bisect(-1000,1000,10^(-7)); ans = 2000 ans = 1000 ans = 500 ans = 250 ans = 125 ans = 62.5000 ans = 31.2500 ans = 15.6250 ans = 7.8125 ans = 3.9062 ans = 1.9531 ans = 0.9766 ans = 0.4883 ans = 0.2441 ans = 0.1221 ans = 0.0610 ans = 0.0305 ans = 0.0153 ans = 0.0076 ans = 0.0038 ans = 0.0019 ans = 9.5367e-04 ans = 4.7684e-04 ans = 2.3842e-04 ans = 1.1921e-04 ans = 5.9605e-05 ans = 2.9802e-05 ans = 1.4901e-05 ans = 7.4506e-06 ans = 3.7253e-06 ans = 1.8626e-06 ans = 9.3132e-07 ans = 4.6566e-07 ans = 2.3283e-07 ans = 1.1642e-07 ans = 5.8208e-08 % find the size of A >> size(A) ans = 100 3 % the first interval and its midpoint >> A(1,:) ans = -1000 0 1000 % the second interval and its midpoint >> A(2,:) ans = -1000 -500 0 % the third interval and its midpoint >> A(3,:) ans = -500 -250 0 >> A(4,:) ans = -250 -125 0 >> A(5,:) ans = -125.0000 -62.5000 0 >> A(6,:) ans = -62.5000 -31.2500 0 % define err to be the distance from the left-hand point to the midpoint >> for i=1:100, err(i) = A(i,2)-A(i,1); end >> err err = 1.0e+03 * Columns 1 through 7 1.0000 0.5000 0.2500 0.1250 0.0625 0.0312 0.0156 Columns 8 through 14 0.0078 0.0039 0.0020 0.0010 0.0005 0.0002 0.0001 Columns 15 through 21 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 Columns 22 through 28 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 Columns 29 through 35 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 Columns 36 through 42 0 0 0 0 0 0 0 Columns 43 through 49 0 0 0 0 0 0 0 Columns 50 through 56 0 0 0 0 0 0 0 Columns 57 through 63 0 0 0 0 0 0 0 Columns 64 through 70 0 0 0 0 0 0 0 Columns 71 through 77 0 0 0 0 0 0 0 Columns 78 through 84 0 0 0 0 0 0 0 Columns 85 through 91 0 0 0 0 0 0 0 Columns 92 through 98 0 0 0 0 0 0 0 Columns 99 through 100 0 0 % want to see more significant figures >> format long >> err err = 1.0e+03 * Columns 1 through 4 1.00000000000000 0.50000000000000 0.25000000000000 0.12500000000000 Columns 5 through 8 0.06250000000000 0.03125000000000 0.01562500000000 0.00781250000000 Columns 9 through 12 0.00390625000000 0.00195312500000 0.00097656250000 0.00048828125000 Columns 13 through 16 0.00024414062500 0.00012207031250 0.00006103515625 0.00003051757812 Columns 17 through 20 0.00001525878906 0.00000762939453 0.00000381469727 0.00000190734863 Columns 21 through 24 0.00000095367432 0.00000047683716 0.00000023841858 0.00000011920929 Columns 25 through 28 0.00000005960464 0.00000002980232 0.00000001490116 0.00000000745058 Columns 29 through 32 0.00000000372529 0.00000000186265 0.00000000093132 0.00000000046566 Columns 33 through 36 0.00000000023283 0.00000000011642 0.00000000005821 0 Columns 37 through 40 0 0 0 0 Columns 41 through 44 0 0 0 0 Columns 45 through 48 0 0 0 0 Columns 49 through 52 0 0 0 0 Columns 53 through 56 0 0 0 0 Columns 57 through 60 0 0 0 0 Columns 61 through 64 0 0 0 0 Columns 65 through 68 0 0 0 0 Columns 69 through 72 0 0 0 0 Columns 73 through 76 0 0 0 0 Columns 77 through 80 0 0 0 0 Columns 81 through 84 0 0 0 0 Columns 85 through 88 0 0 0 0 Columns 89 through 92 0 0 0 0 Columns 93 through 96 0 0 0 0 Columns 97 through 100 0 0 0 0 >> quit 2599 flops.