0
$\begingroup$

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 0<r<R_c\\ \qquad \qquad \quad\qquad \qquad0, \quad r>R_c \end{cases}$$ Is there a general method I can just apply for a given function and given intervals to get my modified function?

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

1 Answer 1

0
$\begingroup$

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...

The way to achieve that is to apply the following transformations to the function:

$$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).

enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .