# Solving an equation involving elliptic integral

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:

InverseFunction[f]


and

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


In both the cases the evaluation apparently never ends.

What could be a way to get around this?

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

• I really just wanted to solve f[θ]==1. – Subho May 20 '18 at 14:25
• Yeah, 1 doesn't lie in the range of the function. But it was just the idea I was looking for. Thanks – Subho May 20 '18 at 14:34
• 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 – OkkesDulgerci May 20 '18 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]


0.132122

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}] Clear[f]

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}] Verifying that f is periodic

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

(* True *)


The function domain for real values in the base period is

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

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


Note that f is undefined

f However, the value exists in the limit

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

(* 0 *)


Consequently, add to the definition of f

f = f[0.] = 0;


The maximum value is

FindMaximum[{f[θ], 0 < θ <
2*ArcTan[Sqrt[-2 + Sqrt]]}, {θ, 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,
Point[{θ, Abs[f[θ]]} /. sol]}] • Thanks a lot for the extended answer and comments. – Subho May 20 '18 at 15:56

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]] ==
`