  We analyse the production of defects during the dynamical crossing of a
mean-field phase transition with a real order parameter. When the parameter
that brings the system across the critical point changes in time according to a
power-law schedule, we recover the predictions dictated by the well-known
Kibble-Zurek theory. For a fixed duration of the evolution, we show that the
average number of defects can be drastically reduced for a very large but
finite system, by optimising the time dependence of the driving using optimal
control techniques. Furthermore, the optimised protocol is robust against small
fluctuations.
