In the free-boundary case, the extremum of the potential functional is found from the variational principle. Thereby the equation and boundary conditions required for plasma equilibrium are derived. The Euler equation of the relevant functional is the magnetic surface function equation with the condition of free boundary. A variational functional suitable for numerical computation is given. This functional corresponds to a boundary value problem with an equal-value surface boundary condition. For the case of a conducting wall of simple geometry (i.e., a rectangular wall), numerical computation has been carried out by using the Ritz method.