![]() |
Square Root via Newton’s Method 0 | Index << >> |
Apply Newton iteration ⍺
times to find the square root of ⍵ .
sqrt0←{ W←⍵ f←{2÷⍨W+⍺÷⍵} ⍺ {1≥⍺:⍵ ⋄ (⍺-1)∇ ⍵,f ¯1↑⍵} 1 ⍝ f⍣(⍳⍺)⊢1 } ⊢ t← 8 sqrt0 2 1 1.5 1.41667 1.41422 1.41421 1.41421 1.41421 1.41421 (15⍕ ⍪t), ' ', ¯6⍕ ⍪ 2-t×t 1.000000000000000 1.00000E0 1.500000000000000 ¯2.50000E¯1 1.416666666666667 ¯6.94444E¯3 1.414215686274510 ¯6.00730E¯6 1.414213562374690 ¯4.51061E¯12 1.414213562373095 4.44089E¯16 1.414213562373095 4.44089E¯16 1.414213562373095 4.44089E¯16 |