Solving $\sin x = x^3-2x^2+1$ using Newton's Method

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?

• 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. – Simply Beautiful Art Sep 19 '16 at 1:40
• 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. – AfronPie Sep 19 '16 at 1:49
• 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$. – Winther Sep 19 '16 at 2:02
• @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. – Simply Beautiful Art Sep 19 '16 at 2:04
• $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$. – Moo Sep 19 '16 at 2:24

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)$.

• Thanks so much! I'd never find that mistake even if I did the problem hundreds of times. – AfronPie Sep 19 '16 at 6:29
• @AaronM. You are very welcome. May I confess that I did not see it at first galnce ? – Claude Leibovici Sep 19 '16 at 6:40
• @ClaudeLeibovici Nah, I didn't see it either. Totally glanced over once I saw the first equation was right. – Simply Beautiful Art Sep 19 '16 at 12:25
• Yeah, it really bothered me because the roots kept bouncing, and I knew they should be converging to .568. Thanks again. – AfronPie Sep 19 '16 at 22:37
• @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! – user21820 Sep 22 '16 at 10:52

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


protected by Community♦Sep 21 '16 at 0:08

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).