Display optimization object




show(obj) displays information about obj at the command line. If the object display is large, consider using write instead to output the display to a text file.


collapse all

The show function returns information about problem-based objects at the command line. For example, examine the various stages of problem construction for optimizing the Rosenbrock function confined to the unit disk (see Solve a Constrained Nonlinear Problem, Problem-Based).

Create a 2-D optimization variable x. Show the variable.

x = optimvar('x',2);
    [ x(1) ]
    [ x(2) ]

Create an expression for the objective function. Show the expression.

obj = 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2;
  ((100 .* (x(2) - x(1).^2).^2) + (1 - x(1)).^2)

Create an expression for the constraint. Show the constraint.

cons = x(1)^2 + x(2)^2 <= 1;
  (x(1).^2 + x(2).^2) <= 1

Create an optimization problem having obj as the objective function and cons as the constraint. Show the problem.

prob = optimproblem("Objective",obj,"Constraints",cons);
  OptimizationProblem : 

	Solve for:

	minimize :
       ((100 .* (x(2) - x(1).^2).^2) + (1 - x(1)).^2)

	subject to :
       (x(1).^2 + x(2).^2) <= 1

Finally, create an initial point [0 0] and solve the problem starting at the intial point.

x0.x = [0 0];
[sol,fval,exitflag] = solve(prob,x0)
Solving problem using fmincon.

Local minimum found that satisfies the constraints.

Optimization completed because the objective function is non-decreasing in 
feasible directions, to within the value of the optimality tolerance,
and constraints are satisfied to within the value of the constraint tolerance.
sol = struct with fields:
    x: [2x1 double]

fval = 0.0457
exitflag = 

Examine the solution point.

ans = 2×1


Input Arguments

collapse all

Optimization object, specified as one of the following types.

  • OptimizationProblemshow(obj) displays the variables for solution, objective function, constraints, and variable bounds.

  • EquationProblemshow(obj) displays the variables for solution, equations for solution, and variable bounds.

  • OptimizationExpressionshow(obj) displays the optimization expression.

  • OptimizationVariableshow(obj) displays the optimization variables. This display does not indicate variable type or bounds, it shows only the variable dimensions and index names (if any).

  • OptimizationConstraintshow(obj) displays the constraint expression.

  • OptimizationEqualityshow(obj) displays the equality expression.

  • OptimizationInequalityshow(obj) displays the inequality expression.

Example: show(obj)

Introduced in R2019b