# Solve Equation with NSolve

I am trying to solve nonlinear equation in mathematica, the equation include the function Erfc which is defined in mathematica, the equation is true and I should for sure get answer. but for some reason It doesn't stop running though it should take a few seconds, and I think that there is a syntax problem , I try hard to find it but couldn't so please help me find the problem.

BR = 0.0001;
xvec = {1.8};
y = -100;
bindEVSa =
Table[{xvec[[b]],
qdim /. NSolve[{ (qdim  N[Erfc[qdim BR]])/(
qdim/y Exp[qdim^2 BR^2] *N[Erfc[qdim BR]] - 1) - qdim^2 + 1/(
1/xvec[[b]] - 1/y) == 0, qdim >= 0}, {qdim},
Reals][[1]]}, {b, Length[xvec]}]
(*or*)
bindEVSa =
Table[{xvec[[b]],
qdim /. NSolve[{ (qdim  N[Erfc[qdim BR]])/(
qdim/y Exp[qdim^2 BR^2] *N[Erfc[qdim BR]] - 1) - qdim^2 + 1/(
1/xvec[[b]] - 1/y) == 0, qdim >= 0}, {qdim}][[1]]}, {b,
Length[xvec]}]

• I don't know if this will work for your actual problem, but bindEVSa=Table[{xvec[[b]],qdim/. FindRoot[qdim N[Erfc[qdim BR]]/(qdim/y Exp[qdim^2 BR^2]*N[Erfc[qdim BR]]-1)-qdim^2+1/(1/xvec[[b]]-1/y)==0,{qdim,1}]},{b,Length[xvec]}] returns the solution in 0.001 seconds
– Bill
Feb 17, 2023 at 22:37
• thank you very much ! , it gives the right answer! but did you know why Nsolve doesn't work ?
– maya
Feb 17, 2023 at 22:43
• Your NSolve was complicated enough that I was not able to quickly find exactly what was causing the problem for you so I got the answer instead.
– Bill
Feb 17, 2023 at 22:45

\$Version

(* "13.2.1 for Mac OS X ARM (64-bit) (January 27, 2023)" *)

Clear["Global*"]


From the documentation, "NSolve deals primarily with linear and polynomial equations." For other equations, NSolve may be helped by adding constraints to simplify the search. In this case, constrain qdim to an interval, e.g., 5 > qdim >= 0, rather than just restricting it to be nonnegative.

BR = 0.0001;
xvec = Range[1.8, 10.8, 1.8];
y = -100;

bindEVSa =
Table[{xvec[[b]],
NSolveValues[{(qdim Erfc[qdim BR])/(qdim/y Exp[qdim^2 BR^2]*
Erfc[qdim BR] - 1) - qdim^2 + 1/(1/xvec[[b]] - 1/y) == 0,
5 > qdim >= 0}, qdim, Reals][[1]]}, {b, Length[xvec]}]

(* {{1.8, 0.923629}, {3.6, 1.43531}, {5.4, 1.82517},
{7.2, 2.14803}, {9., 2.4266}, {10.8, 2.67296}} *)
`