Analysis of Z-scan of thick media with high-order nonlinearity by variational approach