1
$\begingroup$

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}]
$\endgroup$
  • $\begingroup$ The expressions for timeDiff and dispersion are lacking $\endgroup$ – Dr. belisarius Sep 24 '14 at 2:55
  • $\begingroup$ oops youre right...fixed!! $\endgroup$ – user1886681 Sep 24 '14 at 3:22
  • 2
    $\begingroup$ 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}]. $\endgroup$ – Daniel Lichtblau Sep 24 '14 at 14:53
1
$\begingroup$
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})]

enter image description here

The intersection points are the solution points and provide the initial estimates for FindRoot

sol = FindRoot[{time == delay, disp == .6},
    {{theta, #[[1]]}, {lb, #[[2]]}}] & /@
  {{-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}}

$\endgroup$
  • 1
    $\begingroup$ 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 $\endgroup$ – Nasser Sep 24 '14 at 6:43
  • $\begingroup$ @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; $\endgroup$ – Dr. belisarius Sep 24 '14 at 17:47
1
$\begingroup$

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}}

Original answer

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]

Mathematica graphics

roots = FindRoot[eqs, {{theta, -8}, {lb, .1}}]
eqs /. roots

Mathematica graphics

Maple solution:

Mathematica graphics

Using Mathematica 10.01 on windows.

$\endgroup$
  • 1
    $\begingroup$ NSolve can handle it but requires a restricted domain. $\endgroup$ – Daniel Lichtblau Sep 24 '14 at 16:07
  • $\begingroup$ @DanielLichtblau thanks! I actually did not notice that NSolve accepts ranges, now it works much better. Updated answer. $\endgroup$ – Nasser Sep 24 '14 at 16:26
  • $\begingroup$ 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? $\endgroup$ – user1886681 Sep 24 '14 at 18:56

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.