Main Content


(Not recommended) Save optimization problem description


writeproblem is not recommended. Use write instead.

writeproblem(prob) saves a description of the optimization problem prob in a file named prob.txt. Here, prob is the workspace variable name of the problem. If writeproblem cannot construct the file name from the problem name, it writes to WriteProblemOutput.txt. The writeproblem function overwrites any existing file.


writeproblem(prob,filename) saves a description of the optimization problem prob in a file named filename.


collapse all

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 ProblemDescription.txt:

	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

Input Arguments

collapse all

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 eqnproblem.


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.

Example: prob = optimproblem; prob.Objective = obj; prob.Constraints.cons1 = cons1;

Example: prob = eqnproblem; prob.Equations = eqs;

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 .txt.

Example: "../Notes/steel_stuff.txt"

Data Types: char | string


  • writeproblem is equivalent to calling all of the following:

  • To obtain the writeproblem information at the Command Window, use showproblem.

Version History

Introduced in R2017b

expand all

Not recommended starting in R2019b