The following is a problem in a Numerical Methods class.
Consider the following function:
$$f(x) = x^3 - \frac{31}{10}x^2+\frac{1}{10}x+\frac{21}{5}$$
Implement a method that will allow you to find the nearest left and right roots, using the Newton-Raphson method as your base root finding method.
You should find the nearest roots of the following start points: $x = 0.0161, x= 2.051, x=0.5$
This is to be programmed in Matlab, so I'm looking at making a method which can be iterated over.
So far, I find the first root of the function (be it left or right), by continually evaluating:
$$x_{i+1} = x_i - \frac{f(x_i)}{f'(x_i)}$$
Starting with $x = 0.0161$, I find the closest root lies to the left at $x= -1$.
Finding the other root, to the right, is where I get a bit lost.
What I've concluded is that if I find the first root to the left, then the result of the following $f(x)f'(x) > 0$ will be true. And for a root to the right, the inverse, $f(x)f'(x) < 0$ will be true.
However, since my start value of $x$ is equal to $0.0161$, the derivative evaluates at $9.5763×10^{-4}$ and the jump that I make with Newton-Raphson is very big because of the small denominator.
Mathematically, how can I arrive at the other root?
I am not sure if this is a very good solution, but it works at least for your problem. The standard Newton-Raphson method uses the linear approximation of the function. One could also use a quadratic approximation. This quadratic approximation can have two solutions, upon which one choose either of these solutions to further iterate using the standard Newton-Raphson method. There is, however, a possibility that the quadratic approximation has no solutions.
So let say that we start at $x_0$. The quadratic approximations has the following solution: $$ x = x_0 + \frac{-f'(x_0) \pm \sqrt{(f'(x_0))^2 - 4f(x_0)f''(x_0)}}{2f''(x_0)}. $$ From the two solutions found, one can use the standard Newton-Raphson method: $$ x_{i+1} = x_i - \frac{f(x_i)}{f'(x_i)}. $$
I used the following code to check whether it works for your example:
x0 = 0.0161results in:x0 = 2.051results in:x0 = 0.5results in: