Re: Linear equation system with additional conditions
- From: "John D'Errico" <woodchips@xxxxxxxxxxxxxxxx>
- Date: Wed, 4 Mar 2009 12:16:01 +0000 (UTC)
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
.
- Follow-Ups:
- References:
- Linear equation system with additional conditions
- From: Thomas
- Re: Linear equation system with additional conditions
- From: Torsten Hennig
- Linear equation system with additional conditions
- Prev by Date: Re: 2 dimensional recurrence equation
- Next by Date: save figure in jpeg:prblem
- Previous by thread: Re: Linear equation system with additional conditions
- Next by thread: Re: Linear equation system with additional conditions
- Index(es):
Relevant Pages
|