0

I have some solve results stored in the ptes variable:

ptes = Solve[{x1, y1} \[Element] 
lin[alpha0, p1x0] && {x1, y1} \[Element] rec1, {x1, y1}]

{{x1 -> -80.0104, y1 -> -7.}, {x1 -> 0, y1 -> 0}}

I would like to store those 4 numbers into 4 different variables. I have been trying to access them in the following manner:

p1tes = Part[ptes, 1];
p2tes = Part[ptes, 2];

and then the single values

p1xtes = p1tes[[1]]
p1ytes = p1tes[[2]]
p2xtes = p2tes[[1]]
p2ytes = p2tes[[2]]

however now in these variables is stored something like

x1 -> -80.0104

I don't know how to store only the value, which I would need to perform some calculation afterward. I have tried reading some similar questions here, but for some reason they do not apply to my case

Thanks

saimon
  • 57
  • 5
  • 1
    To get the order of the variables right, start with sol = {x1,y1} /. ptes and then extract numbers from sol, for example with {p1x,p1y,p2x,p2y}=Flatten[sol]. See also https://mathematica.stackexchange.com/a/18706/26598 – Roman Apr 17 '19 at 08:14
  • @Roman thanks, this solved my issue. I'd like to mark the answer as solved, but it doesn't allow me to do so, I suspect it is because your is a comment and not an answer – saimon Apr 17 '19 at 09:13
  • Values@Solve[(y^2 + x^2) == 25 && x + y == 7, {x, y}] Use Flatten if you need. – OkkesDulgerci Apr 17 '19 at 12:10

1 Answers1

2

Let's take a simple example

Solve[(y^2 + x^2) == 25 && x + y == 7, {x, y}]

{{x -> 3, y -> 4}, {x -> 4, y -> 3}}

What you are looking for is

{x, y} /. Solve[(y^2 + x^2) == 25 && x + y == 7, {x, y}]

{{3, 4}, {4, 3}}

which you can save in a variable.

Sumit
  • 15,912
  • 2
  • 31
  • 73