Differentiable function which smoothly transitions from $\frac{1}{\cos(x)}$ function into constant value Is it possible to construct a differentiable function which behaves as a $\frac{1}{\cos(x)}$ function of x until a threshold (less than $\frac{\pi}{2}$) then is close to or is a constant value? I show what I'm looking for in the figure below. The function I want to create is differentiable and behaves the same as one over cosine at values less than the threshold (the green curved line) but is constant or near constant at x values greater than the threshold (the straight blue line). 

 A: There is no differentiable function $f:[0,b] \to \mathbb{R}$ such that $b>\pi/2$ and $f(x)=1/\cos(x)$ for all $0<x<\pi/2$. In fact, there is no such continuous function, since such a function would be bounded.  
There is something close which is possible, which is that if you give me any $\epsilon>0$, I can construct a function with the following properties:


*

*$f$ is differentiable on an interval containing $\pi/2$

*For $x<\pi/2-\epsilon$, $f(x)=1/\cos(x)$

*For $x\ge\pi/2$, $f(x)$ is some constant specified in advance


A detailed proof would be quite long, but here is the idea: it relies on the function $\phi(x)=\exp(-1/x^{2})$. It is an exercise to show that $\phi$ is smooth (if we extend it to all of $\mathbb{R}$ by defining $\phi(0)=0$), and all of its derivatives are $0$ at the origin. In particular, $\phi$ is not analytic: the Taylor series for $\phi$ does not converge to $\phi$ anywhere except at $0$.   
What does this mean? Well, you can add any multiple of $\phi$ to $f$ and not change its derivatives. In particular, if you define $f(x)=1/\cos(x)$ on $(0,\pi/2-\epsilon)$, say, and then
$$f(x+\pi/2 - \epsilon)=\frac{1}{\cos(x+\pi/2 - \epsilon)}+ae^{-\frac{b}{x^{2}}}$$
where $a$ and $b$ are suitably chosen constants that $f(y)=C$ and $f'(y)=0$ for some $y \in (\pi/2 - \epsilon, \pi/2)$, and define, $f(x)=C$ for $x>y$, then the resulting glued function will be differentiable, and will have the properties you desire.
