bisection and newton for matlab and R