# Error using Nsolve with system of two equations: “Use Reduce”

Having some odd behavior with some mathematica code I am running. I am solving a simple system of two equations but mathematica gives an error and asks to use Reduce? I looked up in the manual but have no clue what to do to rememdy the situation.

delay = 4*10^-9;
gamma = (25*10^3)/0.511;
beta = Sqrt[1 - gamma^-2];
c = 3*10^8;

rho = lb/theta;
drift = 4 lb;

time = (4 rho*theta + 2 drift - 4 lb - 2 drift*Cos[theta])/(beta*c);
disp = lb^2/rho + lb/rho*drift*Cos[theta];

NSolve[{time== delay, disp == 0.6},{theta,lb}]

• The expressions for timeDiff and dispersion are lacking – Dr. belisarius Sep 24 '14 at 2:55
• oops youre right...fixed!! – user1886681 Sep 24 '14 at 3:22
• NSolve does not handle situations of infinitely many solutions. Could restrict a variable to get to a finite case, e.g. NSolve[{time == delay, disp == 0.6, -30 <= theta <= 30}, {theta, lb}]. – Daniel Lichtblau Sep 24 '14 at 14:53

delay = 4*10^-9;
gamma = (25*10^3)/0.511;
beta = Sqrt[1 - gamma^-2];
c = 3*10^8;
rho = lb/theta;
drift = 4 lb;

time = (4 rho*theta + 2 drift - 4 lb - 2 drift*Cos[theta])/(beta*c);

disp = lb^2/rho + lb/rho*drift*Cos[theta];

ContourPlot[{time == delay, disp == .6},
{theta, -12, 5}, {lb, 0, .3},
FrameLabel -> (Style[#, 14, Bold] & /@
{theta, lb})] The intersection points are the solution points and provide the initial estimates for FindRoot

sol = FindRoot[{time == delay, disp == .6},
{{theta, #[]}, {lb, #[]}}] & /@
{{-11, .1}, {-8, .1}, {-4, .1}, {-3, .1},
{2, .2}, {5, .15}}


{{theta -> -10.6056, lb -> 0.108685}, {theta -> -8.28907, lb -> 0.105523}, {theta -> -3.97865, lb -> 0.089839}, {theta -> -2.80309, lb -> 0.0771901}, {theta -> 1.26384, lb -> 0.214949}, {theta -> 4.68236, lb -> 0.145628}}

{time == delay, disp == .6} /. sol


{{True, True}, {True, True}, {True, True}, {True, True}, {True,
True}, {True, True}}

• I tried using Ersek RootSearch, which is supposed to be able to find roots in given range, but on V 10.01 something changed. Now I get No more memory available. Mathematica kernel has shut down. Try quitting other applications and then retry. This package looks like it is no longer maintained. library.wolfram.com/infocenter/MathSource/4482 It worked ok on version 9.01 – Nasser Sep 24 '14 at 6:43
• @Nasser I think one can build one by finding the intersections on the interpolation of grids = Cases[ Normal@Graphics@ Cases[ContourPlot[ ...], GraphicsComplex[__], Infinity], Line[__], Infinity] /. Line[a__] -> a; – Dr. belisarius Sep 24 '14 at 17:47

Updated answer: Thanks to hint by Daniel below, one can give NSolve region to search on.

NSolve[{time == delay, disp == 0.6 && (-4 Pi < theta < 4 Pi) && (0 < lb < 10)},
{theta, lb}]


gives

{{theta -> -10.6056, lb -> 0.108685}, {theta -> -8.28907, lb -> 0.105523},
{theta -> -3.97865, lb -> 0.089839}, {theta -> -2.80309, lb -> 0.0771901},
{theta -> 1.26384, lb -> 0.214949}, {theta -> 4.68236, lb -> 0.145628},
{theta -> 7.96477, lb -> 0.135066}, {theta -> 10.8505, lb -> 0.131059}}


I do not know why NSolve can't solve this since Maple fsolve can. But you can use FindRoot when all else fails. (the problem with FindRoot is that one need to have some idea where to look for)

Clear[lb, theta];
delay = 4*10^-9;
gamma = (25*10^3)/0.511;
beta = Sqrt[1 - gamma^-2];
c = 3*10^8;
rho = lb/theta;
drift = 4 lb;
time = (4 rho*theta + 2 drift - 4 lb - 2 drift*Cos[theta])/(beta*c);
disp = lb^2/rho + lb/rho*drift*Cos[theta];
eqs = {time == delay, disp == 0.6};
NSolve[eqs, {theta, lb}, Reals] roots = FindRoot[eqs, {{theta, -8}, {lb, .1}}]
eqs /. roots Maple solution: Using Mathematica 10.01 on windows.

• NSolve can handle it but requires a restricted domain. – Daniel Lichtblau Sep 24 '14 at 16:07
• @DanielLichtblau thanks! I actually did not notice that NSolve accepts ranges, now it works much better. Updated answer. – Nasser Sep 24 '14 at 16:26
• Hey Guys I thought I would try to make things a little easier and give "lb=3;" a try but I get the same error even with lb defined? – user1886681 Sep 24 '14 at 18:56