calc_w function

Calculate w(x)