3
$\begingroup$

In order to apply a newton-rhapson algorithm to solve a set of nonlinear vector equations such as these,

f[x_, y_] = {x^2 - 3*y + 6, (y + 1)^2 - x - 33}

I need to nest the update function to run a few times:

newtit[x_, y_] =  {x, y} - Inverse[D[f[x, y], {{x, y}}]].f[x, y]

However, when using Nest[] I cannot seem to pass a list of arguments ({2,2}) to this function.

Nest[newtit, {2, 2}, 2]

To be clear why I don't just use Solve[], I want to use this algorithm to solve a larger and more complicated set of vector equations. I am quite new to mathematica, but the syntax I use for passing lists to functions would be (f@@{2,2}), I can't use this form in Nest[]. What should I use in this case?

$\endgroup$
1
  • $\begingroup$ Thanks, those are insightful, but both entries seem to only handle a single input argument to the function f, or am I not looking into the arguments well enough? $\endgroup$ Commented Apr 3, 2016 at 22:34

1 Answer 1

3
$\begingroup$
Nest[newtit @@ # &, {2, 2}, 2]

{477912/142961, 2239654/428883}

$\endgroup$
3
  • $\begingroup$ Thanks! What does the syntax here mean exactly? $\endgroup$ Commented Apr 3, 2016 at 22:41
  • $\begingroup$ @FlorisvanElteren, thanks for the accept. f@@expr replaces the head of expr by f; i.e., the head of {2,2} (i.e. List) is replaced by newtit giving newtit[2,2]. (see Apply (@@) ) $\endgroup$
    – kglr
    Commented Apr 3, 2016 at 22:44
  • 2
    $\begingroup$ Alternatively, f should have been directly defined for vector input: f[{x_, y_}] := {x^2 - 3*y + 6, (y + 1)^2 - x - 33}; newtit[{x_, y_}] = {x, y} - Inverse[D[f[{x, y}], {{x, y}}]].f[{x, y}]. Then Nest[newtit, {2, 2}, 2] just works. $\endgroup$ Commented Apr 3, 2016 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.