write - Save optimization object description - MATLAB (original) (raw)
Save optimization object description
Syntax
Description
Use write
to save the description of an optimization object.
write([obj](#mw%5F59ab0b97-36cf-4b3c-a0d6-3fe3a8e04dfb))
saves a description of the optimization object obj
in a file named_obj
.txt
. Here,obj
_ is the workspace variable name of the optimization object. If write
cannot construct the file name from the expression, it writes the description to WriteOutput.txt
instead. write
overwrites any existing file. If the object description is small, consider using show instead to display the description at the command line.
write([obj](#mw%5F59ab0b97-36cf-4b3c-a0d6-3fe3a8e04dfb),[filename](#d126e166228))
saves a description of obj
in a file named filename
.
Examples
Create an optimization variable and an expression that uses the variable. Save a description of the expression to a file.
x = optimvar('x',3,3); A = magic(3); var = sum(sum(A.*x)); write(var)
write
creates a file named var.txt
in the current folder. The file contains the following text:
8x(1, 1) + 3x(2, 1) + 4x(3, 1) + x(1, 2) + 5x(2, 2) + 9x(3, 2) + 6x(1, 3) + 7*x(2, 3)
- 2*x(3, 3)
Save the expression in a file named 'VarExpression.txt'
in the current folder.
write(var,"VarExpression.txt")
The VarExpression.txt
file contains the same text asvar.txt
.
Input Arguments
Optimization object, specified as one of the following:
- OptimizationProblem object —
write(obj)
saves a file containing the variables for the solution, objective function, constraints, and variable bounds. - EquationProblem object —
write(obj)
saves a file containing the variables for the solution, equations for the solution, and variable bounds. - OptimizationExpression object —
write(obj)
saves a file containing the optimization expression. - OptimizationVariable object —
write(obj)
saves a file containing the optimization variables. The saved description does not indicate variable types or bounds; it includes only the variable dimensions and index names (if any). - OptimizationConstraint object —
write(obj)
saves a file containing the constraint expression. - OptimizationEquality object —
write(obj)
saves a file containing the equality expression. - OptimizationInequality object —
write(obj)
saves a file containing the inequality expression.
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
Version History
Introduced in R2019b