An energy-preserving nonlinear system modeling a string with input and output on the boundary