\documentclass[12pt, letterpaper]{article}

\usepackage{graphicx}
\usepackage{epsfig}
\usepackage{amssymb}
\usepackage{geometry}
\usepackage{setspace}

\title{Homework 3}
\author{Menyoung Lee}
\geometry{margin=1in}
%\doublespacing

\begin{document}
\maketitle

\subsection*{P1}
The plots show both $y = x$ (in blue), $f(x)$ (also in blue), and $g(x)$ (green) as well as the fpi diagram plot (once again blue).
Newton's method printout:
\begin{verbatim}
f = inline('3*cos(4*x) + 14*cos(2*x).*sin(x) - 15*cos(2*x) - 11*sin(x)
						+ 11')

f =
     Inline function:
     f(x) = 3*cos(4*x) + 14*cos(2*x).*sin(x) - 15*cos(2*x) - 11*sin(x)+11


g = inline('-12*sin(4*x) + 14*(-2*sin(2*x).*sin(x)+cos(2*x).*cos(x))
						+ 30*sin(2*x) - 11*cos(x)')

g =
     Inline function:
     g(x) = -12*sin(4*x) + 14*(-2*sin(2*x).*sin(x)+cos(2*x).*cos(x))
						+ 30*sin(2*x) - 11*cos(x)

(g here is the derivative, not the g for Newton fpi)

newton(f, g, -0.5, 0.0000000001, 0.5)

r =

  -0.33983690945412


ans =

  |       x_i       |      g(x_i)      |       error      |   error ratio   
  -0.50000000000000  -0.38499267963579   0.16016309054588                  0
  -0.38499267963579  -0.34519615006708   0.04515577018166   0.28193618159941
  -0.34519615006708  -0.33992694933625   0.00535924061296   0.11868340616054
  -0.33992694933625  -0.33983693552615   0.00009003988213   0.01680086576319
  -0.33983693552615  -0.33983690945412   0.00000002607203   0.00028956085939
  -0.33983690945412  -0.33983690945412   0.00000000000000   0.00000009368243
  -0.33983690945412  -0.33983690945412   0.00000000000000   0.11363636363636


newton(f, g, 0.5, 0.0000000001, 0.5)

r =

   0.52359630078870


ans =

  |       x_i       |      g(x_i)      |       error      |   error ratio   
   0.50000000000000   0.50788132816905   0.02359630078870                  0
   0.50788132816905   0.51312651126278   0.01571497261964   0.66599306223336
   0.51312651126278   0.51661975397137   0.01046978952591   0.66623021110634
   0.51661975397137   0.51894714334656   0.00697654681733   0.66635024515628
   0.51894714334656   0.52049813681164   0.00464915744213   0.66639808545208
   0.52049813681164   0.52153187784706   0.00309816397705   0.66639257018370
   0.52153187784706   0.52222092886745   0.00206442294164   0.66633753310988
   0.52222092886745   0.52268024851408   0.00137537192125   0.66622584621954
   0.52268024851408   0.52298644064974   0.00091605227461   0.66603968022104
   0.52298644064974   0.52319055953961   0.00060986013895   0.66574818474416
   0.52319055953961   0.52332663450846   0.00040574124908   0.66530212939707
   0.52332663450846   0.52341735020372   0.00026966628023   0.66462623862714
   0.52341735020372   0.52347782611110   0.00017895058498   0.66360015357257
   0.52347782611110   0.52351814345040   0.00011847467760   0.66205247451647
   0.52351814345040   0.52354502354606   0.00007815733829   0.65969656871308
   0.52354502354606   0.52356294530766   0.00005127724264   0.65607713566020
   0.52356294530766   0.52357487500129   0.00003335548103   0.65049287595277
   0.52357487500129   0.52358285443287   0.00002142578741   0.64234682700063
   0.52358285443287   0.52358824904516   0.00001344635583   0.62757814086887
   0.52358824904516   0.52359153987740   0.00000805174353   0.59880488346504
   0.52359153987740   0.52359328110033   0.00000476091130   0.59128948639768
   0.52359328110033   0.52359630078870   0.00000301968837   0.63426688268604
   0.52359630078870   0.52359630078870                  0                  0
   0.52359630078870   0.52359630078870                  0                NaN

exit
\end{verbatim}

\includegraphics[width=5in]{hw3-1.png}

\includegraphics[width=5in]{hw3-2.png}

\subsection*{P2}
According to newton.m:
\[r_1 = -0.33983690945412\]
I trust this one to 7 digits, the smallest digit to stay constant at the last meaningful step.
\[r_2 = 0.52359630078870\]
I trust this one to 5 digits, the smallest digit to stay constant at the last meaningful step.

\subsection*{P3}
Newton's method converges quadratically to $r_1$, as shown by the decreasing error ratio (except for weirdness of the last one).
Meanwhile, it only seems to converge linearly to $r_2$---the error ratio stays around 0.6 and doesn't drop significantly.

\subsection*{P4}
For Newton's method, the error ratio, i.e. $g'(x)$, is $\frac{f(x)f"(x)}{f'(x)^2}$.
For $r_1$, $f(x)=0$ while $f'(x) \neq 0$, and therefore theoretically the error ratio is 0, and the error ratio indeed does go to 0.
For $r_2$, $f(x) = f'(x) = 0$, so we need to simplify the expression to obtain the theoretical error.
\[f(x) = 3cos(4x) + 14cos(2x)sin(x) - 15cos(2x) - 11sin(x)+11\]
\[f'(x) = -12sin(4x) + 14(-2sin(2x)sin(x)+cos(2x)cos(x)) + 30sin(2x) - 11cos(x)\]
\[f"(x) = -48cos(4x) + 14(-2(2cos(2x)sin(x)+sin(2x)cos(x)) + -2sin(2x)cos(x) - cos(2x)sin(x)) + 60cos(2x) + 11sin(x)\]
See graph of $\frac{f(x)f"(x)}{f'(x)^2}$ near the root (the discontinuity is obvious):

\includegraphics[width=5in]{hw3-3.png}

The ratio is $\frac{2}{3}$, and it isn't too far away from the eror ratio shown by newton.m, which seems to be around that.

\subsection*{P5}
Starting at -0.125325 gets you to 11680.16.

\begin{verbatim}
>> newton(f, g, -0.125325, 0.0000000001, 100000)

r =

     1.168010164913740e+04

ans =

  |       x_i       |      g(x_i)      |       error      |   error ratio   

ans =

   1.0e+04 *

  -0.00001253250000   1.16802348140508   1.16802269741374                  0
   1.16802348140508   1.16799470408663   0.00001331649134   0.00000000114009
   1.16799470408663   1.16800588580176   0.00001546082711   0.00011610285861
   1.16800588580176   1.16800967892816   0.00000427911198   0.00002767712202
   1.16800967892816   1.16801015749185   0.00000048598558   0.00001135715960
   1.16801015749185   1.16801016491197   0.00000000742189   0.00000152718248
   1.16801016491197   1.16801016491374   0.00000000000177   0.00000002387123
   1.16801016491374   1.16801016491374                  0                  0
   1.16801016491374   1.16801016491374                  0                NaN
\end{verbatim}

\end{document}


