0
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ 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 mathematica.stackexchange.com/a/18706/26598 $\endgroup$ – Roman Apr 17 at 8:14
  • $\begingroup$ @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 $\endgroup$ – saimon Apr 17 at 9:13
  • $\begingroup$ Values@Solve[(y^2 + x^2) == 25 && x + y == 7, {x, y}] Use Flatten if you need. $\endgroup$ – OkkesDulgerci Apr 17 at 12:10
2
$\begingroup$

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.