0
$\begingroup$

I am trying to solve a seemingly simple problem, namely the correct extraction of a single solution from Solve, to use in a subsequent calculation.

my function is a boring piecewise linear one;

y[x_] := Piecewise[{{0, 
x < 8642}, {((0.42 - 0.14)/(
   53666 - 8652)) x + (0.14 - ((0.42 - 0.14)/(53666 - 8652)
      8652)), 8652 < x <= 53666}, {0.42, x > 53666}}, x]

From here I solve to a particular value

sol = Solve[(x - y[x] x)/12 == 3000, x]

my answer becomes

{{x -> 62069.}}

Now, after having read around a bit, using Values and the first value of sol...( namely sol[[1]] ), I can calculate value for a subsequent equation;

Values[sol[[1]]] - ein 12 /. ein -> 1000
{50069.}

All is great.

However, now wanting to put sol into my original equation, I get the following;

0 {62069.} < 8642
{0.472269} 8652 < {62069.} <= 53666
0.42 {62069.} > 53666
{62069.} True

My assumption being, Values is providing a list to the function, and it can't solve it....and it gives me the answer back as if i had simply put in "y[a1]". How can I extract a value from Solve correctly to use in more automated subsequent calculations?

Thanks

$\endgroup$

1 Answer 1

1
$\begingroup$

Work with rule for the solution

sol = First@Solve[(x - y[x] x)/12 == 3000, x]

(*   {x -> 62069.}   *)

x - ein 12 /. sol /. ein -> 1000

(*   50069.   *)

(x - y[x] x)/12 == 3000 /. sol

(*   True   *)

y[x] /. sol

(*   0.42   *)
$\endgroup$
1
  • $\begingroup$ Thanks! worked like a charm. $\endgroup$ Mar 25, 2018 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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