2
$\begingroup$

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?

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

2 Answers 2

1
$\begingroup$
  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}]]
$\endgroup$
0
1
$\begingroup$
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]];

FindRoot[Cases[Flatten@Grad[f, x], Except[0]] == 0, Thread@{x, xo}]

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

$\endgroup$

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.