# How to use quantities obtained by solving equations directly to plot

I want to know how we could use the quantities we found by solving simultaneous equations, directly into plotting graphs. For example I have this Mathematica code; it gives the values of a and b but does not plot.

Clear[a, b]
Solve[{a + b == 30, 2*a + 3*b == 50}, {a, b}]
Plot[a*x + b*x, {x, 0, 10}]
• Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Jun 16, 2016 at 17:53
• You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this meta Q&A helpful Jun 16, 2016 at 17:53
• See (18393, ans. 18706) for advice. See also (3175), (6669). Jun 16, 2016 at 17:56

## 2 Answers

You'll want to do

sol = First@Solve[{a+b==20,2a+3b==50},{a,b}];
Plot[a x + b x/.sol,{x,0,10}]

Solve gives you a list of Rules. Here, there's just one such rule, but it's still wrapped in an "extra" set of braces because It's a list of rules. Use First@ (equivalent to wrapping the expression in First[]) to get the first element of that list, which is your desired Rule.

Using /. just lets you plug the rule from 'sol' into your equation; i.e. a x + b x /. sol = a x + b x /. {a->10,b->10} = 10x + 10x = 20x, which you can Plot.

• Thanks a lot Ben, it really works. Actually it was for a bigger project than that and really helpful, saved a lot of work for me. Jun 16, 2016 at 18:05
• Happy to help. Remember to search the documentation; it's extremely helpful! Be sure to read through this as well, as @Michael E2 suggested. Jun 16, 2016 at 18:09
sol = Solve[{a + b == 20, 2 a + 3 b == 50}, {a, b}]

{{a -> 10, b -> 10}}

point = {a, b} /. sol

{{10, 10}}

ContourPlot[{a + b == 20, 2 a + 3 b == 50}, {a, 0, 15}, {b, 0, 15},
Epilog -> {Red, PointSize[Large], Point@point}]