Moving-horizon estimation for discrete-time linear and nonlinear systems using the gradient and Newton methods