Given f, Newton finds where f is 0.  Your function is x^2 - 2x = 0.

   load 'math/calculus'
   Newton =: adverb : ']-u%(u deriv_jcalculus_ 1)'(^:_)("0)
   0 _2 1&p. Newton 1.1
2

Check:

   p. 0 _2 1
+-+---+
|1|2 0|
+-+---+


Without guardrails, Newton may crash:

   0 _2 1&p. Newton 1
|NaN error
|       0 _2 1&p.Newton 1

Henry Rich


On 2/5/2020 2:21 AM, Skip Cave wrote:
Newton =: adverb : ']-u%(u D.1)'(^:_)("0)

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to