By setting up the solver algorithm in the option settings, the simulation time cna be shortened substantially. E.g.
options = optimoptions('fmincon','Display','off', 'Algorithm', 'active-set');
f = @(x) sum( ( y-x(1)*g-u*x(2) ).^2 );
nonlcon = @unitdisk;
x = fmincon(f,[0.2 0.02],,,,,,,nonlcon,options);
This algorithm shortens the computation time by about 50%. If you are not satisfied with this, you can investigate furthermore with the option settings for fmincon.