Newton Raphson interactive demo

Last updated at 8:45 pm UTC on 1 July 2018

### To develop

A solution which answers in a dynamic way (i.e. in something like a Dynabook page) the question

'Can someone please tell me the conditions under which the Newton Raphson method will not converge? '

https://math.stackexchange.com/questions/726369/when-does-the-newton-raphson-method-fail/1766666#1766666

### Tools

- Dr. Geo, Release 1806 (Pharo implementation, updated version)
- The Dr. Geo educational software uses Smalltalk as DSL
- The problem is solved by using a Dr. Geo Smalltalk script
- To implement in Dr. Geo: Newton Raphson interactive demo viewer, but at the moment just evaluate the script below in Dr. Geo from the world menu.
- Active essay below is what should be shown in the viewer

### Active Essay of the Newton-Raphson algorithm

The Newton-Raphson algorithm does X and Y by using Z ....... (TODO put in the EXPLANATION)

| sketch f df pointA pointB|
sketch := DrGeoCanvas new axesOn.
f := [ :x | x cos + x ].
df := [ :x | (f value: x + 1e-8) - (f value: x) * 1e8]. "Derivate number"
sketch plot: f from: -20 to: 20.
pointA := (sketch point: 2@0) large.
pointB name: 'Drag me'.
5 timesRepeat: [
pointB := sketch
point: [ :pt | pt x @ (f value: pt x)]
parent: pointA.
pointB hide.
(sketch segment: pointA to: pointB) dotted forwardArrow .
pointA := sketch point: [:pt | | x |
x := pt x.
x - ( (f value: x) / (df value: x) ) @ 0
]
parent: pointB.
pointA hide.
(sketch segment: pointB to: pointA) dotted forwardArrow
].

Explanation of the first statement in the repeat block:

pointB := sketch point: [ :pt | pt point x @ (f value: pt point x)] parent: pointA.

The idea is to have a point object in the Dr. Geo model which coordinates are updated by an arbitrary block of code.

The block can receive one or several arguments as parents.

It is very handy to compute point position in cascade as in this example or in a recursive sequence for example.

The French doc explains it a bit further, but still might need more elaboration.

https://www.gnu.org/software/dr-geo/doc/fr/Figure-Smalltalk.html#index-point_003aparent_003a-on-DrGeoCanvas