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$
  • $\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$ – Mariusz Iwaniuk May 24 '16 at 10:39
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}]]
| improve this answer | |
$\endgroup$
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.}

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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