This document contains code for two root-finding algorithms: the fixed point method and the secant method. The fixed point method code takes an initial guess xo and error es, iterates xo^3 + 1 until the error is below es, and returns the root xr and number of iterations i. The secant method code takes initial guesses xo and x1, error es, and uses the secant line between points to update the next guess xi until error is below es, returning xr and i. Both methods iterate up to 200 times before terminating.
This document contains code for two root-finding algorithms: the fixed point method and the secant method. The fixed point method code takes an initial guess xo and error es, iterates xo^3 + 1 until the error is below es, and returns the root xr and number of iterations i. The secant method code takes initial guesses xo and x1, error es, and uses the secant line between points to update the next guess xi until error is below es, returning xr and i. Both methods iterate up to 200 times before terminating.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online from Scribd
This document contains code for two root-finding algorithms: the fixed point method and the secant method. The fixed point method code takes an initial guess xo and error es, iterates xo^3 + 1 until the error is below es, and returns the root xr and number of iterations i. The secant method code takes initial guesses xo and x1, error es, and uses the secant line between points to update the next guess xi until error is below es, returning xr and i. Both methods iterate up to 200 times before terminating.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online from Scribd
ea = es + 1; i = 0; if (abs(3*xo^2)>=1 || (3*xo^2)==0) else while (ea>es) xi = xo^3 + 1; ea = abs((xi-xo)/xi); xo = xi; i = i + 1; if (i == 200) break; end end xr = xi; end
Secant Method Code:
function [xr i] = Secant (xo,x1,es) ea = es + 1; i = 0; while (Ea>Es) xi = x1-(x1^3 - x1 + 1)*(x1-xo)/((x1^3 - x1 + 1)-(xo^3 - xo + 1)); ea = abs((xi-x1)/xi); xo = x1; x1 = xi; i = i + 1; if (i == 200) break; end end xr = xi; end