# How to analytically solve for an intersection of two functions on an interval?

I would like to analytically solve for the intersection of two functions on a given interval and store the solution as a function (of parameters) for later use. How can I tell Mathematica to look for a solution only on the given interval (there may be other intersections outside this interval)?

Here is my concrete example: I consider two functions of $$x$$ which depend on 4 other parameters:

$$f_1(x)=((c - a x) (c + x (-a + 2 r_1 x)))/(3 b x^2)$$

and

$$f_2(x)=((c - a x) (c + x (-a + 2 r_2 x)))/(3 b x^2)$$

where $$a>b>0$$ and $$c>0$$ are identical parameters for the two functions, and the two functions differ only in the values of $$r_1$$ and $$r_2$$ such that $$0.

Both functions have a unique maximum for $$x>c/a$$ which I denote $$x_{f1max}=argmax_{x>c/a} f_1$$ and $$maxf_1=f_1(x_{f1max})$$, and $$x_{f2max}=argmax_{x>c/a} f_2$$ and $$maxf_2=f_2(x_{f2max})$$.

$$r_2 implies that $$x_{f1max} and $$maxf_1.

Consider $$\tilde f_1$$ a "vertically translated" $$f_1$$ such that $$\tilde f_1$$ and $$f_2$$ have the same maximum value: $$\tilde f_1(x)=f_1(x)+maxf_2-maxf_1$$.

$$\tilde f_1$$ and $$f_2$$ intersect once in the interval $$[x_{f1max},x_{f2max}]$$. I would like to find this intersection and store it as a function of the parameters $$a$$, $$b$$, $$c$$, $$r_1$$ and $$r_2$$.

Here is the code where I define the functions:

f[a_, b_, c_, r_, x_] = ((c - a x) (c + x (-a + 2 r x)))/(3 b x^2)
xmax[a_, b_, c_, r_] = ArgMax[{f[a, b, c, r, x], x > c/a}, x];
maxf[a_, b_, c_, r_] = MaxValue[{f[a, b, c, r, x], x > c/a}, x];


Here is how $$\tilde f_1$$ and $$f_2$$ look like and their intersection:

Plot[{f[10, 1, 1, 1, x] + maxf[10, 1, 1, 0.2] - maxf[10, 1, 1, 1],
f[10, 1, 1, 0.2, x]}, {x, 1/10, 5}]


$\tilde f_1$ and $$f_2$$" />

I can find the intersections of the two functions using

SolveValues[
f[a, b, c, r2, x] ==
f[a, b, c, r1, x] + maxf[a, b, c, r2] - maxf[a, b, c, r1], x]]


But this finds all the intersections and I would like to pick up only the one in the interval $$[x_{f1max},x_{f2max}]$$.

I found a way around this using Last:

xInt[a_, b_, c_, r1_, r2_] =
Last[SolveValues[
f[a, b, c, r2, x] ==
f[a, b, c, r1, x] + maxf[a, b, c, r2] - maxf[a, b, c, r1], x]];


but this will not work in other cases when looking for a different intersection. Would anyone please have a suggestion?

• From the top of my head, I'd say you could either add a constraint to the SolveValues, or you filter the results afterwards with Select[solutions, a <= # <= b&]. May 3 at 13:59
• Simplify[((c - a x) (c + x (-a + 2 r1 x)))/(3 b x^2) == ((c - a x) (c + x (-a + 2 r2 x)))/(3 b x^2) evaluates condition ((r1 - r2) (c - a x))/b == 0 for the intersection point! May 3 at 14:16
• @JEM_Mosig Thank you. Adding a constraint to SolveValues would be ideal, but I have not managed to make it work. May 3 at 14:38
• @Ulrich Neumann Thank you. But I need to solve for the intersection of $\tilde f_1(x)=f_1(x)+max f_2-max f_1$ and $f_2$ and not the original $f_1$ and $f_2$. This does not seem to simplify. May 3 at 14:52