# NewtonsMethod.frink

``` use functionUtils.frink use derivatives.frink use integrals.frink use solvingTransformations.frink use BooleanTransformations.frink use powerTransformations.frink /** This program tries to help you find a Newton's method iteration for a    particular function . */ NewtonsMethod[f] := {    body = functionBody[f]    df = transformExpression[makeDerivative[f]]    vars = functionArgumentsAsSymbols[f] //   println["f  = " + inputForm[body]] //   println["df = " + inputForm[df]]    return transformExpression[vars@0 - body/df] } /** This program tries to help you find a Halley's method iteration for a    particular function . */ HalleysMethod[f] := {    body = functionBody[f]    df =  transformExpression[makeDerivative[f]]    df2 = transformExpression[makeDerivative[f, 2]]    vars = functionArgumentsAsSymbols[f] //   println["f   = " + inputForm[body]] //   println["df  = " + inputForm[df]] //   println["df2 = " + inputForm[df2]]    return transformExpression[vars@0 - 2 body df / (2 df^2 - df df2)] } symbolicMode[true] /** Newton's method solves for the roots or zeroes of a function f, that is,     where      f[x]=0     The below creates a two-argument anonymous function that implicitly     encodes the condition     x^2 - n = 0     or, alternately,     x^2 = n     or, alternately,     n = sqrt[x]     which is what we really want to be solving in this case. */  f = {|x, n| x^2- n} println["The next term (Newton's Method) is given by iterating: "] println[inputForm[NewtonsMethod[f]]] println[] println["The next term (Halley's method) is given by iterating: "] println[inputForm[HalleysMethod[f]]] ```

This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 18354 days, 1 hours, 26 minutes ago.