For the Gradient descent (fmincon) optimization solver, the gradients are computed using numerical perturbation:
x is a scalar design variable.
xmin is the lower bound of x.
xmax is the upper bound of x.
xtypical is the scaled value of x.
opt_fcn is the objective function.
dx is relatively large to accommodate simulation solver tolerances.
If you want to compute the gradients in any other way, you can do so in the cost function you write for performing design optimization programmatically. See sdo.optimize and GradFcn of sdo.OptimizeOptions for more information.