c-Vector; linear least-squares VectorG-Matrix; linear least-squares Matrixlc-(optional) list; linear constraintsbd-(optional) list; boundsn-NiNJJ3Bvc2ludEdJKnByb3RlY3RlZEdGJA==; number of variablesq-NiNJJ3Bvc2ludEdJKnByb3RlY3RlZEdGJA==; number of residuals p-procedure; least-squares objective functionnc-(optional) NiNJKm5vbm5lZ2ludEc2JEkqcHJvdGVjdGVkR0YlSShfc3lzbGliRzYi or list of 2 nonnegints; number of nonlinear constraintsnlc-(optional) procedure; nonlinear constraintsopts-(optional) equation(s) of the form option = value where option is one of assume, constraintjacobian, feasibilitytolerance, infinitebound, initialpoint, iterationlimit, method, objectivejacobian, optimalitytolerance, or output; specify options for the LSSolve command

<Text-field style="Heading 2" layout="Heading 2" bookmark="info">Description</Text-field>The LSSolve command solves a least-squares (LS) problem, which involves computing the minimum of an objective function having one of the forms shown below, possibly subject to constraints. Generally, a local minimum is returned unless the problem is convex.LSSolve accepts linearly-constrained, linear LS problems of the following form.minimize LUklbXJvd0c2JEkqcHJvdGVjdGVkR0YlL0krbW9kdWxlbmFtZUc2IkksVHlwZXNldHRpbmdHNiRGJUkoX3N5c2xpYkdGKDYkLUkmbWZyYWNHNiRGJS9GJ0YpNiUtSSNtbkc2JEYlL0YnRik2I1EiMUYoLUYzNiNRIjJGKC9JLmxpbmV0aGlja25lc3NHRihGNy1JJW1zdXBHNiRGJS9GJ0YpNiQtSShtZmVuY2VkRzYkRiUvRidGKTYlLUYjNictSSNtaUc2JEYlL0YnRik2I1EiY0YoLUkjbW9HNiRGJS9GJ0YpNiNRKCZtaW51cztGKC1GSjYjUSJHRigtRlA2I1ExJkludmlzaWJsZVRpbWVzO0YoLUZKNiNRInhGKC9JJW9wZW5HNiRGJUYrUScmVmVydDtGKC9JJmNsb3NlRzYkRiVGK0Zbb0Y4subject toNiMxLUkiLkc2JEkqcHJvdGVjdGVkR0YnSShfc3lzbGliRzYiNiRJIkFHRilJInhHRilJImJHRik= (linear inequality constraints)NiMvLUkiLkc2JEkqcHJvdGVjdGVkR0YnSShfc3lzbGliRzYiNiRJJEFlcUdGKUkieEdGKUkkYmVxR0Yp (linear equality constraints)LUklbXJvd0c2JEkqcHJvdGVjdGVkR0YlL0krbW9kdWxlbmFtZUc2IkksVHlwZXNldHRpbmdHNiRGJUkoX3N5c2xpYkdGKDYnLUkjbWlHNiRGJS9GJ0YpNiNRI2IxRigtSSNtb0c2JEYlL0YnRik2I1ElJmxlO0YoLUYuNiNRInhGKEYzLUYuNiNRI2J1Rig= (bounds)where NiNJInhHNiI= is the vector of problem variables; NiNJImNHNiI=, NiNJImJHNiI=, NiNJJGJlcUc2Ig==, NiNJI2JsRzYi and NiNJI2J1RzYi are vectors; and NiNJIkdHNiI=, NiNJIkFHNiI= and NiNJJEFlcUc2Ig== are matrices. The relations involving matrices and vectors are element-wise. The dimension of NiNJImNHNiI= must be greater than or equal to the dimension of NiNJInhHNiI=.LSSolve also accepts nonlinear LS problems of the following form.minimize NiMvLUkiRkc2IjYjSSJ4R0YmKiYtSSFHRiY2IyMiIiIiIiNGLiwqKiQtSSNmMUdGJkYnRi9GLiokLUkjZjJHRiZGJ0YvRi5JJC4uLkc2JEkqcHJvdGVjdGVkR0Y5SShfc3lzbGliR0YmRi4qJC1JI2ZxR0YmRidGL0YuRi4=subject toNiMxLUkidkc2IjYjSSJ4R0YmIiIh (nonlinear inequality constraints)NiMvLUkid0c2IjYjSSJ4R0YmIiIh (nonlinear equality constraints)NiMxLUkiLkc2JEkqcHJvdGVjdGVkR0YnSShfc3lzbGliRzYiNiRJIkFHRilJInhHRilJImJHRik= (linear inequality constraints)NiMvLUkiLkc2JEkqcHJvdGVjdGVkR0YnSShfc3lzbGliRzYiNiRJJEFlcUdGKUkieEdGKUkkYmVxR0Yp (linear equality constraints)LUklbXJvd0c2JEkqcHJvdGVjdGVkR0YlL0krbW9kdWxlbmFtZUc2IkksVHlwZXNldHRpbmdHNiRGJUkoX3N5c2xpYkdGKDYnLUkjbWlHNiRGJS9GJ0YpNiNRI2IxRigtSSNtb0c2JEYlL0YnRik2I1ElJmxlO0YoLUYuNiNRInhGKEYzLUYuNiNRI2J1Rig= (bounds)where each NiMtSSNmaUc2IjYjSSJ4R0Yl is a real-valued function of NiNJInhHNiI=; NiMtSSJ2RzYiNiNJInhHRiU= and NiMtSSJ3RzYiNiNJInhHRiU= are vector-valued functions of NiNJInhHNiI=; and the other components are as described previously. The algorithms used by LSSolve assume the residuals NiMtSSNmaUc2IjYjSSJ4R0Yl and the constraints are twice continuously differentiable. LSSolve will sometimes succeed even if this condition is not met. The number of residuals must be greater than or equal to the dimension of NiNJInhHNiI=.This help page describes how to specify the problem in Matrix form. For details about the exact format of the objective function and the constraints, see the Optimization/MatrixForm help page. The algebraic and operator forms for specifying an LS problem are described in the Optimization[LSSolve] help page. The Matrix form is more complex, but leads to more efficient computation.Consider the first calling sequence for linearly constrained, linear LS problems. The first parameter NiM3JEkiY0c2IkkiR0dGJQ== is a list containing the LS Vector and Matrix respectively.The second parameter lc is an optional list of linear constraints. The most general form is NiM3JkkiQUc2IkkiYkdGJUkkQWVxR0YlSSRiZXFHRiU=, where A and Aeq are Matrices, and b and beq are Vectors. This parameter can take other forms if either inequality or equality constraints do not exist. For a full description of how to specify general linear constraints, refer to the Optimization/MatrixForm help page.The third parameter NiNJI2JkRzYi is an optional list NiM3JEkjYmxHNiJJI2J1R0Yl of lower and upper bounds. In general, bl and bu must be NiNJIm5HNiI=-dimensional Vectors. The Optimization/MatrixForm help page describes alternate forms that can be used when either bound does not exist and provides more convenient ways of specifying the Vectors. Non-negativity of the variables is not assumed by default, but can be specified using the assume = nonnegative option.Use the second calling sequence for nonlinear LS problems. Again, refer to the Optimization/MatrixForm help page for more details about the format of each parameter.The first parameter [n, q] is a list containing the number of problem variables followed by the number of residuals.The second parameter p is a procedure, LUklbXJvd0c2JEkqcHJvdGVjdGVkR0YlL0krbW9kdWxlbmFtZUc2IkksVHlwZXNldHRpbmdHNiRGJUkoX3N5c2xpYkdGKDYnLUkjbWlHNiRGJS9GJ0YpNiNRJXByb2NGKC1JI21vRzYkRiUvRidGKTYjUTAmQXBwbHlGdW5jdGlvbjtGKC1JKG1mZW5jZWRHNiRGJS9GJ0YpNiMtRiM2JS1GLjYjUSJ4RigtRjQ2I1EoJmNvbW1hO0YoLUYuNiNRInlGKC1GLjYjUSQuLi5GKC1GLjYjUSllbmR+cHJvY0Yo, that computes the values of the residuals. The current point is passed as the Vector NiNJInhHNiI=, and the values of NiMtSSNmMUc2IjYjSSJ4R0Yl, NiMtSSNmMkc2IjYjSSJ4R0Yl, ..., NiMtSSNmcUc2IjYjSSJ4R0Yl are returned using the Vector parameter NiNJInlHNiI=.The third parameter nc is a list of two non-negative integers representing the number of nonlinear inequality constraints and the number of nonlinear equality constraints. If there are no inequality constraints, nc can be a single integer value.The fourth parameter nlc is a procedure, LUklbXJvd0c2JEkqcHJvdGVjdGVkR0YlL0krbW9kdWxlbmFtZUc2IkksVHlwZXNldHRpbmdHNiRGJUkoX3N5c2xpYkdGKDYnLUkjbWlHNiRGJS9GJ0YpNiNRJXByb2NGKC1JI21vRzYkRiUvRidGKTYjUTAmQXBwbHlGdW5jdGlvbjtGKC1JKG1mZW5jZWRHNiRGJS9GJ0YpNiMtRiM2JS1GLjYjUSJ4RigtRjQ2I1EoJmNvbW1hO0YoLUYuNiNRInlGKC1GLjYjUSQuLi5GKC1GLjYjUSllbmR+cHJvY0Yo, that computes the values of the nonlinear constraints. The current point is passed as the Vector NiNJInhHNiI=, and the values of NiMtSSJ2RzYiNiNJInhHRiU= followed by the values of NiMtSSJ3RzYiNiNJInhHRiU= are returned using the Vector parameter NiNJInlHNiI=.The fifth parameter lc, representing linear constraints, and the sixth parameter bd, representing bounds, are as described for the first calling sequence.If the residuals are nonlinear and there are no nonlinear constraints, the third calling sequence, in which parameters nc and nlc are omitted, can be used.Maple returns the solution as a list containing the final minimum value and a point (the extremum). If the output = solutionmodule option is provided, then a module is returned. See the Optimization/Solution help page for more information.
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk1">Options</Text-field>The opts argument can contain one or more of the following options. These options are described in more detail in the Optimization/Options help page.assume = nonnegative -- Assume that all variables are non-negative.constraintjacobian = procedure -- Use the provided procedure to compute the Jacobian matrix of the constraints. The form required for the procedure is described in the Nonlinear Constraints section of the Optimization/MatrixForm help page.feasibilitytolerance = realcons(positive) -- Set the maximum absolute allowable constraint violation.infinitebound = realcons(positive) -- Set any value of a variable greater than the infinitebound value to be equivalent to infinity during the computation.initialpoint = Vector -- Use the provided initial point, which is an n-dimensional Vector of numeric values.iterationlimit = posint -- Set the maximum number of iterations performed by the algorithm.method = modifiednewton or sqp -- Specify the method. See the Optimization/Methods help page for more information.objectivejacobian = procedure -- Use the provided procedure to compute the Jacobian matrix of the objective function residuals. The form required for the procedure is described in the Nonlinear Least-Squares Objective section of the Optimization/MatrixForm help page.optimalitytolerance = realcons(positive) -- Set the tolerance that determines whether an optimal point has been found. This option is not available when the problem is linear.output = solutionmodule -- Return a module as described in the Optimization/Solution help page.
<Text-field style="Heading 2" layout="Heading 2" bookmark="bkmrk2">Notes</Text-field>The LSSolve command uses various methods implemented in a built-in library provided by the Numerical Algorithms Group (NAG). See the Optimization/Methods help page for more details. The solvers are iterative in nature and require an initial point. The quality of the solution can depend greatly on the point chosen, particularly for nonlinear problems, so it is recommended that you provide a point through the initialpoint option. Otherwise, a point is automatically generated.The computation is performed in floating-point. Therefore, all data provided must have type realcons and all returned solutions are floating-point, even if the problem is specified with exact values. For best performance, Vectors and Matrices should be constructed with the NiMvSSlkYXRhdHlwZUc2IkkmZmxvYXRHSSpwcm90ZWN0ZWRHRic= option and all procedures should work with evalhf. Because the solver fails when a complex value is encountered, it is sometimes necessary to add additional constraints to ensure that the objective function and constraints always evaluate to real values. For more information about numeric computation in the Optimization package and suggestions on how to obtain the best performance using the Matrix form of input, see the Optimization/Computation help page.For some methods of solving nonlinear problems, the computation is more efficient when derivatives of the objective function and constraints are available. Use objectivejacobian and constraintjacobian to set these options. For information on the methods that use derivatives, see the Optimization/Methods help page.Although the assume = nonnegative option is accepted, general assumptions are not supported by commands in the Optimization package.An answer is returned when necessary first-order conditions for optimality have been met and the iterates have converged. If the initial point already satisfies the conditions, then a warning is issued. Generally, the result is a local extremum but it is possible for the solver to return a saddle point. It is recommended that you try different initial points with each problem to verify that the solution is indeed an extremum.Occasionally the solver will return a solution even if the iterates have not converged but the point satisfies the first-order conditions. Setting infolevel[Optimization] to 1 or higher will produce a message indicating this situation if it occurs.If LSSolve returns an error saying that no solution could be found, it is recommended that you try a different initial point or use tolerance parameters that are less restrictive.
<Text-field style="Heading 2" layout="Heading 2" bookmark="examples">Examples</Text-field>with(Optimization):Use the first calling sequence for LSSolve to minimize the objective function NiMqJi1JIUc2IjYjIyIiIiIiI0YpLCYqJCwmRipGKUkieEdGJiEiKEYqRikqJCwmISIkRilGLiEiJkYqRilGKQ== in Matrix form.c := Vector([2,-3], datatype = float):G := Matrix([[7],[5]], datatype = float):LSSolve([c, G]);Minimize NiMqJi1JIUc2IjYjIyIiIiIiI0YpLCgqJCwmRilGKUkieEdGJiEiIkYqRikqJCwmRilGKUkieUdGJkYvRipGKSokLCZGKUYpSSJ6R0YmRi9GKkYpRik= subject to the constraints NiMxLCZJInhHNiIiIidJInlHRiYiIiQiIiI= and NiMxSSJ4RzYiIiIh.c := Vector([1,1,1], datatype = float):G := Matrix([[1,0,0], [0,1,0], [0,0,1]], datatype = float):A := Matrix([[6,3,0], [1,0,0]], datatype = float):b := Vector([1,0], datatype = float):lc := [A, b]:LSSolve([c, G], lc);See AlsoCurveFittingevalhfOptimizationOptimization/AlgebraicFormOptimization/ComputationOptimization/MatrixFormOptimization/MethodsOptimization/OptionsOptimization/SolutionOptimization[LSSolve]realcons