# How to automatically get {a,b,c} from {x -> a, y -> b, z -> c}? [duplicate]

I want to get the graphic of a 3D-straight line:

First:

Clear["Global*"];
FindInstance[1/4 (-1 + x) == -y == 1/3 (-2 - z), {x, y, z}, Reals, 2]

(*{{x -> 1/2, y -> 1/8, z -> -(13/8)}, {x -> 3/5, y -> 1/10,
z -> -(17/10)}}*)


Then the " x-> y-> z->" need to be deleted manually and get two point {1/2, 1/8, -(13/8)}, {3/5, 1/10, -(17/10)}.

Finally:

Graphics3D[InfiniteLine[{{1/2, 1/8, -(13/8)}, {3/5, 1/10, -(17/10)}}],
PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}, Axes -> True,
AspectRatio -> 1, AxesOrigin -> {0, 0, 0}, AxesLabel -> {x, y, z}]


How to combine these two pieces of code into one piece? Or, How to automatically get {a,b,c} from {x -> a, y -> b, z -> c}?

• You are looking for Values. Feb 17, 2022 at 1:45
• @MarcoB great. This is a 3rd way to do it. May be you can make this an answer also. We now only need 7 more ways to get to 10 :) Feb 17, 2022 at 1:54
• OK. Thank you. :-) @MarcoB Feb 17, 2022 at 2:03
• @Nasser an update: only three to reach your claimed number of alternatives
– user49048
Feb 17, 2022 at 2:51

There are probably many ways to do this. (in Mathematica, the rule of thumb is that there are at least 10 ways to do the same thing :)

But one way could be

Clear["Global*"];
sol = FindInstance[1/4 (-1 + x) == -y == 1/3 (-2 - z), {x, y, z},  Reals, 2];
pts = sol /. Rule[x_, y_] :> y;
Graphics3D[InfiniteLine[pts],
PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}, Axes -> True,
AspectRatio -> 1, AxesOrigin -> {0, 0, 0}, AxesLabel -> {x, y, z}]


• Thank you. :-) @Nasser Feb 17, 2022 at 2:04

If you want to get {a,b,c} from {x -> a, y -> b, z -> c} you should use Values:

In[10]:= Values[{x -> a, y -> b, z -> c}]

Out[10]= {a, b, c}


For what it's worth I only read the post title, so there may be some context I'm missing here.

sol = FindInstance[1/4 (-1 + x) == -y == 1/3 (-2 - z), {x, y, z},
Reals, 2];
{x,y,z}/.sol
sol[[;; , ;; , 2]]

• Thank you. :-) @cvgmt Feb 17, 2022 at 2:04

Another way would be

sol = FindInstance[1/4 (-1 + x) == -y == 1/3 (-2 - z), {x, y, z},
Reals, 2]

sol /. Rule[a_, b_] :> b


I am still a bit jealous of the amazing performance given by @cvgmt the other day, so the following also works:

sol = FindInstance[1/4 (-1 + x) == -y == 1/3 (-2 - z), {x, y, z},
Reals, 2]

Apply[#2 &, sol, {2}]


Another possible way to do it:

{Last @@@ sol[[1]], Last @@@ sol[[2]]}


One more

FoldList[#1 /. #2 &, {x, y, z}, sol][[2 ;; 3]]


Not a surprise that you can use Fold as well in the following manner

Table[Fold[#1 /. #2 &, {x, y, z}, sol[[i]]], {i, 1, 2}]