Visualizing the Newton Method in EMT

In a post by squareCircleZ I found a visualization of the Newton method with JavaScript. This looks like a modern and sleek way of providing demos to students. I have some doubts about the depth of the insights gained by this click and try demos. But, for a first clue, they seem to be okay.

However, I’d much prefer this to be done with a little bit of programming in EMT. Here is the code. I am going to explain it below.

>function f(x) &= x^4+x-1

                               x  + x - 1

>function df(x) &= diff(f(x),x)

                                4 x  + 1

>function newstep (x) &= x - f(x)/df(x)

                                 x  + x - 1
                             x - ----------
                                  4 x  + 1


                                3 x  + 1
                                4 x  + 1

>function vstep (x) ...
$  plot2d([x,x],[0,f(x)],style="--",color=blue,>addpoints,>add);
$  x1=newstep(x);
$  plot2d([x,x1],[f(x),0],style="-",color=blue,>add);
$  return x1;
>loop 1 to 8; x=vstep(x); end:

It is all quit straightforward. Using Maxima, we compute the derivative or our symbolic function f(x), and then the Newton step. The simplification with ratsimp() is only to show that the original form can be simplified quite substantially. We plot the function, and define a function vstep() which draws two lines (one with endpoints) and returns the new value of the Newton algorithm. Then we do this 8 times starting from x=1.9. Note the colon : after the last statement, which inserts the graphics into the notebook.


If you save all that in an EMT notebook it should provide a nice environment for own experiments by the students. With a little bit of thought, we can do a lot more now. E.g., we could try to experimentally prove the the order of the algorithm is quadratic. This involves logarithms and quite a bit of thought.

By the way, Maxima can also give us the formula for the root of this particular function. As you will see, it is not very useful.



3 Gedanken zu „Visualizing the Newton Method in EMT

  1. Wolfgang Tintemann

    The formula of Maxima is somewhat impressive but I think only to those ( as me ) who never solved this quadratic equation by pencil and paper.

  2. Radovan Omorjan

    By the way, we have the fwebplot() function in EMT which will visualize the fixed point iteration method. With a little bit of effort there could be visualized, say, bisect() or secant() as well.

  3. mga010 Beitragsautor

    Nobody solves this by pencil and paper anymore. This art has been lost. I am not sure if I care.

    To evaluate the formula in EMT, you have to use complex:expr(), by the way. The third roots won’t work otherwise.


Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.