# How to find the number of real roots for this equation?

I want to find the number of real roots that satisfy this equation:

f[g[x]] - h[f[x]] == (a)^2

Where:

f[x_] = x*Cos[x]
g[x_] = CubeRoot[-5 + (x)^2]
h[x_] = Abs[x + 2]

Where x is given as between the values of 0 and 5 i.e. [0,5]. And a is a parameter that i can change the value of.

What I have tried so far is to animate the function to just get a visual on the functions. I wrote this code:

Animate[Plot[{f[g[x]] - h[f[x]], (a)^2}, {x, 0, 5}], {a, 0, 1}]

I then wondered what might be the maximum value in this interval and I found it to be 0.511 when x = 2.4987. I used this code:

FindMaximum[{f[g[x]] - h[f[x]]}, {x, 2, 5}]

That value is given when a = 0.71499.

By a purely graphical analysis there are always two solutions to this equation at any one value of a when a is between the values of [0,0.71499). At a=0.71499 there is only one solution and beyond it there are no solutions. Now how do I calculate the total number of roots to this equations? I have tried the command CountRoots but it doesn't yield a result. Any other suggestions?

• CountRoots expects a univariate function ! Commented Sep 13, 2023 at 15:29

ContourPlot gives you an idea of the answer I think

f[x_] = x*Cos[x]
g[x_] = CubeRoot[-5 + (x)^2]
h[x_] = Abs[x + 2]

pic=ContourPlot[f[g[x]] - h[f[x]] == (a)^2, {x, 0, 5}, {a, -1, 1}, FrameLabel -> {x, a}]

mini = NMinimize[{a, f[g[x]] - h[f[x]] == (a)^2, Element[a, Reals]}, {x, a}]
(*{-0.715053, {x -> 2.49876, a -> -0.715053}}*)
maxi = NMaximize[{a, f[g[x]] - h[f[x]] == (a)^2,Element[a, Reals]}, {x, a}]
(*{0.714933, {x -> 2.49863, a -> 0.714933}}*)

amin=a/.mini[[2]]; (*-0.715053*)
amax=a/.maxi[[2]]; (*0.714933*)

As you can see from ContourPlot:

There exist two solutions if amin<a<amax There exists one solutions if a==amin or a==amax In all other cases there is no real solution

There exists no solution if `a>a/.maxi

• It's clear the plot is symmetric with respect to a-axis since the function is even in a. Commented Sep 13, 2023 at 15:17
• I am sorry but I dont understand. What is a contour plot, how exactly does it answer my question and how do I calculate the number of real roots with this information? Commented Sep 13, 2023 at 15:27
• @IhabAlrikabi In my answer ContourPlot[...] plots all points x,a which fullfill the equation f[g[x]] - h[f[x]] == (a)^2 Commented Sep 13, 2023 at 15:31
• Oh ok I understand its purpose now but I dont see how I should use this info to calculate the number of solutions. Commented Sep 13, 2023 at 15:36

You can try FindInstance:

FindInstance[f[g[x]] - h[f[x]] == a^2, {a, x}, Reals]

And

FindInstance[f[g[x]] - h[f[x]] == a^2, {a, x}, Complexes]

Each of these yielded one solution, both outside your outside domain. Neither found multiple solutions, but that is limited by the methods available to the function.

Look at the result of

f[x_] = x*Cos[x];g[x_] = CubeRoot[-5 + (x)^2] ;h[x_] = Abs[x + 2];
ContourPlot[{f[g[x]] - h[f[x]] == (a)^2}, {x, 0, 5}, {a, 0, 1}]

to this end.