 Systems of linear equations arise naturally when scientists, engineers, or economists, or others of course, whenever they study flow of certain quantities through a network of some kind, for example, suppose an urban planner or maybe a traffic engineer is trying to monitor the patterns of traffic flow in certain grids of city streets, right? We monitor the cars going in, we monitor the cars going out and this information can help them as they do their city planning and such, or imagine an electrical engineer wants to calculate the current flow through some electrical circuits, or maybe an economist is trying to analyze the distribution of products from a manufacturer to consumer throughout a network of wholesalers or realtor retailers and the such, right? So for networks, the system of equations in play often involve hundreds or even thousands of variables and equations. This thing's quite the case. We're gonna look at just much smaller examples, but the basic idea here is that commonly in the sciences, you have conservation laws of some kind that the amount of things going in is equal to the amount of things going out and whenever you have a conservation law, balancing that conservation nearly always leads to setting up a system of linear equations. So in this video, I wanna do an example of that with balancing a chemical reaction. So imagine we have some chemical compounds that are coming together, they react with one another and then they produce some things. So basically you have some type of reactants that maybe come together and these can get really complicated of course, but let's just say we have just two reactants. We have two chemical compounds that react with each other and then they produce a product of some kind and for this example, we have two products. So we have a product plus a product. So the conservation law is that the number of atoms entering the system is gonna be the same as the number exiting the system. That is to say we have the same number of carbons from start to finish. We have the same number of hydrogens, the same number of oxygens or whatever elements are in play right here. And so for this simple example, I want you to consider this diagram that's on the screen. So our reactants are gonna be CH4. C here stands for carbon, H stands for hydrogen, O stands for oxygen, if you're not familiar with the chemical notation here. So CH4, this is your methane gas. O2, this is our standard oxygen molecule. These are reactants, they combine together to create carbon dioxide, CO2 and water, H2O. Now, trying to balance like well, how many molecules do we have on the left-hand side versus the right-hand side? It leads naturally to a system of linear equations for which basically we're gonna come up with a three vector that keeps track of how much carbon, how much hydrogen, how much oxygen is in the system from left to right. And then our variables here are gonna keep track of how many molecules we had of each thing. So X1 will keep track of how many molecules of methane did we have, X2 will keep track of how many molecules of oxygen, X3 will keep track of the number of molecules of CO2. And then lastly, X4 will be counting the number of molecules of water and play. And so with these variables and vectors in consideration, then this right here naturally leads to a vector equation. So we have X1 times, then let's read this here. We have one carbon for hydrogen's no oxygen. So that's our methane vector. Then we're gonna have an oxygen vector, which has no carbon or hydrogen, but it has two oxygen atoms there. And so that's the left-hand side. That's the reactant side, the product side. We then do it for CO2, carbon dioxide. We have X3 times, you have one carbon, no hydrogen, two oxygen. And you have then also the water and play here, for which you're gonna have X4 times no carbon, two hydrogen, one oxygen. And so when you see, when you compare these things, right? On the reactant side, all of the oxygen is from the oxygen molecule. Carbon and hydrogen are just together with the methane. But when then it's over, right? All of the carbon lives with the carbon dioxide, all of the hydrogen lives with the water, but then the oxygen got broke up into two places and such. And so if you just count, it's like, oh, I have two oxygen on the left, then you have three oxygen on the right. It can get a little bit confusing how to balance all these things, but this vector equation takes care of it naturally. And then so combining, you can, I should say, translating this vector equation into a system of equations, you get something like the following. You're gonna get X1 plus, well, zero X2. So I'll just actually leave it blank, I guess. Then on the right-hand side, just looking at the carbon, right? You're gonna get X3 and then no X4, right? So that's why I said earlier, all of the carbon from the methane is gonna end up with the carbon dioxide. But then what about the hydrogen, right? So you're gonna have four X1, looking at now the second entry, you have no X2. On the right-hand side, you have no X3, but then you're gonna have two times X4, like so. So again, like I said, all of the hydrogen, that was originally part of the methane, is gonna be part of the water when we're done. Finally, you'll get a third equation for the oxygen inside of this problem here, for which no oxygen came from the methane, all of the oxygen came from the oxygen molecule, so you get two X2. But on the right-hand side, you're gonna have two X3, and then you're gonna have one X4, like so. For which then, when we put in the standard form we do, we put all the variables on the one side, you're gonna get X1 minus X3 is equal to zero. You're gonna get four X1 minus two X4, that's equal to zero. And then you're gonna have two X2 minus two X3 minus X4 is equal to zero. And so then this final system of linear equations, we can see that it's, first of all, it's a homogeneous system of equations. We talked about that in the previous video. Homogeneous systems that you have zeros all on the right-hand side, they're always consistent. Now, of course, the trivial solution doesn't really tell you much. You're gonna, if you could put zero in for everything, like if you have no molecules whatsoever, that is a balanced equation, sort of silly, but that is a possibility. What else could there be? Well, notice this system of equations, this system of equations is under-determined. We have more variables than equations. We have three equations for variables. So what that tells us is there's at least one free variable in this system. And if you solve this system of equations, you in fact do get one free variable. Let's say that free variable is X1, the amount of methane in the system. And that kind of makes sense because it depends on how much stuff you want. You could, there's a reaction you could do where you have one mole of methane or two moles of methane. That's not a problem. That's a possibility. Is that free variable allows for that adjustment? You could have a larger or smaller quantity of methane in play here. But once we determine the number of methane, like one mole or two moles of methane, that will then force all the others to be what they are. So like if we have one mole of methane, then you're gonna have to have two moles of oxygen, one mole of carbon dioxide and two moles of water. Those other variables are dependent upon that. And so if we leave in the free variable, that gives us the general solution that dependent upon say the number of moles of methane, which you can do other variables could be the free variables if you want to. But we're then would write the general solution as, well, here's the list of the free variables. And then the dependent variables are combinations of the other ones. So like, for example, X1 and X3, they're the same. So however many moles of methane will be the number of carbon dioxide you have here. If you take the second equation divided by two, you see that the moles, the mole you have for methane will be half of the moles you get for X4. And then you can also ascertain that X2 and X4 are the same as well. And that's how one gets it without actually solving the system of equations. And so this was a pretty simple chemical reaction here, but for even more complicated chemical reactions, these linear systems come into play and thus solving those linear systems can help a chemist balance these chemical equations.