This example shows how to use the Optimization app to solve a constrained least-squares problem.
The problem in this example is to find the point on the plane x1 + 2x2 + 4x3 = 7 that is closest to the origin. The easiest way to solve this problem is to minimize the square of the distance from a point x = (x1,x2,x3) on the plane to the origin, which returns the same optimal point as minimizing the actual distance. Since the square of the distance from an arbitrary point (x1,x2,x3) to the origin is , you can describe the problem as follows:
subject to the constraint
x1 + 2x2 + 4x3 = 7.
The function f(x) is called the objective function and x1 + 2x2 + 4x3 = 7 is an equality constraint. More complicated problems might contain other equality constraints, inequality constraints, and upper or lower bound constraints.
This section shows how to set up the problem with the
in the Optimization app.
optimtool in the Command
Window to open the Optimization app.
lsqlin from the
selection of solvers. Use the
Active set algorithm.
Enter the following to create variables for the objective function:
In the C field, enter
In the d field, enter
The C and d fields should appear as shown in the following figure.
Enter the following to create variables for the equality constraints:
In the Aeq field, enter
In the beq field, enter
The Aeq and beq fields should appear as shown in the following figure.
Click the Start button as shown in the following figure.
When the algorithm terminates, under Run solver and view results the following information is displayed:
The Current iteration value when
the algorithm terminated, which for this example is
The final value of the objective function when the algorithm terminated:
Objective function value: 2.333333333333333
The algorithm termination message:
The final point, which for this example is
0.3333 0.6667 1.3333