Find $a,b$ for $f(x) = \frac{x^2-x+a}{x^2-4x+b}$ when $f(x)\le-\frac{7}{2}$ or $f(x) \ge \frac{1}{2}$ I'm self-studying and have attempted the following question. I don't have access to a worked solution.
Find $a,b$ for real $x$:
$$f(x) = \frac{x^2-x+a}{x^2-4x+b}\quad when\quad f(x)\le-\frac{7}{2}\space or\space f(x) \ge \frac{1}{2}$$
I however keep getting stuck and find myself always facing division by $0$.
I have a feeling I'm missing some intuition here. I don't think there are operation or arithmetic errors. I am not confident that I have setup the equations correctly either. My questions are:
1) What is the correct approach here / key idea I'm missing?
2) What is the solution?
A sample of my working is as follows:
$$\frac{x^2-x+a}{x^2-4x+b} = -\frac{7}{2}\Rightarrow 9x^2-30x = b - 2a\qquad [1]$$
$$\frac{x^2-x+a}{x^2-4x+b} = \frac{1}{2}\Rightarrow x^2+2x = b-2a \qquad [2]$$
$$[2]-[1]:\qquad 8x^2 - 32x = 0 \Rightarrow x(x-4) = 0\Rightarrow x=0,x=4$$
$x = 0$ leads to $b=0$ which leads to division by $0$ so I discarded it.
Subbing $x=4$ gives:
$$\frac{12 + a}{b} = -\frac{7}{2} \Rightarrow 24 + 2a = -7b \qquad [3]$$
$$\frac{12+1}{b} = \frac{1}{2} \Rightarrow 24 + 2a = b \qquad [4]$$
$[3] + 7[4]$ gives:
$$192 + 16a = 0 \Rightarrow a = -\frac{192}{16} \Rightarrow a = -12$$
Subbing $a=-12$ into $[4] \Rightarrow b = 0$
So for $x=4,a=-12,b=0$ the denominator becomes $0$.
 A: Well, at first, let 
$$p(x)=x^2-x+a$$
$$q(x)=x^2-4x+b$$
Then, we have:
$$f(x)=\frac{p(x)}{q(x)}$$
Also - crucial note here - we see that:
$$\lim_{x\to+\infty}f(x)=\lim_{x\to-\infty}f(x)=1$$.
Let us now consider the following cases:


*

*If q(x) has no real roots, hence:
$$\Delta=16-4b=4(4-b)<0\Leftrightarrow b>4$$
then $f$'s domain is $\mathbb{R}$ and $q(x)>0$. 

*If q(x) has exactly one (double) real root, hence:
$$\Delta=16-4b=4(4-b)=0\Leftrightarrow b=4$$
then $f$'s domain is $(-\infty,2)\cup(2,+\infty)$ and $q(x)>0$ for $x\neq2$. 

*If q(x) has two real roots, hence:
$$\Delta=16-4b=4(4-b)>0\Leftrightarrow b<4$$
then $f$'s domain is $(-\infty,c)\cup(c,d)\cup(d,+\infty)$ and where
$$c=2-\sqrt{4-b}\mbox{ and }d=2+\sqrt{4-b}$$ and for $q(x)$ we have that
$$\begin{array}{c|ccccccc}
x & -\infty & & c& & d & &+\infty\\
\hline
q(x) & & + & 0 & - & 0 & + & \\
\end{array}$$


In the first case, $b>4$, we note that, if there exists a $\xi\in\mathbb{R}$ such that
$$f(\xi)\leq-\frac{7}{2}$$
then, by Intermediate Values Theorem, since $\lim\limits_{x\to\pm\infty}f(x)=1>0$, there should exist (at least two, but one is enough in our case) $x_0\in\mathbb{R}$ such that $$f(x_0)=0$$
which contradicts with our hypothesis. So, only $f(x)\geq\frac{1}{2}$ can hold in that case.
In the same way, the same result applies to case 2. For the third case we can ensure that such a result holds for every $x\in(-\infty,c)\cup(d,+\infty)$. So, in this case only, $f$ may be lesser that $-\frac{7}{2}$ for every $x\in(c,d)$.
Consider now the inequality 
$$f(x)=\frac{p(x)}{q(x)}\geq\frac{1}{2}$$
in any case in which it necessarily holds - so, everything from the aforematnioned, apart from $x\in(c,d)$ in case 3. In all these, $q(x)>0$, so the above is equivalent to:
$$s(x):=2p(x)-q(x)\geq0\Leftrightarrow x^2+2x+2a-b\geq0\tag{$\star$}$$
Now, back to our cases:


*

*If $b>4$, then $(\star)$ needs to hold for every $x\in\mathbb{R}$, so:
$$\Delta^\prime=4-4(2a-b)\leq0\Leftrightarrow4-8a+4b\leq0\Leftrightarrow2a\geq1-b$$.

*If $b=4$, then $(\star)$ needs to hold for every $x\neq2$, so:
$$\Delta^\prime=4-4(2a-b)\leq0\Leftrightarrow4-8a+4b\leq0\Leftrightarrow2a\geq1-b\Leftrightarrow2a\geq-3$$.

*If $b<4$, then $(\star)$ needs to hold for every $x\in(-\infty,c)\cup(d,+\infty)$. It is obvious that $s(x)>0$ for every $x\in(-\infty,\rho_1)\cup(\rho_2,+\infty)$ where $\rho_1\leq\rho_2$ are the two real roots of $s(x)=0$. It is then equivalent to demand that
$$c\leq\rho_1\leq\rho_2\leq d$$
Since
$$\rho_1=-1-\sqrt{1-2a+b}\mbox{ and }\rho_2=-1+\sqrt{1-2a+b}$$
solving this system of inequalities will give us the wanted result. Lastly, we need to check, in the same way what happens when $x\in(c,d)$, which, by now, should be trivial.


Important note! What is to be highlighted from this question is that the hypothesis in the form:
$$f(x)\leq A\mbox{ OR }f(x)\geq B$$
does not mean that, if $A<B$, is a contradiction. It means, instead, that for some $x$ the first inequality is satisfied and for the rest, the second one is satisfied.
