A nonlinear programming optimization algorithm is implemented for the control of a PMSM to find the optimum current vector references which minimize the total copper and core losses in the entire operating region of the motor, including the field weakening mode. The maximum voltage and current constraints of the drive system are also included in the optimization. The results for an investigated 50 kW PMSM-machine from the optimization algorithm is compared with Maximum Torque Per Ampere(MTPA) field oriented vector control method which inherently takes in to account the copper loss only. It is shown that the efficiency is improved in the entire high-speed operating region of the machine up to 8%. Besides, the machine is simulated in an electric vehicle and it is shown that by using the optimization method instead of the MTPA, the power loss is decreased up to 1.5 % in NEDC drive cycle. Furthermore the loss determination in the equivalent circuit has been further improved by using a variable core loss resistance.