0
$\begingroup$

Suppose I solve an equation y=Solve[x+3==8,x]

and I want to get the numerical value of y, how do I do that? I mean, if I want to work with my result and evaluate, for example y-2 it will not work, because y is not in the form of a number, but rather {{y->3}}. How can I convert it into a number?

Thanks

$\endgroup$
0
$\begingroup$

In:

(* #1 *)
Solve[x + 3 == 8, x] // Part[#, 1, 1, 2] &
(* #2 *)
Last @@ Last @@ Solve[x + 3 == 8, x] 
(* #3 *)
x /. # & @@ Solve[x + 3 == 8, x] 

Out:

5
5
5
$\endgroup$
  • 1
    $\begingroup$ Or y = Solve[x + 3 == 8, x][[1, 1, 2]] less typing :) $\endgroup$ – pfactors Apr 27 '17 at 18:15
  • $\begingroup$ Last @ Reduce[x + 3 == 8] $\endgroup$ – UnchartedWorks Apr 27 '17 at 18:30
  • $\begingroup$ No competition Uncharted, just pointing out that your first example can be shortened :) $\endgroup$ – pfactors Apr 27 '17 at 18:34
  • 1
    $\begingroup$ :) I know. It's just for fun. $\endgroup$ – UnchartedWorks Apr 27 '17 at 18:40
  • 1
    $\begingroup$ Okay then! Good to see someone with a passion for anonymous functions and the apply function, continue sir :) $\endgroup$ – pfactors Apr 27 '17 at 18:54

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