Skip to main content
Tweeted twitter.com/StackMma/status/1344976672236449792
edited tags
Link
kglr
  • 400.5k
  • 18
  • 488
  • 929

extract values formfrom replacement list

added 79 characters in body
Source Link
sjdh
  • 7.8k
  • 5
  • 38
  • 48

Solve returns a list of replacement rules

In: Solve[x + y == 3 && x - y == 6, {x, y}]
Out: {{x -> 9/2, y -> -(3/2)}}

I am only interested in the right hand side of these rules. To extract the right hand side I use substitution:

({x, y} /. sol)[[1]]

It gives

{9/2, -(3/2)}

This works, but it is not very elegant. You have to adapt the list of the variables, each time you solve for different variables. Is there a more general way to extract the right hand sides form a list of replacements?

Edit The number of variables and the number of solutions may both differ.

Solve returns a list of replacement rules

In: Solve[x + y == 3 && x - y == 6, {x, y}]
Out: {{x -> 9/2, y -> -(3/2)}}

I am only interested in the right hand side of these rules. To extract the right hand side I use substitution:

({x, y} /. sol)[[1]]

It gives

{9/2, -(3/2)}

This works, but it is not very elegant. You have to adapt the list of the variables, each time you solve for different variables. Is there a more general way to extract the right hand sides form a list of replacements?

Solve returns a list of replacement rules

In: Solve[x + y == 3 && x - y == 6, {x, y}]
Out: {{x -> 9/2, y -> -(3/2)}}

I am only interested in the right hand side of these rules. To extract the right hand side I use substitution:

({x, y} /. sol)[[1]]

It gives

{9/2, -(3/2)}

This works, but it is not very elegant. You have to adapt the list of the variables, each time you solve for different variables. Is there a more general way to extract the right hand sides form a list of replacements?

Edit The number of variables and the number of solutions may both differ.

Source Link
sjdh
  • 7.8k
  • 5
  • 38
  • 48
Loading