I want to find a numeric solution using Grad. With Solve, I get

Clear[m, x, x1, x2, f, fi];
m = 2;
x = Array[xi, m];
f = Array[fi, m];
fi[i_] := xi[i] - 1/i xi[i]^2;
sol = Solve[Grad[f, x] == 0, x]


{{xi[1] -> 1/2, xi[2] -> 1}}

But with FindRoot, I get:

xo = x /. sol[[1]];
FindRoot[Grad[f, x] == 0, {x, xo}]


FindRoot[Grad[f,x] == 0, {x, xo}]

How can fix the last command to get a solution?

• Maybe like this:FindRoot[{Flatten@Grad[f, x][[1, 1]] == 0, Flatten@Grad[f, x][[2, 2]] == 0}, {{xi[1], 1}, {xi[2], 1}}] May 24, 2016 at 10:39

  Clear[m, x, x1, x2, f, fi];
m = 2;
x = Array[xi, m];
f = Array[fi, m];
fi[i_] := xi[i] - 1/i xi[i]^2;
sol = Solve[Grad[f, x] == 0, x]

FindRoot[Flatten[Table[Grad[f, x][[n, n]] == 0, {n, 1, m}]],
Table[{xi[n], 1}, {n, 1, m}]]


{xi[1] -> 0.5, xi[2] -> 1.}

For very large m you can use a RandomInteger[] or RandomReal[] randomize searches starting points x=x0.

  FindRoot[Flatten[Table[Grad[f, x][[n, n]] == 0, {n, 1, m}]],
Table[{xi[n], Evaluate@RandomInteger[{1, 10}]}, {n, 1, m}]]

m = 2;
x = Array[xi, m];
f = Array[fi, m];
fi[i_] := xi[i] - 1/i xi[i]^2;
sol = Solve[Grad[f, x] == 0, x]
(* {{xi[1] -> 1/2, xi[2] -> 1}} *)

xo = x /. sol[[1]];


{xi[1] -> 0.5, xi[2] -> 1.}