Message Boards Message Boards

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

How to store the solution of a equation system into a list?

Posted 10 years ago

a = x == 4 b = x == y^2 Solve[a && b, {x, y}]

has solution {{x -> 4, y -> -2}, {x -> 4, y -> 2}} How can I store {4,-2} and {4,2} into a list?

Thanks.

POSTED BY: steve ma
2 Replies
Posted 10 years ago

Hi Steve

Take a look at this example

eqn = Solve[4 x + 2 y == 28 && x > 0 && y > 0, {x, y}, 
  Integers]; p = {x, y} /. eqn

In[817]:= eqn

Out[817]= {{x -> 1, y -> 12}, {x -> 2, y -> 10}, {x -> 3, 
  y -> 8}, {x -> 4, y -> 6}, {x -> 5, y -> 4}, {x -> 6, y -> 2}}

In[818]:= p

  Out[818]= {{1, 12}, {2, 10}, {3, 8}, {4, 6}, {5, 4}, {6, 2}}
POSTED BY: Paul Cleary
Posted 10 years ago

Try

mylist = {x, y} /. Solve[a && b, {x, y}]

or

mylist = ReplaceAll[{x, y}, Solve[a && b, {x, y}]]

Perhaps unfortunately, the help/documentation page for ReplaceAll or /. don't show an example like this and assume the new user will be able to discover this.

POSTED BY: Bill Simpson
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