3
$\begingroup$

Given $2$ equations: $$\text{1) }\ y= \sin (x),\ \ \ \text{2) }\ y= x^3-2x^2+1.$$ I was told to look a graph online, and then solve using newton's method. After looking it up, I realized that there are $3$ separate intervals in which you had to solve on.

I set $\sin (x)$=$3x^2-2x^2+1$. Then I moved $\sin(x)$ over, getting $x^3-2x^2+1-\sin(x)=0$, with the interval $[0,1]$. Then, I set up, and used Newton's equation. $$x_{n+1}=x_n-{x_n^3-2x_n^2+1-\sin(x_n)\over 3x_n^2-4x_n-\cos(x_n)}.$$ After making a common denominator and simplifying more, I got: $$x_{n+1}= {2x_n^3-2x_n^2-\cos(x_n^2)+\sin(x_n)-1\over 3x_n^2-4x_n-\cos(x_n)}.$$ After doing Newton's method on my calculator, the values keep jumping around. I started with $x_1=1$. The real answer is about $.568$. When using newtons method, for $x_2$, I got $.294$... and $x_3 \sim .935$ and $x_4 \sim .3514$...

The numbers keep jumping around. I'm confused what I did wrong. Did I do the wrong range, or am I plugging it into my calculator wrong, or is my equations wrong?

$\endgroup$
9
  • $\begingroup$ In the future, note that \cos and \sin render much better and rather than using x_(n+1), you should use x_{n+1}. In general, "{$\dots$}" group stuff so you can do whatever it is you want to do to it as a grouped object. $\endgroup$ Sep 19 '16 at 1:40
  • 1
    $\begingroup$ I know the formatting isn't that good, but can anyone still try explaining to me why I can't find the correct answer; .568. $\endgroup$
    – AfronPie
    Sep 19 '16 at 1:49
  • 2
    $\begingroup$ If you implement it s Moo said above then it works perfectly fine: if $0 \lesssim x_0 \lesssim 1$ then it will converge to the zero at $\simeq 0.568$. For larger $x_0$ it will converge to $\simeq 1.979$ which is a second root. For $x_0 \lesssim 0$ it will converge to the third root $\simeq -0.782$. $\endgroup$
    – Winther
    Sep 19 '16 at 2:02
  • 1
    $\begingroup$ @AaronM What?! Um, you can't just change things around willy nilly and expect them that it "doesn't really matter mathematically..." because it does. $\endgroup$ Sep 19 '16 at 2:04
  • 1
    $\begingroup$ $x_ {n + 1}= x_n - \dfrac {x_n^3 - 2 x_n^2 - \sin (x_n) + 1} {3 x_n^2 - 4 x_n - \cos (x_n)} $, choose $x_0 = 0.5$, the result is $x^{*} = 0.5680257385175188$. $\endgroup$
    – Moo
    Sep 19 '16 at 2:24
6
$\begingroup$

I did not not understand why, starting with $x_0=1$, you have problem $$f(x)=x^3-2 x^2+1-\sin (x)$$ $$f'(x)=3 x^2-4 x-\cos (x)$$ $$x_{n+1}=x_n-\frac{f(x_n)}{f'(x_n)}=\frac{2 x_n^3-2 x_n^2+\sin (x_n)-x_n \cos (x_n)-1}{3 x_n^2-4 x_n-\cos (x_n)}$$ So, the iterates are $$\left( \begin{array}{cc} n & x_n \\ 0 & 1 \\ 1 & 0.5798249292 \\ 2 & 0.5765888390 \\ 3 & 0.5765861544 \end{array} \right)$$

In fact, your first formula is totally correct but "after making a common denominator and simplifying more", there is a "small" mistake : $x_n \cos(x_n)$ is not $\cos(x_n^2)$.

$\endgroup$
8
  • $\begingroup$ Thanks so much! I'd never find that mistake even if I did the problem hundreds of times. $\endgroup$
    – AfronPie
    Sep 19 '16 at 6:29
  • $\begingroup$ @AaronM. You are very welcome. May I confess that I did not see it at first galnce ? $\endgroup$ Sep 19 '16 at 6:40
  • $\begingroup$ @ClaudeLeibovici Nah, I didn't see it either. Totally glanced over once I saw the first equation was right. $\endgroup$ Sep 19 '16 at 12:25
  • $\begingroup$ Yeah, it really bothered me because the roots kept bouncing, and I knew they should be converging to .568. Thanks again. $\endgroup$
    – AfronPie
    Sep 19 '16 at 22:37
  • 1
    $\begingroup$ @AaronM: What Claude is saying is that Newton's method may fail even if there is a root. You must not ignore the required conditions if you want it to converge. If you do not start close enough to the root, it is possible that it oscillates, such as for $( x \mapsto \frac{x}{3+x^2} )$ starting at $1$. Also, if the function is not differentiable at the root, such as $( x \mapsto x^{1/3} )$, then it may be that it will always diverge no matter how close you start to the root! $\endgroup$
    – user21820
    Sep 22 '16 at 10:52
2
$\begingroup$

$\newcommand{\braces}[1]{\left\lbrace\,{#1}\,\right\rbrace} \newcommand{\bracks}[1]{\left\lbrack\,{#1}\,\right\rbrack} \newcommand{\dd}{\mathrm{d}} \newcommand{\ds}[1]{\displaystyle{#1}} \newcommand{\expo}[1]{\,\mathrm{e}^{#1}\,} \newcommand{\ic}{\mathrm{i}} \newcommand{\mc}[1]{\mathcal{#1}} \newcommand{\mrm}[1]{\mathrm{#1}} \newcommand{\pars}[1]{\left(\,{#1}\,\right)} \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}} \newcommand{\root}[2][]{\,\sqrt[#1]{\,{#2}\,}\,} \newcommand{\totald}[3][]{\frac{\mathrm{d}^{#1} #2}{\mathrm{d} #3^{#1}}} \newcommand{\verts}[1]{\left\vert\,{#1}\,\right\vert}$

We can see that $\ds{\mrm{f}\pars{x} \equiv \sin\pars{x} - x^{3} + 2x^{2} - 1}$ has a change of sign in $\ds{\bracks{0,1}}$. We can set the starting point as $\ds{x_{0} = {0.0 + 1.0 \over 2.0} = 0.5}$ with $$ x_{n + 1} = x_{n} - {\sin\pars{x_{n}} - x_{n}^{2}\pars{x_{n} - 2} - 1 \over \cos\pars{x_{n}} -x_{n}\pars{3x_{n} - 4}}\,,\qquad n \geq 0 $$

The $\texttt{javascript}$ code at the end $\pars{~\texttt{nr0.js}~}$ makes the job. You can run it in the console $\pars{~\mbox{'as an script'}~}$ with $\texttt{node}$, from https://nodejs.org/en/:

$\texttt{> node nr0.js}$

The result is given by

0.5, f(0.5) = -0.145574461395797
0.5684224734698207, f(0.5684224734698207) = 0.0008518369364767242
0.5680257404259389, f(0.5680257404259389) = 4.097584049844727e-9
0.5680257385175188, f(0.5680257385175188) = 0
0.5680257385175188, f(0.5680257385175188) = 0
// nr0.js
"use strict";
var n = 0;
var s = "";
var x = 0.5;

function f(x)
{
 return Math.sin(x) - x*x*(x - 2.0) - 1.0;
}

function next(x)
{
 return x - f(x)/(Math.cos(x) - x*(3.0*x - 4.0));
}

do {
    s += x + ", f(" + x + ") = " + f(x) + "\n";
    x = next(x);
} while (++n < 4);

s += x + ", f(" + x + ") = " + f(x) + "\n";
console.log(s);
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.