Re: Linear equation system with additional conditions



Torsten Hennig <Torsten.Hennig@xxxxxxxxxxxxxx> wrote in message <13763134.1236166979045.JavaMail.jakarta@xxxxxxxxxxxxxxxxxxxxxx>...
Hi,

I have a linear equation system Ax = b and solve it
with x = A\b.

But now I want to impose come additional constraints
on the solution x, in my case it would be that a
certain number of elements of x would have to be
queal, i.e. diff(x(j:k)) = 0.

Is there an easy way to implement this?

Thanks

Thomas

Add the equations
x_j - x_k = 0
to the system Ax = b and solve in the usual way
(x = A~\b~).

Best wishes
Torsten.

While you can do this, it is subtly different from
applying an equality constraint.

When you append the equality constraints as
another row to the linear system, they merely
become yet one more "data point" in the linear
least squares problem. As such, the constraint
will NOT be satisfied in the analysis, only subject
to noise, and lack of fit.

That is, if the least squares solver does not really
"want" to satisfy the constraint, it will accept some
error in it. So really the constraint then becomes

x_j - x_k + noise = 0

Not

x_j - x_k == 0

as you probably desire.

The point is, when you formulate a linear least
squares subject to equality constraints, typically
one wishes to find the solution vector X such that

norm(A*X - b)

is minimized, subject to the equality constraint

C*X = d

is exactly satisfied. See that merely adding those
extra rows to the problem will not in general
satisfy the equality constraint system exactly.

The solution is to use a tool that will restrict the
solution to the linear subspace of solutions that
exactly satisfies the equality constraint system.
lsqlin from the optimization toolbox is the tool
of first choice here, if you have that toolbox.
Alternatively, you can use other tools found on
the file exchange. My own lse is written to solve
exactly this problem, a linear least squares, subject
to linear equality constraints.

http://www.mathworks.com/matlabcentral/fileexchange/13835

Use of lse is simple here. Given the matrix system
to be satisfied, A*x = b, I'll assume that you wish
to constrain variables 1 and 4 to be equal, as well
as the pair 2 and 5. Simply form the matrices

C = [1 0 0 -1 0;0 1 0 0 -1];
d = [0;0];

(This assumes a total of 5 variables to solve for.)
Solve it using lse:

x = lse(A,b,C,d);

I also show how to write such a code in my tips
and tricks document, there using a qr factorization
for the elimination (I think that was what I did,
without checking.) LSE offers two methods as
options to the user, which will have subtly different
results on singular systems.

http://www.mathworks.com/matlabcentral/fileexchange/8553

HTH,
John
.



Relevant Pages

  • Re: fmincon
    ... I'll check this option,but i don't absolutely understand one nuance: The constaints in fmincon are continuous functions,linear and not linear but continuous. ... The rectangles are alligned to axes so the code of calculating the intersection is o'k i guess. ... Excuse me for maybe stupid question: -A as sign to empty intersection is given to implement say constraint c< 0? ...
    (comp.soft-sys.matlab)
  • Re: A question regarding optimization theory
    ... 1)all the x1 ....x6 must be positive and non zero ... i know that it is going to be solved by non linear programming ..i ... doing right i need a type of algorithm in which the constraint ... no optimizer will allow you to apply a strict ...
    (comp.soft-sys.matlab)
  • Re: Solve non linear constraint optimization
    ... it be a linear system it would be probably easy to solve this ... constraint problem. ... , nor the constraint. ...
    (comp.soft-sys.matlab)
  • Re: Linear Equations Similar to 1D Poisson
    ... (Peter Spellucci) ... how to deal with a linear system with matrix ...  you write the coefficients of the linear equation on top of the matrix.. ... constraint when ATA is invertible, ...
    (sci.math.num-analysis)
  • Re: question regarding lsqnonlin function
    ... If its a single linear equality constraint, ... If they are only bound constraints, then lsqnonlin ...
    (comp.soft-sys.matlab)