code demo for numerical optimization