Consider the following function:

f[θ_] = 
 Integrate[1/(Cot[θ]^2 - Sin[θ]^2)^(1/2), θ];

Now, I want to determine the value of $\theta$ for which say $f(θ)=1$. I tried:



θ1[t_] := NSolve[f[θ] == t, {θ}]

In both the cases the evaluation apparently never ends.

What could be a way to get around this?


4 Answers 4


Note: Edited to match edited question

Try this

f[θ_] = Integrate[1/Sqrt[Cot[θ]^2-Sin[θ]^2], θ];
Plot[f[θ] ,{θ,-4 π, 4 π},PlotRange->{0,2}] 
FindRoot[f[θ]==1 ,{θ,7}]

which in an instant gives a plot showing approximately where one of your solutions will lie and in another instant gives you one of those solutions.

FindRoot is often pretty aggressive at getting you a solution if you have a fairly good estimate of where the root will lie and your function isn't too wild.

A couple of little notes to the original poster.

If you want to solve f[θ]==1 then the plot doesn't show anything above y==Sqrt[2] because your function goes complex then and you won't find a Real root, but it does give you a complex root.

Next, the usual convention when posting questions here that include Greek characters is to replace the \[GreekCharName] with the individual character. Different people have different ways of doing this. One way of doing this is to open a second tab in your browser, go to this Greek Character Table and then scrape-n-paste the individual characters to replace the Mathematica form of these. You can see the result of my doing that in my answer. And many think this makes the equations easier to read and understand.

  • $\begingroup$ I really just wanted to solve f[θ]==1. $\endgroup$
    – Subho
    May 20, 2018 at 14:25
  • $\begingroup$ Yeah, 1 doesn't lie in the range of the function. But it was just the idea I was looking for. Thanks $\endgroup$
    – Subho
    May 20, 2018 at 14:34
  • 1
    $\begingroup$ Or you can use this website to convert Mathematica special sharacter. Copy and paste all your code in top area and hit convert then copy the result from bottom and paste it here. steampiano.net/msc $\endgroup$ May 20, 2018 at 14:38

I like to use NDSolve to find the inverse of a function. Start with:

$$g(\theta (z))=z$$

and differentiate to get an ODE for $\theta$:

$$g'(\theta(z)) \theta'(z) = 1$$

In your example, the derivative of $f$ is just the integrand, so the ODE is:

ode = θ'[z]/Sqrt[Cot[θ[z]]^2-Sin[θ[z]]^2] == 1;

Next, we need an initial condition, which we can obtain by evaluating your $f$ at some point, e.g.:

initial = f[.5]


We have the pieces needed for NDSolve:

sol = NDSolveValue[{ode, θ[initial] == .5}, θ, {z, 0, 1}];

NDSolveValue::mxst: Maximum number of 98592 steps reached at the point z == 0.7425352404828982`.

The solution becomes complex at some point, which causes the message. Visualization:

Plot[sol[z], {z, 0, .742}]

enter image description here


f[θ_] = Integrate[1/(Cot[θ]^2 - Sin[θ]^2)^((1/2)), θ];

If you plot your function you will see that it is periodic and never equals 1

Plot[{f[θ], 1}, {θ, -2 Pi, 2 Pi}]

enter image description here

Verifying that f is periodic

f[θ + 2 π] == f[θ] // Simplify

(* True *)

The function domain for real values in the base period is

fd = FunctionDomain[{f[θ], -π < θ < π}, θ]

enter image description here

fd[[-1]] // N

(* -0.904557 < θ < 0. || 0. < θ < 0.904557 *)

Note that f[0] is undefined


enter image description here

However, the value exists in the limit

Limit[f[θ], θ -> 0]

(* 0 *)

Consequently, add to the definition of f

f[0] = f[0.] = 0;

The maximum value is

FindMaximum[{f[θ], 0 < θ < 
        2*ArcTan[Sqrt[-2 + Sqrt[5]]]}, {θ, 0.5}] // Quiet

(* {0.742394, {θ -> 0.904557}} *)

If, however, you want to find where Abs[f[θ]] == 1

sol = FindRoot[Abs[f[θ]] == 1, {θ, #}] & /@ {-5, -1, 1, 5}

(* {{θ -> -5.03865}, {θ -> -1.24454}, {θ -> 1.24454}, {θ -> 5.03865}} *)

Plot[{Abs[f[θ]], 1}, {θ, -2 π, 2 π},
 Epilog -> {Red, AbsolutePointSize[4],
   Point[{θ, Abs[f[θ]]} /. sol]}]

enter image description here

  • $\begingroup$ Thanks a lot for the extended answer and comments. $\endgroup$
    – Subho
    May 20, 2018 at 15:56

How about this unexpected result?

FindRoot[Integrate[1/(Cot[\[Theta]]^2 - Sin[\[Theta]]^2)^(1/2),\[Theta]] ==
  1, {\[Theta], 5}, AccuracyGoal -> 4]

FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

{[Theta] -> 6.28319 + 1.33034 I}


FindRoot[Integrate[1/(Cot[\[Theta]]^2 - Sin[\[Theta]]^2)^(1/2), \[Theta]] == 
  1, {\[Theta], 1}, AccuracyGoal -> 3, MaxIterations -> 400,WorkingPrecision -> 20]

FindRoot::cvmit: Failed to converge to the requested accuracy or precision within 400 iterations. {[Theta] -> 0.91743686083261174824 + 1.0175067301349649178*10^-6 I}


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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