# Solving an equation with the Brent method [closed]

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.

• Try Plot[{al[x] - 2*Pi*e, a*Sin[al[x]]/(Cosh[x] + Cos[al[x]])}, {x, 0, 4}, PlotRange -> All]... – MikeLimaOscar Mar 17 '17 at 16:47
• Thanks but I need something different. How to write the script correctly. – user2272592 Mar 17 '17 at 16:53
• 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}. – MikeLimaOscar Mar 17 '17 at 16:56
• Ah, ok. That was working. Good luck – user2272592 Mar 17 '17 at 16:58

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