Newton's method cannot be used to find multiple roots. You basically find one root, and you are done.
Then you can start at a new point. Hopefully Newton's method will converge to another root. Or it might just find the first one.
So a simple approach for 1-d problem is to evaluate the function at a bunch of points, looking to see where there might be zero crossings. A root MUST exist in the area of any zero crossing. But you might miss two roots, if they are close to each other. So sample sufficiently tightly so this will not happen. But wherever your tests see a crossing, start Newton's method there, and you SHOULD probably find another root.
There is no magic in the above - just careful programming.
Now, could you use homotopy (continuation) methods to find multiple roots? Well yes, in some cases, yes. But that is wildly beyond just using Newton's method. And it involves an ODE solver, which is NOT at all Newton's method. I don't think this is the goal of your assignment, unless you wanted to invest a lot of effort.
Ok, there are other tricks. You can use a root deflation scheme, so as you find a root, you modify the function, so the root you just found is no longer a root. This can get tricky too, if you are not careful.
The point is, you cannot simply just modify Newton's method to find multiple roots. The simple approach is as I suggested, just look for sign changes in a sequence of function evaluations.
yfun = @(x) 4*exp(-0.3*x).*(sin((3*x)+0.25));
xtest = linspace(0,4,1000);
ytest = yfun(xtest);
indp2n = strfind(sign(ytest),[1,-1]);
indn2p = strfind(sign(ytest),[-1,1]);
xstart = (xtest([indp2n,indn2p]) + xtest([indp2n,indn2p]+1))/2;
Note my use of .* in yfun. That will be necessary.
ezplot(yfun,[0 4])
grid on
hold on
plot(xstart,yfun(xstart),'ro')
Now, just start your Newton scheme at each of those points. It will converge in only a few iterations from each start point, since Newton is quadratically convergent, and those are darn good starting values.
Best Answer