1
$\begingroup$

Slightly clearer, hopefully:

I would like to plot Solve[Normal[Series[E^(n x), {x, 0, n}]] == 0 for incrementally increasing n, and show all plots overlayed. Here is my effort with up to n=63 using this code:

enter image description here

...Very time consuming though, & I would really like to find a way of plotting it (& similar plots) up to any n without the labour-intensive copying & pasting.

$\endgroup$
6
  • 1
    $\begingroup$ Also, it's good to explain in words what you are doing instead of just posting a piece of code to decode first (!) and then improve. $\endgroup$
    – Szabolcs
    Nov 10, 2013 at 23:02
  • $\begingroup$ Please see link to my other question for further details: math.stackexchange.com/questions/554964/… $\endgroup$
    – martin
    Nov 10, 2013 at 23:35
  • $\begingroup$ Thanks for the link. It would be useful to incorporate the relevant parts into this question so that users have the full picture here instead of having to follow links :) $\endgroup$
    – rm -rf
    Nov 10, 2013 at 23:40
  • 1
    $\begingroup$ There's an error in your statement. You seem to be plotting x/n, not simply x. Alternatively one can solve for the zeros of the partial sums for E^(n x). $\endgroup$
    – Michael E2
    Nov 11, 2013 at 1:17
  • $\begingroup$ @ Michael E2, Thankyou very much :) - Yes, sorry for the error - forgot to mention rescaling:) $\endgroup$
    – martin
    Nov 11, 2013 at 1:34

1 Answer 1

6
$\begingroup$

Here's a way that's fast but inaccurate. Some of the roots it finds for large n are wrong.

roots = Table[
    x /. NSolve[Normal[Series[E^(n x), {x, 0, n}]] == 0, x], {n, 200}]; // AbsoluteTiming
(* {2.441688, Null} *)

For accuracy set WorkingPrecision (a small amount will do), but it takes much more time:

roots = ParallelTable[
    x /. NSolve[Normal[Series[E^(n x), {x, 0, n}]] == 0, x, 
      WorkingPrecision -> 10], {n, 200}]; // AbsoluteTiming
(* {137.021271, Null} *)

To visualize, we convert the roots to points. Packing the array is optional -- it will be packed when the graphics are displayed, if it is not pre-packed.

pts = Developer`ToPackedArray @ N[Flatten[roots] /. z_Real | z_Complex :> {Re[z], Im[z]}];

Here is the output on the more accurate calculation of the roots.

Manipulate[
 Graphics[
  GraphicsComplex[pts,
   {PointSize[Tiny],
    Dynamic @ Point[Range @ Length @ Flatten[roots[[;; n]]]]}],
  Frame -> True, PlotRange -> 1],
 {n, 1, Length @ roots, 1}
 ]

Manipulate output

The original Manipulate -- somewhat more straightforward but slower, as it converts the roots to points at every update:

Manipulate[
 Graphics[{PointSize[Small], 
   Point[Flatten[roots[[;; n]]] /. z_Real | z_Complex :> {Re[z], Im[z]}]},
  Frame -> True, PlotRange -> 1],
 {n, 1, Length @ roots, 1}
 ]
$\endgroup$
7
  • $\begingroup$ @ Michael E2 - Great - I am getting slight problems with numerical error towards the end, but I can live with that! - Zeros should really be entering curve at all :) $\endgroup$
    – martin
    Nov 11, 2013 at 1:50
  • $\begingroup$ Just out of interest, how would I increase the precision of the calculations? Have tried {Re[z], Im[z]},50], but doesn't seem to affect it. $\endgroup$
    – martin
    Nov 11, 2013 at 1:56
  • $\begingroup$ Realise I will lose performance - just curious for static example. $\endgroup$
    – martin
    Nov 11, 2013 at 1:58
  • 1
    $\begingroup$ NSolve has a WorkingPrecision option. WorkingPrecision -> 10 took 454 sec., but eliminated the points on x, y axes that encroach on the interior. It's a good candidate for ParallelTable. $\endgroup$
    – Michael E2
    Nov 11, 2013 at 2:04
  • $\begingroup$ Great - thank you for your help on this :) $\endgroup$
    – martin
    Nov 11, 2013 at 2:04

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.