0
$\begingroup$

I want to solve eqn for c0 in the following code. I want to do it with both replacement rules. I realize I could just use solve twice, once for subsCoke, and once for subsPepsi. I'm trying to do it in just one Solve to learn how to use Mathematica's functional style better.

eqn = c0/(c0 + cs) == Iunk/Is
subsCoke = {cO -> c0, cs -> 2, Iunk -> 0.3995, Is -> 0.7339};
subsPepsi = {c0 -> c0, cs -> 2, Iunk -> 0.3915, Is -> 0.7645};
Solve[eqn  /. {subsCoke, subsPepsi}, c0]
$\endgroup$
  • 1
    $\begingroup$ The usual way is to solve it once and then use the reprules: $\endgroup$ – Dr. belisarius Mar 3 '14 at 5:12
  • 1
    $\begingroup$ As in eqn = c0/(c0 + cs) == Iunk/Is; s = Solve[eqn, c0][[1]]; subsCoke = {cO -> c0, cs -> 2, Iunk -> 0.3995, Is -> 0.7339}; subsPepsi = {c0 -> c0, cs -> 2, Iunk -> 0.3915, Is -> 0.7645}; {s /. subsCoke, s /. subsPepsi} $\endgroup$ – Dr. belisarius Mar 3 '14 at 5:13
1
$\begingroup$

This is belisarius' comments combined into an answer

The usual way is to solve it once and then use the replacement rules:

eqn = c0/(c0 + cs) == Iunk/Is;
subsCoke = {cO -> c0, cs -> 2, Iunk -> 0.3995, Is -> 0.7339}; 
subsPepsi = {c0 -> c0, cs -> 2, Iunk -> 0.3915, Is -> 0.7645};

s = Solve[eqn, c0][[1]];
{s /. subsCoke, s /. subsPepsi}
{{c0 -> 2.38935}, {c0 -> 2.0992}}
$\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.