FindRoot with vector function

I have trouble with FindRoot for vector variables, I have search MMA SE find a solution. in Szabolcs‘s code, Vector FindRoot realized by the Evaluated option of FindRoot.

Here is my code,Evaluated -> False not work.

deltat = 1*^-3;
integrator[x_, y_, {x0_, y0_}] := {x, y} /.
FindRoot[{x - x == {1, 1, 1},
y - y == {1, 1, 1}} /. {x -> x0, y -> y0}, {{x,
x0}, {y, y0}}, Evaluated -> False];
integrator[x, y, {{0, 0, 0}, {0, 0, 0}}];

I have test when the variables is scalar, but it fails in Vector variables.

Any comments will be very appreciate!

The issue is that something like x + {1, 1} automatically evaluates to {1+x, 1+x}, and now making x a vector causes issues. In your case that means that x - x becomes {x, x, x} and FindRoot doesn't work. One idea is to put all the explicit vectors on one side of the equation and implicit vectors on the other:

integrator[x_, y_, {x0_, y0_}] := {x, y} /. FindRoot[
{x == x0 + {1,1,1}, y == y0 + {1,1,1}},
{
{x, x0},
{y, y0}
}
];

integrator[x,y,{{0,0,0},{0,0,0}}]

{{1., 1., 1.}, {1., 1., 1.}}

Another possibility is to add equations for x and y:

integrator[x_, y_, {x0_, y0_}] := {x, y} /. FindRoot[
{x -x == {1,1,1}, y - y == {1,1,1}, x == x0, y == y0},
{
{x, x0},
{y, y0},
{x, x0},
{y, y0}
}
];

integrator[x,y,{{0,0,0},{0,0,0}}]

{{1., 1., 1.}, {1., 1., 1.}}

• Thank you, follow your idea, I have test this code and find some issues and maybe fixed it(in this question). any advice will be appreciate.
– Ben
Nov 19 '21 at 23:15

@Carl Woll, thank you!

I think the answer should combine Carl and Szabolcs‘s code. In Carl's code, it seems not work when equation right-hand with x which need to FindRoot.

Here is the example code, which return error.

integrator[x_, y_, {x0_, y0_}] := {x, y} /.
FindRoot[{x == x0 + x\[Cross]{1, 1, 1},
y == y0 + {1, 1, 1}}, {{x, x0}, {y, y0}}];

integrator[x, y, {{0, 0, 0}, {0, 0, 0}}]

So ,if we put Evaluated option

integrator[x_, y_, {x0_, y0_}] := {x, y} /.
FindRoot[{x == x0 + x\[Cross]{1, 1, 1},
y == y0 + {1, 1, 1}}, {{x, x0}, {y, y0}},
Evaluated -> False];

integrator[x, y, {{0, 0, 0}, {0, 0, 0}}]

I didn't know why we should take Evaluated option, but it works for general form.

Thanks to Carl and Szabolcs again.