# Is there a general method of creating a cutoff for a given function for chooseable intervals?

I'm trying to implement a cutoff for a potential energy function (Lennard-Jones potential) for a Verlet-integrator I wrote in python. I want to change it in such a way, that for arguments in the interval $$\left ( 0, R_C \right )$$ the function returns it's regular values (unmodified behaviour), but once it goes into $$\left [ R_C, +\infty \right )$$ it only returns Zero. I'm new to writing functions on SE, but I guess the mathematical summary of what I want would be this: $$U(r)=\begin{cases} \displaystyle4\epsilon\left(\left(\frac{\sigma}{r}\right)^6-\left(\frac{\sigma}{r}\right)^{12}\right), \quad 0R_c \end{cases}$$ Is there a general method I can just apply for a given function and given intervals to get my modified function?

• Assuming $\frac00=1$, you could do $$f(x)\cdot\frac12\cdot\left(1+\frac{|x-R_C|}{x-R_C}\right)$$ Dec 15, 2021 at 17:13

Thanks to @Don Thousand I have found the solution with a little bit of thinking of my own. What I'm essentially looking for is a transformed version of the sign function $$sgn(x) = \frac{|x|}{x}$$, so that the image of sgn(x) is no longer ...-1,-1,-1,...,1,1,1..., but ...1,1,1,...,0,0,0...
$$f(x) = 1/2 \cdot sgn(x) \\ g(x) = -f(x) \\ h(x) = g(x) +1/2 \\ i(x) = h(x+R_C) = -1/2 \cdot\left (\frac {|x-Rc|}{x-Rc} + 1\right )$$
You can then multiply it with $$U(r) = 4 \epsilon \left ( \left ( \frac {\sigma}{r} \right )^6 - \left ( \frac {\sigma}{r} \right )^{12} \right )$$ to get the desired behavior. This should work for all functions with positive values and one variable. I'm guessing that it can be extended relatively easily to functions with multiple variables but idk. Here's a plot of the finished result. The only thing that's really different to Don's answer is the sign in the front of i(x). 