0
$\begingroup$

I'm sorry if this is a dumb question, but for some reason NSolve isn't working for me. Here's what I'm trying to do.

f1[x_] := (4 - x^2)^(1/2)
f2[x_] := -x*Cot[x]

NSolve[f1[x] == f2[x], x]

During evaluation of In[50]:= Infinity::indet: Indeterminate expression 0 ComplexInfinity encountered. >>

During evaluation of In[50]:= NSolve::naqs: 2==Indeterminate is not a quantified system of equations and inequalities. >>

NSolve[2 == Indeterminate, 0]

I know there is a solution, because I did it on a different numerical solver and I got 1 result equal to 1.895494....

I'm a totally newbie at Mathematica so again, sorry if this is a simple question. I tried my best to figure out how to make it work but I'm not sure what's going on.

$\endgroup$
3
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Oct 5, 2015 at 1:18
  • $\begingroup$ I get a different error message, NSolve::nsmet: This system cannot be solved with the methods available to NSolve. >> Some expressions are too difficult for NSolve. In such cases, use FindRoot instead. It gives your expected answer. $\endgroup$
    – bbgodfrey
    Oct 5, 2015 at 1:23
  • $\begingroup$ This works: NSolve[f1[x] == f2[x] && -3 < x < 3, x]. I arrived at this after I had a look at the plot Plot[{f1[x], f2[x]}, {x, -5, 5}]. $\endgroup$ Oct 5, 2015 at 11:08

1 Answer 1

3
$\begingroup$

No dumb at all,

Plot[{f1[x], f2[x]}, {x, -π, π}]

enter image description here

As commented by @StephenLuttrell NSolve works with intervalls quite well;

NSolve[f1[x] == f2[x] && -3 < x < 3, x]
{{x -> -1.89549}, {x -> 1.89549}}

As well FindInstance and FindRoot

FindInstance[f1[x] == f2[x], x] // N // Chop
{{x -> 1.89549}}
FindRoot[f1[x] == f2[x], {x, -2}] // Chop
{x -> -1.89549}

So, you'll find the Intersections with:

pts = {x, f2[x]} /. FindRoot[f1[x] == f2[x], {x, #}] & /@ {-2, 2} // 
  Chop
{{-1.89549, 0.638045}, {1.89549, 0.638045}}
Plot[{f1[x], f2[x]}, {x, -π, π}, 
 Epilog -> {Red, AbsolutePointSize[6], Point[pts]}]

enter image description here

$\endgroup$

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