Simulation of galaxy formation