using optimisation based on Lagrange multipliers