Message Boards Message Boards

0
|
5782 Views
|
2 Replies
|
0 Total Likes
View groups...
Share
Share this post:
GROUPS:

Turning Inequalities into Equalities/Equations

Posted 8 years ago

Given a set/list/array of inequalities- {2x >= y, 2z >= y, 2x+y <= 4, 2z+y <= 4}

I would like to be able to set certain equations equal. In this example, lets set equations 1 and 3 equal generating-

2x=y & 2x+y=4.

How can this be done? I would assume some how set the coefficients into a matrix. However, I am unsure how to do this.

Any help would be greatly appreciated.

POSTED BY: Conor Nelson
2 Replies

What about this?

eq = {2 x >= y, 2 z >= y, 2 x + y <= 4, 2 z + y <= 4}

FullForm@eq
(*List[GreaterEqual[Times[2,x],y],GreaterEqual[Times[2,z],y],LessEqual[Plus[Times[2,x],y],4],LessEqual[Plus[y,Times[2,z]],4]]*)
MapAt[(# /. {LessEqual :> Equal, GreaterEqual :> Equal}) &, eq, {{1}, {3}}]
(*{2 x == y, 2 z >= y, 2 x + y == 4, y + 2 z <= 4}*)
Posted 8 years ago

This is exactly what I needed. Thank you very much!

POSTED BY: Conor Nelson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract