1
$\begingroup$

How do I write correct code to use the Brent method to solve an equation? My code is

p[R_] := R/(1 + R); q[R_] := 1/(1 + R);
a = 0.001; t = 100;
e = 0.491;
al[g_] := ArcCos[(a * Cos[q[t] * Sinh[g]/(g/a - p[t])] - Cosh[g])];
FindRoot[
     al[x] - 2 * Pi * e == a * Sin[al[x]]/(Cosh[x] + Cos[al[x]]),
     {x, 0, 4},
     Method -> "Brent"
]

I get the error message

FindRoot::bbrac: Method -> Brent is only applicable to univariate real functions and requires two real starting values that bracket the root.

$\endgroup$

closed as off-topic by MarcoB, happy fish, gwr, Young, yohbs Mar 22 '17 at 2:06

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, happy fish, gwr, Young, yohbs
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    $\begingroup$ Try Plot[{al[x] - 2*Pi*e, a*Sin[al[x]]/(Cosh[x] + Cos[al[x]])}, {x, 0, 4}, PlotRange -> All]... $\endgroup$ – MikeLimaOscar Mar 17 '17 at 16:47
  • $\begingroup$ Thanks but I need something different. How to write the script correctly. $\endgroup$ – user2272592 Mar 17 '17 at 16:53
  • 1
    $\begingroup$ Look at where the lines cross in the plot. The upper limit of your bracket is two orders of magnitude above that point (and the values at higher x are tending to ±infinity) so try reducing the bracket, e.g. {x,0,0.04}. $\endgroup$ – MikeLimaOscar Mar 17 '17 at 16:56
  • $\begingroup$ Ah, ok. That was working. Good luck $\endgroup$ – user2272592 Mar 17 '17 at 16:58
2
$\begingroup$

Your functions return complex values, hence the error message:

{al[x] - 2*Pi*e, a*Sin[al[x]]/(Cosh[x] + Cos[al[x]])} /. x -> 4
{0.05654866776461631` - 3.9999633557579153` I, 0.` + 27.288916588244273` I}

You should restrict the range to the real domain:

FindRoot[al[x] - 2*Pi*e == a*Sin[al[x]]/(Cosh[x] + Cos[al[x]]), {x, 0, .04}, 
 Method -> "Brent"]
{x -> 0.03464662602138138`}
$\endgroup$

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