I ran into a strange problem, where using ConstantArray
inside FindRoot
results in a FindRoot::jsing
error. Here's a minimal example, with the first instance working and the second failing:
FindRoot[{0, 0} == {x^2 + y^2 - 1, x - y}, {x, 0.1}, {y, 0.2}]
(* {x -> 0.707107, y -> 0.707107} *)
FindRoot[ConstantArray[0, 2] == {x^2 + y^2 - 1, x - y}, {x, 0.1}, {y, 0.2}]
(* FindRoot::jsing: Encountered a singular Jacobian at the point {x,y} = {0.1,0.2}. Try perturbing the initial point(s). *)
(* {x -> 0.1, y -> 0.2} *)
Any idea why this occurs?
Anyhow, here's an easy workaround:
FindRoot[Table[0, 2] == {x^2 + y^2 - 1, x - y}, {x, 0.1}, {y, 0.2}]
(* {x -> 0.707107, y -> 0.707107} *)
FindRoot
having the attributeHoldAll
. Change toFindRoot[Thread[ConstantArray[0, 2] == {x^2 + y^2 - 1, x - y}], {x, 0.1}, {y, 0.2}]
$\endgroup$FindRoot[{x^2 + y^2 - 1, x - y}, {x, 0.1}, {y, 0.2}]
$\endgroup$Table[0, 2]
version works withoutThread
? $\endgroup$ConstantArray
appears to be that it is packed.Needs["Developer`"]; FindRoot[FromPackedArray@ConstantArray[0, 2] == {x^2 + y^2 - 1, x - y}, {x, 0.1}, {y, 0.2}]
works. $\endgroup$FindRoot[Developer`ToPackedArray@Table[0, 2] == {x^2 + y^2 - 1, x - y}, {x, 0.1}, {y, 0.2}]
-- Still seems like a bug to me. $\endgroup$