Theory and design of nonlinear metamaterials