A numerical method to obtain optimal quadrature formulas