Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

This question already has an answer here:

Let's say I solve a system:

Solve[{a == 3* c, b == 2 *a}, {a, b}]

and then want to see if the values found for a and b satisfy an inequality:

Reduce[a < 7 b]

What I would usually do is copy and paste by hand the result of the Solve[] to make it available to Reduce:

Solve[{a == 3* c, b == 2 *a}, {a, b}]
(output) {{a -> 3 c, b -> 6 c}}

a = 3 c;
b = 6 c;
Reduce[a < 7 b]

but there must be a better way to do this? I would also like all those variables (a,b and c) to stay local because I will have to solve a lot of similar equations with the same variable names on the same notebook and I wouldn't want the values to mix.

share|improve this question

marked as duplicate by halirutan, m_goldberg, Yves Klett, Artes, Sjoerd C. de Vries Jul 9 '13 at 13:49

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
{a, b} = {a, b} /. First@Solve[...] ? –  Öskå Jul 8 '13 at 16:00
    
Try First@Solve[{a == 3*c, b == 2*a}, {a, b}]; Reduce[(a < 7 b) /. %] –  PlatoManiac Jul 8 '13 at 16:05
    
@Öskå this would work but a and b are not local in this case. –  su1 Jul 8 '13 at 16:12
add comment

1 Answer

There is a reason why Solve returns a list of rules ;-)

sol = Solve[{a == 3*c, b == 2*a}, {a, b}]
Reduce[a < 7 b /. First[sol]]

To be a bit more verbose in my answer: a thing like a->b is called a Rule and it can be used to replace a with b in expressions. Hopefully, now it makes more sense to you why most solving or minimization routines return rules.

share|improve this answer
1  
but if I try that I get as output {c \[Element] Reals && 3 c < 42 c} which is not the same as the "normal" output c > 0 –  su1 Jul 8 '13 at 16:08
    
@su1 I think you want Reduce[a < 7 b /. sol] –  Mr.Wizard Jul 8 '13 at 16:11
    
@su1 I was to fast, but updated my answer. Of course you first want to replace the solution and then you want to reduce it. –  halirutan Jul 8 '13 at 16:14
    
@su1 Additionally, note that in this case it doesn't matter whether you leave out the First as MrWizard did in his comment. In general solve returns a list of solutions, thats why you get a double nested list. –  halirutan Jul 8 '13 at 16:16
1  
@su1 you are missing a ; in that line. Try: Module[{sol}, sol = Solve[{a == 3*c, b == 2*a}, {a, b}]; Reduce[a < 7 b /. sol]] or simply: Reduce[a < 7 b /. Solve[{a == 3*c, b == 2*a}, {a, b}]] –  Mr.Wizard Jul 8 '13 at 16:38
show 8 more comments

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