A numerical method is applied to calculate an optimal distribution of currents in air which generate the magnetic field gradients required to spatially encode the radiofrequency signal in a NMR tomographic experiment. We compare the performances of the gradient circuits for the whole body air-core electromagnet described by Bangert and Mansfield (J. Phys. E 15; 1982) with the results of our optimization.