Generalize script for any function f(x)