ASantosRibeiro
ASantosRibeiro

Reputation: 1257

Linear systems of inequations

Ok so I have a systems with 6 inequations and 3 variables, and a point that may or may not solve this system. To check whether this point solves the inequations is straightforward, my problem is when it does not solve the inequations to find the closest point that does solve the problem.

I will present an example of such a system: Ax<=b

A=

[  C11,  C12,  C13]
[ -C21, -C22, -C23]
[  C31,  C32,  C33]
[ -C41, -C42, -C43]
[  C51,  C52,  C53]
[ -C61, -C62, -C63]

b=

[ Cb1]
[ Cb2]
[ Cb3]
[ Cb4]
[ Cb5]
[ Cb6]

Pxyz=

[  pX,  pY,  pZ]

Does Pxyz solve Ax<=B ?

if all(A*Pxyz<=b)
accept point
else
get the closest point to Pxyz (by Euclidean distance) that solves the system. How?
end

Upvotes: 1

Views: 206

Answers (1)

rozsasarpi
rozsasarpi

Reputation: 1641

EDIT: Try one of these (tested with a 2D problem):

Approach 1:

[Psol,fval,exitflag] = fmincon(@(Psol) norm(Pxyz-Psol), Pxyz, A, b)

Approach 2:

If I understand correctly, you have a constrained linear optimization problem, more specifically a constrained linear least-squares problem which can be solved using lsqlin. It would be something like this:

if all(A*Pxyz <= b)
  % accept point
else
  % get the closest point to Pxyz (by Euclidean distance) that solves the system
  C = eye(length(b));
  [Psolu, resnorm, residual, exitflag] = lsqlin(C, Pxyz, A, b);
end

Hope this helps to solve your problem.

Upvotes: 3

Related Questions