Save optimization problem description
writeproblem( saves a description
of the optimization problem
prob in a file named
prob is the workspace variable name of the problem.
writeproblem cannot construct the file name from the problem
name, it writes to
writeproblem function overwrites any existing file.
Create an optimization problem.
x = optimvar('x'); y = optimvar('y'); prob = optimproblem; prob.Objective = -x - y/3; prob.Constraints.cons1 = x + y <= 2; prob.Constraints.cons2 = x + y/4 <= 1; prob.Constraints.cons3 = x - y <= 2; prob.Constraints.cons4 = x/4 + y >= -1; prob.Constraints.cons5 = x + y >= 1; prob.Constraints.cons6 = -x + y <= 2;
Save the problem description in a file in the current directory.
The contents of
minimize : -x - 0.33333*y subject to cons1: x + y <= 2 subject to cons2: x + 0.25*y <= 1 subject to cons3: x - y <= 2 subject to cons4: 0.25*x + y >= -1 subject to cons5: x + y >= 1 subject to cons6: -x + y <= 2
prob— Optimization problem or equation problem
Optimization problem or equation problem, specified as an
OptimizationProblem object or an
EquationProblem object. Create an optimization problem by using
optimproblem; create an equation problem by using
The problem-based approach does not support complex values in an objective function, nonlinear equalities, or nonlinear inequalities. If a function calculation has a complex value, even as an intermediate value, the final result can be incorrect.
prob = optimproblem; prob.Objective = obj; prob.Constraints.cons1 =
prob = eqnproblem; prob.Equations = eqs;
filename— Path to file
Path to the file, specified as a string or character vector. The path is relative to the
current folder. The resulting file is a text file, so the file
name typically has the extension