Main Content
Minimize Nonlinear Function Using Multiple-Start Solver, Problem-Based
Find a local minimum of the peaks
function on the range starting from the point [–1,2]
.
x = optimvar("x",LowerBound=-5,UpperBound=5); y = optimvar("y",LowerBound=-5,UpperBound=5); x0.x = -1; x0.y = 2; prob = optimproblem(Objective=peaks(x,y)); opts = optimoptions("fmincon",Display="none"); [sol,fval] = solve(prob,x0,Options=opts)
sol = struct with fields:
x: -3.3867
y: 3.6341
fval = 1.1224e-07
Try to find a better solution by using the GlobalSearch
solver. This solver runs fmincon
multiple times, which potentially yields a better solution.
ms = GlobalSearch; [sol2,fval2] = solve(prob,x0,ms)
Solving problem using GlobalSearch. GlobalSearch stopped because it analyzed all the trial points. All 15 local solver runs converged with a positive local solver exit flag.
sol2 = struct with fields:
x: 0.2283
y: -1.6255
fval2 = -6.5511
GlobalSearch
finds a solution with a better (lower) objective function value. The exit message shows that fmincon
, the local solver, runs 15 times. The returned solution has an objective function value of about –6.5511, which is lower than the value at the first solution, 1.1224e–07.
See Also
GlobalSearch
| MultiStart
| run
| solve