show
Display information about optimization object
Syntax
Description
Use show
to display information about an optimization
object.
Tip
For the full workflow, see Problem-Based Optimization Workflow or Problem-Based Workflow for Solving Equations.
Examples
Examine Problem-Based Setup
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);
show(x)
[ x(1) ] [ x(2) ]
Create an expression for the objective function. Show the expression.
obj = log(1 + 100*(x(2) - x(1)^2)^2 + (1 - x(1))^2); show(obj)
log(((1 + (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; show(cons)
(x(1).^2 + x(2).^2) <= 1
Create an optimization problem that has obj
as the objective function and cons
as the constraint. Show the problem.
prob = optimproblem("Objective",obj,"Constraints",cons); show(prob)
OptimizationProblem : Solve for: x minimize : log(((1 + (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 initial 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.0447
exitflag = OptimalSolution
Examine the solution point.
sol.x
ans = 2×1
0.7864
0.6177
Input Arguments
obj
— Optimization object
OptimizationProblem
object | EquationProblem
object | OptimizationExpression
object | OptimizationVariable
object | OptimizationConstraint
object | OptimizationEquality
object | OptimizationInequality
object
Optimization object, specified as one of the following:
OptimizationProblem
object —show(obj)
displays the variables for the solution, objective function, constraints, and variable bounds.EquationProblem
object —show(obj)
displays the variables for the solution, equations for the solution, and variable bounds.OptimizationExpression
object —show(obj)
displays the optimization expression.OptimizationVariable
object —show(obj)
displays the optimization variables. This display does not indicate variable types or bounds; it shows only the variable dimensions and index names (if any).OptimizationConstraint
object —show(obj)
displays the constraint expression.OptimizationEquality
object —show(obj)
displays the equality expression.OptimizationInequality
object —show(obj)
displays the inequality expression.
Version History
Introduced in R2019b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)