In this work, the modified Lyapunov-Schmidt reduction is used to find a nonlinear Ritz approximation of Fredholm functional defined by the nonhomogeneous Camassa-Holm equation and Benjamin-Bona-Mahony. We introduced the modified Lyapunov-Schmidt reduction for nonhomogeneous problems when the dimension of the null space is equal to two. The nonlinear Ritz approximation for the nonhomogeneous Camassa-Holm equation has been found as a function of codimension twenty-four.