>> % NEWTON >> f = @(x) cos(x) - x f = @(x) cos (x) - x >> x = -10:.01:10; plot(x,f(x)), grid on >> format long >> x = 1 x = 1 >> df = @(x) -sin(x) - 1 df = @(x) -sin (x) - 1 >> x = x - f(x) / df(x) x = 0.750363867840244 >> x = x - f(x) / df(x) x = 0.739112890911362 >> x = x - f(x) / df(x) x = 0.739085133385284 >> x = x - f(x) / df(x) x = 0.739085133215161 >> x = x - f(x) / df(x) x = 0.739085133215161 >> f(x) ans = 0 >> >> % SECANT >> xold = 1 xold = 1 >> x = 0.8 x = 0.800000000000000 >> xnew = x - f(x) / ( (f(x) - f(xold)) / (x - xold) ), xold = x; x = xnew; xnew = 0.742035906602420 >> xnew = x - f(x) / ( (f(x) - f(xold)) / (x - xold) ), xold = x; x = xnew; xnew = 0.739123508315782 >> xnew = x - f(x) / ( (f(x) - f(xold)) / (x - xold) ), xold = x; x = xnew; xnew = 0.739085158179144 >> xnew = x - f(x) / ( (f(x) - f(xold)) / (x - xold) ), xold = x; x = xnew; xnew = 0.739085133215372 >> xnew = x - f(x) / ( (f(x) - f(xold)) / (x - xold) ), xold = x; x = xnew; xnew = 0.739085133215161 >> xnew = x - f(x) / ( (f(x) - f(xold)) / (x - xold) ), xold = x; x = xnew; xnew = 0.739085133215161 >> >> % BISECTION >> a = 0.5, b= 1 a = 0.500000000000000 b = 1 >> f(a)*f(b) ans = -0.173573833045405 >> c = (a+b)/2, f(a), f(b), f(c) c = 0.750000000000000 ans = 0.377582561890373 ans = -0.459697694131860 ans = -0.0183111311261791 >> b = c b = 0.750000000000000 >> c = (a+b)/2, f(a), f(b), f(c) c = 0.625000000000000 ans = 0.377582561890373 ans = -0.0183111311261791 ans = 0.185963119505218 >> a = c a = 0.625000000000000 >> c = (a+b)/2, f(a), f(b), f(c) c = 0.687500000000000 ans = 0.185963119505218 ans = -0.0183111311261791 ans = 0.0853349461524715 >> a = c a = 0.687500000000000 >> c = (a+b)/2, f(a), f(b), f(c) c = 0.718750000000000 ans = 0.0853349461524715 ans = -0.0183111311261791 ans = 0.0338793724180665 >> a = c a = 0.718750000000000 >> c = (a+b)/2, f(a), f(b), f(c) c = 0.734375000000000 ans = 0.0338793724180665 ans = -0.0183111311261791 ans = 0.00787472545850132 >> a = c a = 0.734375000000000 >> c = (a+b)/2, f(a), f(b), f(c) c = 0.742187500000000 ans = 0.00787472545850132 ans = -0.0183111311261791 ans = -0.00519571174375921 >> b = c b = 0.742187500000000 >> c = (a+b)/2, f(a), f(b), f(c) c = 0.738281250000000 ans = 0.00787472545850132 ans = -0.00519571174375921 ans = 0.00134514975180511 >> a = c a = 0.738281250000000 >> c = (a+b)/2, f(a), f(b), f(c) c = 0.740234375000000 ans = 0.00134514975180511 ans = -0.00519571174375921 ans = -0.00192387278089767 >> b = c b = 0.740234375000000 >> c = (a+b)/2, f(a), f(b), f(c) c = 0.739257812500000 ans = 0.00134514975180511 ans = -0.00192387278089767 ans = -2.89009146790087e-04 >> c c = 0.739257812500000 >> c % bisection estimate after 9 steps c = 0.739257812500000 >> % use Newton to recall solution >> x=1; for k=1:10, x = x - f(x) / df(x); end, x x = 0.739085133215161 >> diary off