Computation of nonlinear least squares estimator and maximum likelihood using principles in matrix calculus