NON-LINEAR EQUATIONS ==================== The following is a MATLAB session, in which several root finding methods are applied to find a root of the function cubic. Its derivative, cubic_der, is used in Newton's Method. Note that the programs do not use "natural" stopping criteria (hence, for example, the division by zero with the Secant Method.) Notice how much faster Newton's Method and the Secant Method are relative to the Bisection Method. ============================================================================== function y=cubic(x) y=x^3-x-6; end; ============================================================================== function y=cubic_der(x) y=3*x^2-1; end; ============================================================================== >> format long >> bisection('cubic',0,3,50) ans = Columns 1 through 4 1.50000000000000 2.25000000000000 1.87500000000000 2.06250000000000 Columns 5 through 8 1.96875000000000 2.01562500000000 1.99218750000000 2.00390625000000 Columns 9 through 12 1.99804687500000 2.00097656250000 1.99951171875000 2.00024414062500 Columns 13 through 16 1.99987792968750 2.00006103515625 1.99996948242188 2.00001525878906 Columns 17 through 20 1.99999237060547 2.00000381469727 1.99999809265137 2.00000095367432 Columns 21 through 24 1.99999952316284 2.00000023841858 1.99999988079071 2.00000005960464 Columns 25 through 28 1.99999997019768 2.00000001490116 1.99999999254942 2.00000000372529 Columns 29 through 32 1.99999999813735 2.00000000093132 1.99999999953434 2.00000000023283 Columns 33 through 36 1.99999999988358 2.00000000005821 1.99999999997090 2.00000000001455 Columns 37 through 40 1.99999999999272 2.00000000000364 1.99999999999818 2.00000000000091 Columns 41 through 44 1.99999999999955 2.00000000000023 1.99999999999989 2.00000000000006 Columns 45 through 48 1.99999999999997 2.00000000000001 1.99999999999999 2.00000000000000 Columns 49 through 50 2.00000000000000 2.00000000000000 >> newton('cubic','cubic_der',3,10) ans = Columns 1 through 4 3.00000000000000 2.30769230769231 2.04181989484242 2.00092462158247 Columns 5 through 8 2.00000046599634 2.00000000000012 2.00000000000000 2.00000000000000 Columns 9 through 11 2.00000000000000 2.00000000000000 2.00000000000000 >> secant('cubic',3,4,10) Warning: Divide by zero ans = Columns 1 through 4 3.00000000000000 4.00000000000000 2.50000000000000 2.27200000000000 Columns 5 through 8 2.05723296766887 2.00753962342663 2.00022971811026 2.00000094194724 Columns 9 through 12 2.00000000011802 2.00000000000000 2.00000000000000 NaN >> quit 670 flops.