# Specify Start Points for MultiStart, Problem-Based

When solving a problem using MultiStart in the problem-based approach, you can specify the start points using one or both of these techniques:

• Create a vector of OptimizationValues objects using the optimvalues function. Pass this vector as the x0 argument to solve.

• Set the MinNumStartPoints name-value argument when you call solve. If MinNumStartPoints exceeds the number of points in x0, then solve creates extra points at random within the problem bounds.

### Vector of Initial Points

For this example, create the initial points vector as a grid for the variable x consisting of integer values from –10 through 10, and for the variable y consisting of half-integer values from –5/2 through 5/2. The optimvalues function requires a problem, so create an optimization problem with the objective function peaks(x,y).

You must specify the points for optimvalues so that the dimension (index) of the number of points is last. For example, to give multiple values of a scalar t with n points, specify

$\left[t\left(1\right)\phantom{\rule{0.5em}{0ex}}t\left(2\right)\phantom{\rule{0.5em}{0ex}}...\phantom{\rule{0.5em}{0ex}}t\left(n\right)\right]$ (This is 1-by-n, and n is the last index.)

To give multiple values of a vector variable w of length 2, specify

$\left[\begin{array}{ccccc}w\left(1,1\right)& w\left(1,2\right)& w\left(1,3\right)& \cdots & w\left(1,n\right)\\ w\left(2,1\right)& w\left(2,2\right)& w\left(2,3\right)& \cdots & w\left(2,n\right)\end{array}\right]$ (This is 2-by-n, and n is the last index.)

This rule holds even for row vectors. In other words, you specify multiple row vectors as if each were a column vector.

To give multiple values of a matrix A that is 2-by-3, specify

$\left[\begin{array}{ccc}\mathit{A}\left(1,1,1\right)& \mathit{A}\left(1,2,1\right)& \mathit{A}\left(1,3,1\right)\\ \mathit{A}\left(2,1,1\right)& \mathit{A}\left(2,2,1\right)& \mathit{A}\left(2,3,1\right)\end{array}\right]\left[\begin{array}{ccc}\mathit{A}\left(1,1,2\right)& \mathit{A}\left(1,2,2\right)& \mathit{A}\left(1,3,2\right)\\ \mathit{A}\left(2,1,2\right)& \mathit{A}\left(2,2,2\right)& \mathit{A}\left(2,3,2\right)\end{array}\right]\cdots \left[\begin{array}{ccc}\mathit{A}\left(1,1,\mathit{n}\right)& \mathit{A}\left(1,2,\mathit{n}\right)& \mathit{A}\left(1,3,\mathit{n}\right)\\ \mathit{A}\left(2,1,\mathit{n}\right)& \mathit{A}\left(2,2,\mathit{n}\right)& \mathit{A}\left(2,3,\mathit{n}\right)\end{array}\right]$(This is 2-by-3-by-n, and n is the last index.)

In the present example, ensure that you specify the multiple values of the scalar variables x and y as row vectors, as in the scalar t example.

x = optimvar("x",LowerBound=-10,UpperBound=10);
y = optimvar("y",LowerBound=-5/2,UpperBound=5/2);
prob = optimproblem(Objective=peaks(x,y));
xval = -10:10;
yval = (-5:5)/2;
[x0x,x0y] = meshgrid(xval,yval);
% Convert x0x and x0y to row vectors for optimvalues
x0 = optimvalues(prob,x=x0x(:)',y=x0y(:)');

Solve the minimization problem starting from all the points in x0.

ms = MultiStart;
[sol,fval,eflag,output] = solve(prob,x0,ms)
Solving problem using MultiStart.

MultiStart completed the runs from all start points.

All 231 local solver runs converged with a positive local solver exit flag.
sol = struct with fields:
x: 0.2283
y: -1.6255

fval = -6.5511
eflag =
LocalMinimumFoundAllConverged

output = struct with fields:
funcCount: 2230
localSolverTotal: 231
localSolverSuccess: 231
localSolverIncomplete: 0
localSolverNoSolution: 0
message: 'MultiStart completed the runs from all start points....'
local: [1x1 struct]
constraintDerivative: "auto"
globalSolver: 'MultiStart'
solver: 'fmincon'

### Random Start Points

Solve the problem again, this time using MultiStart from 25 random initial points. Set the initial point for solve to [–1,2].

init.x = -1;
init.y = 2;
rng default % For reproducibility
[sol2,fval2,eflag2,output2] = solve(prob,init,ms,MinNumStartPoints=25)
Solving problem using MultiStart.

MultiStart completed the runs from all start points.

All 25 local solver runs converged with a positive local solver exit flag.
sol2 = struct with fields:
x: 0.2283
y: -1.6255

fval2 = -6.5511
eflag2 =
LocalMinimumFoundAllConverged

output2 = struct with fields:
funcCount: 161
localSolverTotal: 25
localSolverSuccess: 25
localSolverIncomplete: 0
localSolverNoSolution: 0
message: 'MultiStart completed the runs from all start points....'
local: [1x1 struct]