4
$\begingroup$

In this question Original Post the user provides a working Mathematica code which plots the basins of attraction using the Newton's iteration method. However the code works only for the function $p(z) = z^3 - 1$.

So my question is what should be changed in the code so as to work with any type of $p(z)$ function (i.e., $p(z) = z^5 -1$, $p(z) = z^2 - 2^z$, etc)?

Many thanks in advance!

$\endgroup$
8
  • $\begingroup$ Change the first line of the code f = Function[z, z^3 - 1]; $\endgroup$
    – Marvin
    Dec 5, 2015 at 12:17
  • $\begingroup$ @Saurav And then what? The rest of the code uses p[z]. $\endgroup$
    – Vaggelis_Z
    Dec 5, 2015 at 12:37
  • $\begingroup$ It should be clear from the warning Part::partw: Part 5 of {{cc,0,0},{cc,cc,0},{0,0,cc}} does not exist. that the problem lies in the definition of colorList - it assumes three roots. I suggest changing it to something like colorList = ColorConvert[Hue /@ (Range[numRoots]/numRoots), "RGB"] /. RGBColor[x__] :> cc {x} $\endgroup$ Dec 5, 2015 at 12:39
  • $\begingroup$ @SimonWoods It does not work with other types of functions. Check it out. And for $z^3-1$ the output comes in black and white. $\endgroup$
    – Vaggelis_Z
    Dec 5, 2015 at 12:45
  • $\begingroup$ @Vaggelis_Z, it works fine for me. Here is the result for p[z_]:=z^5-1 $\endgroup$ Dec 5, 2015 at 12:49

1 Answer 1

8
$\begingroup$
newton[z_] := z - f[z]/f'[z]

plot[r_] :=
 ListDensityPlot[Arg@FixedPoint[newton, #, 50] & /@
   Table[i + j I, {j, -r, r, 2 r/365.}, {i, -r, r, 2 r/365.}],
  ColorFunction -> "Rainbow",
  DataRange -> {{-r, r}, {-r, r}}]

f[z_] := z^3 - 1; plot[2.0]

enter image description here

 f[z_] := z^5 - 1; plot[2.0]

enter image description here

$\endgroup$
7
  • $\begingroup$ Very nice! I have a couple of question: (i) You define a grid of initial conditions in the square [-2,2] however the range in the plot is from 0 to about 350. Why? I should be from -2 to 2 on both axes. (ii) Can your code generate the output for $f(z) = z^2 - 2^z$ shown here: mathworld.wolfram.com/NewtonsMethod.html (last figure, left panel) $\endgroup$
    – Vaggelis_Z
    Dec 5, 2015 at 13:22
  • $\begingroup$ Must leave. Will answer/modify later $\endgroup$
    – eldo
    Dec 5, 2015 at 14:06
  • $\begingroup$ @Vaggelis_Z plot := ListDensityPlot[{Re[#], Im[#], Arg@FixedPoint[newton, #, 50]} & /@ Flatten@Table[i + j I, {j, -2., 2., 0.011}, {i, -2., 2., 0.011}], ColorFunction -> "Rainbow"] $\endgroup$
    – mmal
    Dec 5, 2015 at 14:20
  • 2
    $\begingroup$ mathematica.stackexchange.com/a/100786/5478 $\endgroup$
    – Kuba
    Dec 5, 2015 at 14:35
  • 2
    $\begingroup$ mathematica.stackexchange.com/a/100055/5478 $\endgroup$
    – Kuba
    Dec 5, 2015 at 14:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.