So I would like to write a code which iteratively finds the double root (a root which is also a maximum or a minumum) of functions. I would like to apply this to more complex functions Mathematica struggle with handling, but I thought I would start with a simple one:
f[x_] = (-1)*x*(x - 4)^2*(x + 6)
Now this function obviously has a double root in
x = 4. I wanted to write a loop which would test different values of
x until it finds a specific
x for which
f'[x]==0 (the conditions of a double root). I wrote the following:
solution = 0.1 While[f[solution] < 0, solution += 0.1; If[f[solution] == 0 && f'[solution]==0, Return[solution]] ]
As I see it, this loop should start testing
x = 0.1, if
f[0.1] < 0 (which I have made sure it is in the whole interval
0.1<x<4) it should increase the tested value with
0.1 and try again until
f[x] no longer is negative. Also, when we reach the point where the conditions for the double root are met, the loop should return solution. However, it doesn't seem to work at all. I have let the loop run for half an hour without any result. Could somebody please tell me what's wrong?
The only problem I can think about is if for some specific
solution we have
f[solution] < 0, f[solution+0.1] > 0 meaning that the condition
f[solution] == 0 will never be met. This could of course be the case with more complex function, but with the current
f[x] this shouldn't be a problem as 4 = 0.1 + 39*0.1.
EDIT: I do know that there are several commands which can find the root to this function. However, all I would like to know is simply why this loop does not work.