I've only had few previous experiences on Mathematica before. So basically an entry-level question that harasses a rookie like me.
I made the following attempt using bisection method to calculate the real root for the function $f(x)=-x^3+2x^2-2$ with basic while loop and if:
a = -5;
b = 5;
m = (a + b)/2;
While [ Abs[f[m]] > 0.000001,
If[f[m]*f[a] < 0, b = m, a = m];
m = (a + b)/2]
The answer turns out to be $-(14080895/16777216)$ that is correct.
Then, I wanted to create a animation that shows the change of position of a dot along the function curve for each iteration of the bisection method. But I tried several times with different codes that all fails to do so. One confusion is I am not sure how to set up a stepsize here which involves not a constant number but "While" and "If".
Would you please help me animate the iteration with while and if?
m
asm = a + (b - a)/2
, and 2.) change the sign change criterion toSign[f[m]] != Sign[f[a]]
. $\endgroup$