# lattice parameter (um)
a_min = 0.50;
a_max = 3.00;

# waveguide width (fraction of lattice parameter)
dfrac_min = 0.2;
dfrac_max = 0.8;

opt.algorithm = NLOPT_LN_BOBYQA;
opt.ftol_abs = 0.005;
opt.xtol_abs = 0.02;
opt.maxeval = 50;
opt.verbose = 1;
opt.initial_step = 0.04;
opt.lower_bounds = [ a_min dfrac_min ];
opt.upper_bounds = [ a_max dfrac_max ];
opt.max_objective = @compute_radiated_power;

# random initial parameters
a_0 = a_min + (a_max-a_min)*rand;
dfrac_0 = dfrac_min + (dfrac_max-dfrac_min)*rand;

[xopt, fopt, retcode] = nlopt_optimize(opt,[a_0 dfrac_0]);

disp(sprintf("optimum:, a=%0.2f um, d=%0.2f um",xopt(1),xopt(1)*xopt(2)));
