 And so we're finally going to solve for x. So in this video lecture we're going to talk about isolating x, our single unknown variable, on one side of an equation. So this lecture is going to be all about equations and solving equations. Such an important skill and task in data science. So let's then talk about solving equations. One of the most useful skills that you can have in algebra. So first of all we have to define what we mean by an equation. What do we mean by an equation? When is something equation? Well we're going to say that it is a statement. And the statement is, you know, we can use symbols and numbers and we can write something down mathematically and that's a statement. In more advanced statistics you'll learn about statements being something that can be true or false. But for us we're just going to write a statement that equals or equates, let's say, that equates two expressions. So I'm going to have two expressions and I'm going to equate them with an equal symbol such that I have a left-hand side and I'm going to say that equals some right-hand side where both of these sides are going to be an expression. So there we go. There's our first definition for this lecture. We're going to have a left-hand side. We equate that by the equal symbol, the right-hand side. Please take note if you are learning how to use a computer language in a computer language. This is an assignment operator which is very different from using it in mathematics where we use a single equal sign. And we're going to have an aim and the aim is to find values for a variable that makes the statement true, that the left-hand side is indeed equal to the right-hand side. And so what we will have to do, and you might have heard this before, is we want to isolate the variable on one of the sides and usually we isolate that on the left-hand side. So let's have a look at a little example just to make these things concrete and here is my first equation. I have a left-hand side which is a variable and a right-hand side which is just a number, a constant. And when would this be true? Well it's true. Let's say it's true if x is indeed equal to two because then we have two equals two and that is something that is true. And so we can make the statement true by letting x equals two and that is the very simplest form because the solution is already written in the equation. So let's make things slightly more difficult and let's write something like x plus one equals two. Now we have a left-hand side and we have a right-hand side but our aim here is to find the value for the variable that makes this statement true. And an easy way to do that is we could see up here if we isolate the variable here on the one side usually the left-hand side and then it's easy if the right-hand side is just a number that we can read off the value of the variable that makes this equation true. Now to maintain equality we can consider doing something to the left-hand side and to the right-hand side as long as we do the same thing on each side if we do the same thing the equality stays. I want you to imagine a scale, an old-fashioned scale and you put weights on the one side and weights on the other side and it goes up and down. And for you to maintain that equilibrium you have to put weights of equal sizes or equal weights say I put 10 pounds, 10 pounds there as long as I do the same on both sides the scale stays in equilibrium and that's exactly what we're going to do here. So let's just put parentheses here on our left-hand side and let's put a parentheses on our right-hand side. So we have complete isolation of the left-hand side and the right-hand side and let's do something to both sides. And what I'm going to do is I'm going to subtract one so that's like taking my scales and taking one pound off but I also have to take it off on the other side to maintain the equilibrium of those scales. And now we can just read this out it's x plus one minus one and on the other side the right-hand side I have two minus one. Well plus one minus one is just zero so I have x plus zero on the side two minus one is one but x plus zero anything plus zero is just that one thing and I have solved for x. I have isolated x on my one side which happens to be the left-hand side and now that I've isolated it it's like the first example I can just read off the value so that when x equals one this equation holds true if I substitute so we have to talk about substitution. So if I now substitute this x equals one into that original equation here I would have one the substitute for x I substitute one because x is equal to one plus one equals two and indeed one plus one is two and two equals two and that is true. By doing what I do on the left-hand side what I do to the right-hand side if I do exactly the same thing I maintain that equality and I can use that to my advantage to isolate or solve for that unknown to solve for that variable and later on when you do these often enough what we'll usually talk about is just say that we've taken this to the other side and if you take it to the other side we swap the sign and look that's exactly what happens is as if I took this plus one away and I made it a negative one on the other side but behind the scenes the actual truth of the matter is that I do something on the left-hand side and I do something on the right-hand side it so happens that this plus one now disappears this plus one will disappear from the left-hand side I've turned it into a zero and that's what we mean by taking it over to the other side and swapping the sign so from a positive I'm going to go to a negative but hopefully you can see what we are actually doing to solve this equation let's do another example in this example I'm going to have 2x equals four and there are various ways that we can solve this by doing something to the left-hand side and to the right-hand side what we can do is have our left-hand side and we have our right-hand side and do exactly the same on each side and what I'm going to do on each side I'm going to divide each side by 2 now I've done what I've done on the left-hand side to what I've done on the right-hand side nothing has changed I do note that I have 2 divided by 2 there's a multiplication there not additional subtraction which allows me to cancel out those 2s because 2 divided by 2 times x that's exactly what I have there 2 divided by 2 is 1 and that's equal to 1 times x which is just equal to x and that means cancelling those two out and 4 divided by 2 well that's just 2 so that all that's left behind on this side is x and all that's left behind on this side is 2 so the solution is 2 and again if I substitute substitute this value into this I'm going to have 2 and in the place of the x I substitute 2 equals 4 and indeed 4 equals 4 my statement is correct and x equals 2 is a solution to that equation now let's have a look if we could solve this in a different way let's have again 2x equals 4 and what about if I took the left-hand side there's my left-hand side and right-hand side and I multiply both sides by a half so I'm multiplying this side by a half and I'm multiplying that side by a half and 2 times a half or half times 2 that's just 1 times x that's just x equals and a half times 4 is just 2 so dividing by 2 multiplying by half that's exactly the same thing now we can make this more complicated look at this example now are we really having some fun x squared equals 4 how do we solve for that what number do we take such that we square it we get 4 well you might just be able to work that out in your head 2 if I take 2 and I square it 2 times 2 that equals 4 but hey hang on a minute if I take negative 2 times negative 2 negative times the negatives are positive 2 times 2 is 4 so there's actually two numbers that solve for this equation and again there's something we can do we can say we take the square root of both sides I'm taking the square root of x squared and I'm taking the square root of 4 now I just have to remember that there's a positive and a negative involved in some people will write positive and negative there on the left hand side I do remember that what I'm doing here is just using a fraction as my power those two things the square root there remember I have my index is 2 there's my index my radicand and here I have a whole radical and on this side well that's just going to be equal to 2 squared and I'm taking that to the power one half but it's easier to remember to do this it's actually plus or minus the square root of 4 I have to think about both the positive and the negative now two times a half is just one x to the power one is just x and on this side two times a half is just one to the to the power one is just two that's a two but what happens here is I do forget the positive and negative so definitely I have to think about if I take the square root that I do have to think about the positive and negative because both positive 2 and negative 2 are solutions to this equation 2 squared is 4 4 equals 4 that's correct negative 2 times negative 2 is also 4 and 4 equals 4 and that's also correct so both 2 and negative 2 are solutions to this problem now let's have some more fun let's do a very difficult one let's have x divided by 11 and that's going to equal 33 how am I going to solve what value if I divided by 11 gives me 33 once again what I do on the left hand side I have to do on the right hand side and my aim is to isolate x how can I get rid of this 11 well if I multiply both sides by 11 there's x over 11 my left hand side and I multiply the right hand side also by 11 I'm going to get the following if I look at this this is just 11 divided by 1 times x over 11 that's a multiplication which means these two cancel out it might as well be 11 over 11 times x and this is 1 times x exactly the same thing so my 11s are going to cancel and I'm just left with x on the side and now I just have to think 11 times 3 check on your calculator that's 363 and again now I can substitute 363 divided by 11 use your calculator or python you get 33 a solution to that equation now let's do it this way around let's have something like 11 over x equals 33 now immediately I know x is not equal to 0 because I cannot divide by 0 but what if I multiply both sides by x I'm multiplying by x on the left hand side and I'm multiplying by x on the right hand side I have changed nothing now again if I just look at this this is x divided by 1 times 11 divided by x there's a multiplication there which means x divided by x those two x cancel and I'm left with 11 on this side and this side I'm left with 33 x I have commutativity so x times 33 is the same as 33 times x and I have this now I have my variable on the right hand side it's customary to have it on the left hand side but I have an equation here so I can just rewrite this the other way around I can say 33x equals 11 there's no difference between these two statements now once again I can get rid of the 33 by multiplying both sides by 1 over 33 by multiply this remember this is just over 1 and on this side I also divide or multiply by let's have that as that is 33 and on the right hand side I have 11 and so that 33 and that 33 is going to cancel out so I'm left with x on its own on this side and on this side I'm left with 11 and 33 now can I simplify this yes of course I can let's look at the greatest common devices so let's do 11 just break it up and I'm going to take 33 and I'm going to break that up into its and by breaking up I mean factorizing as far as its prime constituents are concerned now here at 33 I can divide 33 not by 2 the smallest prime I'm going to have remainder I can divide it by 3 without the remainder then I'm left with 11 and 11 is prime on its own so there's an 11 if I look at 11 well that's just the prime number I can only divide it by 11 and so let's look at what is common between these two what is common between these two is of course the 11 is a common factor between both of them so the greatest common divisor between 11 and 33 is 11 and then 11 divided by 11 well that's just equal to 1 and 33 divided by 11 well that's just equal to 3 so if I divide both the numerator and denominator by my greatest common divisor which is 11 an actual fact what we're saying here is I'm taking my numerator and I'm dividing it by 11 and I'm taking my denominator and I'm dividing it by 11 I have not changed anything so 11 divided by 11 is just 1 33 divided by 11 is 3 so x equals a third I have simplified 11 over 33 to a third by considering what is the greatest common divisor between 11 and 33 what is the largest number that I can divide into 11 and into 33 without to remain there and indeed that number is 11 by considering this technique of prime factorization let's go for one more example let's use in this example mess make use of reciprocals now for reciprocals if I have something like a over b and b is not equal to 0 it's a reciprocal it's reciprocal as b over a such that when I multiply those two I get 1 and now a can also not be 0 so let's make use of an example let's have 4 over 5 x if I have 4 over 5 x and I'm going to let that equal 12 now there's different ways that I can go about this but let's use the reciprocal how can I get rid of this fourth so that I have x all on its own well let me take four fifths and multiplied by its reciprocal so on the left hand side I'm going to multiply by 5 over 4 and I still have 4 over 5 and I still have x as long as I also do that to this right hand side 5 over 4 times 12 so on both sides I've multiplied by 5 over 4 now I have 5 over 4 times 4 over 5 now if I just look at those two fractions multiply those by each other it's a multiplication so I can cancel the two fours and I can cancel the two fives which leaves me x on the side let's have a look at this if I have 5 over 4 I'm going to multiply that by 12 over 1 but I can write this as 5 over 4 times 12 can be written as 3 over 1 times 4 over 1 3 times 4 is 12 divided by 1 is just 12 so that's all the same and I noticed that I can cancel out the four the four in the numerator the four in the denominator leaving me with 15 so x equals 15 and that's making use of reciprocals to get rid of the coefficient as fast the x is concerned now let's do a much more difficult example and I love these difficult examples because once you can do these you can really solve for x and let's have three times now I'm going to make use of square brackets remember I told you in an earlier lecture I don't really care about PEMDAS I want to put things inside of parentheses brackets and braces to make clear what the order of erythematical operation is that I'm interested in so let's have 4x let's have plus 5 times x minus 2 and then add another 6 to that and that is going to equal 1 minus 2 times let's have 9 minus 2 times x minus 4 let's see if we can solve this immediately we see that we can do distribution and we can do distribution so let's do that now if I do this distribution I'm getting rid of these parentheses I'll have 5x minus 2 so these brackets are the only parentheses on this side and as I say I like to use parentheses brackets and braces in that order so if I get rid of these now those become my lowest order which for me is parentheses but you can use the notation that you're comfortable with so three times there's my 4x and I'm going to have positive 5x and I'm going to have negative 10 and I still have my positive 6 there same's going to happen on this side if I get rid of these now those are going to become my parentheses and I'm going to have 9 and then negative 2x negative 2 times x is negative 2x negative 2 times negative 4 well that gives me a positive 8 now let's simplify on this side I've got 4x plus 5x that gives me a 9x I've still got negative 10 there plus 6 and on this side I'm going to have 1 minus 2 times 9 plus 8 is 17 minus 2x now I can distribute this 3 and I can distribute this negative 2 9 times 3 is 27 times that x 3 times negative 30 is negative 30 and I still have my positive 6 and on this side I'm going to distribute the negative 2 negative 2 times 17 is negative 34 negative 2 times negative 2x gives me a positive 4x let's simplify I've got 27x on this side negative 30 plus 6 gives me a negative 24 and on the right hand side I have 1 minus 33 leaving me with negative 33 plus 4x now I want to get all my x's on one side so what can I do well I can take 27x minus 24 and let's subtract 4x on this side and on the right hand side I've got negative 33 plus 4x as long as I also subtracted on the other side so positive 4x minus 4x nothing gets left behind here 27x minus 4x leaves me with 23x minus 24 equals negative 33 on this side so how do I get the negative 24 to that side well I can just take the negative 24 make it positive 24 on the other side but let's do it the proper way 23x minus 24 I'm going to add 24 to this side and then I've got to add 24 to the side so I've got negative 24 plus 24 nothing left behind I've got 23x and that equals negative 33 plus 24 well that's a negative 9 how do I get rid of the 23 well I'm going to multiply both sides by 1 over 23 and I still have my 23 times x there and that's going to equal 1 over 23 times my negative 9 so the 23s are going to cancel so I'm left with x on this side equals negative 9 over 23 quite a difficult example but once you can do this you understand so much algebra so try that one for me let's do another one of these difficult examples they are really so much fun and as I say if you can do them you can do everything as far as solving for x is concerned with this kind of problem so let's have three times x minus 2 let's have all of that over 4 let's have all of this over 4 plus 1 half times 5x plus 2 and I'm going to equal that to 14x let's do plus 12 I'm going to divide that all by 8 and I'm going to add to that 7 can you isolate x on one side now this is really a difficult difficult problem so what I want to do is to rewrite my problem first of all here I can do distribution so in the numerator I'm going to get 3x minus 6 let's make that a clear 6 and I'm going to still divide that by 4 and I'm going to just rewrite this in the following way that's going to be 5x plus 2 all divided by 2 hopefully you can see that this and this is exactly the same thing I'm taking a half and multiplying it by 5x and a half multiplied by 2 that would be the exact same thing as taking 5x plus 2 and dividing it by 2 I'm just rewriting this in a different way let's do the same with the right hand side I've got 14x that'll be 14x plus 12 and I'm dividing that by 8 but I cannot add to that something that has different denominators so if I want this 7 over 1 to have a denominator of 8 I've got to multiply it by 1 but I'm not going to write 1 I'm going to say 8 over 8 that's still 1 I'm still taking 7 and I'm multiplying it by 1 and so nothing changes now 7 times 8 and the numerator gives me 56 and 1 times 8 is 8 so I have something that is the same as far as both denominators are concerned meaning I can add the two numerators now here I've got a similar problem I have to multiply by 2 over 2 so that I can get a 4 in the denominator here so let's see what this would look like this is still 3x minus 6 and I'm still dividing by 4 and now I'm adding I've got to distribute this 2 so 2 times 5x is going to give me 10x plus 2 times 2 is 4 and that's the numerator and then in the denominator I have 2 times 2 which is 4 and on the right hand side I can write everything over the same denominator so everything over the same denominator so I've got 14x plus 12 plus 56 now on this side I've got a common denominator as well which is 4 let's do this this is still going to be 3x minus 6 and there's a positive there so that's no problem 10x plus 4 and on this side I have to simplify things a little bit I've still got 14x and now I just have to do 12 plus 56 and that gives me 72 so I should say 6 plus 2 is an 8 and 5 plus 1 is 6 so 12 plus 56 gives me 68 there we go that's better and I'm dividing that by 8 now I've got two different denominators here it would be great if they are both the same and I can do that by multiplying the left hand side by 1 and I'm going to rewrite one as 2 over now I don't have to do that on the right hand side because if I multiply anything by 1 I'm just left with that one so I've really changed nothing on the left hand side so I don't have to change anything on the right hand side but now I've got to distribute this 2 into all of these but I see I can simplify things on the left hand side a little bit so before we do that let's simplify things I've got a 3x plus a 10x and of course that is going to leave me with something else that leaves me with a 13x and I've got negative 6 plus 4 that leaves me with a negative 2 so that's slightly simplified over 4 and on the right hand side I still have 14x plus 68 and I'm going to divide that by 8 so let's have a look at this I've got to distribute this 2 now and that leaves me with 26x minus 4 and 2 times 4 is 8 and that's equal to 14x plus 68 over 8 and now have a look at this I can go about looking at this as far as these 8s are concerned I can multiply both sides by 8 if I multiply both sides by 8 multiplied by 8 I can cancel out these 8s I can cancel out these 8s so I have 26x minus 4 equals 14x plus 68 and so let's subtract 14x from both sides 26x minus 4 minus 14x equals 14x plus 68 minus 14x and so 26x minus 14x leaves me with 12x minus 4 and on the right hand side 14x minus 14x those disappear and I've only got 68 so on this side I'm going to have 12x minus 4 I'm going to add 4 here such that I have 68 plus 4 on this side negative 4 positive 4 that leaves leaves me with 12x equals 72 and now I'm just going to divide both sides by 12 I can multiply by 1 over 12 or I can just divide both sides by 12 that's exactly the same thing and 12 12 those will cancel so that I have x on one side and then I have 72 over 12 and 72 divided by 12 check up on that that's equal to 6 so look at this beautiful problem play along with this problem see if you can do it there are more I can do this in a different way see if you can solve for x then go ahead and substitute 6 into there and make sure that your left hand side equals your right hand side now here I want to show you a couple of let's put that in inverted commas and call them a little some tricks let's sum up something like a b a let's say a divided by b and that's going to equal c divided by d how can I rewrite this well I've got different denominators on both sides and I can rewrite this by doing the following let's multiply both sides by the product of the two denominators so that means I'm going to multiply the left side by bd I still have a over b on the side and on the right hand side I multiply by bd and I still have c over d on the side now I can immediately see if this is over one and this is over one that the two b's will cancel out and I'm left with d times a I'm making use of the commutative property on addition so a d times a is just the same as a times d and on this side I see the d cancels and I have b times c bc and now look at that if I have something like a over b is equal to c over d that's exactly the same as ad equals bc so what I did is I multiplied both sides by d so if I multiply this by d the d's would cancel and I have a d up there and then I multiply both sides by b and so the b's would cancel out and I'm left with bc on that side so it's actually those two if I do that multiplication and I do this multiplication that's exactly where I ended up so remember that little trick if you see this I can just do this one multiplied by this one equals that one multiplied by that one is exactly the same thing and you can see where this comes from let's have some something else that we can eliminate let's have something like e times f and I'm going to divide that by say b and that's equal to e times g I'm going to divide that by d now we've had this before if we have something that's common in the denominator denominator we can cancel but also for the numerator and immediately you can see here well if I multiply both sides by one over e I multiply this by one over e it's not in the same order but the order doesn't matter I have the commutative property on multiplication when it comes to real numbers and now the e's are going to cancel the e's are going to cancel and I'm left with f over b equals g over d and I can remember this little trick that I have that if I have fd that is going to equal bg as simple as that so these are just nice neat little things that you can just remember it's quite easy to to use let's have an example of this let's have 3x minus 5 and I'm going to have let's do x plus 3 and I'm going to equal that to 24 over 15 and now you can think of the abcd so I'm going to multiply those two and I'm going to multiply these two so I'm going to be left with 15 3x minus 5 equals 24 and x plus 3 and 15 and 15 and 15 that's 45x minus 15 times 5 well 5 times 5 is 25 I'm going to carry the 2 that leaves me with a 7 and on this side I have 24x and plus 4 times 3 is 12 carry the 1 6 and that leaves me with a 7 plus 72 and now I can have 45x I can subtract 24x from both sides which leaves me with no x's on this side and it does remember that I have to do the 24x on this side and the same is going to go for these I'm going to add 75 to both sides and that's 72 plus 75 and now I can just have 45x which I'm going to subtract from that 24x that leaves me with 21x on this side and on the right hand side I have 72 and 75 that's 147 now I can just divide both sides by 21 which leaves me an x on this side and on this side 147 divided by 21 and if you do that with a calculator you'll see x equals 7 so you see how I can speed things up by not doing every single step now please only do this when you are comfortable with doing things step by step and you can start bringing in these little tricks it just shortens the number of steps that you have to do so I really want you to get to this stage where you can quickly mentally in your mind do this algebraic manipulation so why would I want to do this let's talk about solving formulas now that would just be one use case of algebraic manipulation so let's remember the area of a circle as pi times the radius squared the radius being half of the diameter what if I wanted to solve for r what if I give you the area of a circle and I want to know what is the radius well that'll be very simple I can take both sides and I can divide by pi so on this side I divide by pi and on this side I have pi r squared and I divide it by pi so my pies are going to cancel and I'm left with I'm just going to rewrite that on the other side r squared equals a divided by pi and now to get rid of that too I can just take you know do this to the power half and do this to the power one half but that would be exactly the same as taking the square root of r squared equals the square root of the area divided by pi and two times a half is this once I'm left with the radius all on its own equals the square root of the area divided by pi in this instance I'm only interested in the positive version of this because the radius of a circle we're always going to think of that as a positive radius so that was a very simple neat example but let's talk about something in data science in data science if we talk about a numerical variable that that is something that is a number and imagine I knew for a whole population what they you know the age of every person was let's make that age in years and such that I can calculate the mean age and the mean age or the mean of a numerical variable in a population we usually use the Greek symbol mu for that and that is a population mean population mean and the way that I'm going to do that is I'm just going to add up all the ages and divide by how many people I have now usually we don't know that we cannot know the age of everyone so what we would do is we take a representative sample from the population maybe I have a thousand people I can add a thousand numbers and divide by a thousand and then I get a sample mean which we usually denote as this but we usually want a sample mean to give us some clue as to what the value is in the population that's very useful that means I can go take a do a study I can take a representative unbiased randomly selected sample of people from the population and only work on that small little sample if I could calculate something like a mean of a numerical variable I can use this to be what we call a point estimate of what that should be it's very clear though this is not going to equal that because I'm not measuring that variable and each and every member of my population I'm only doing that for a sample so we're going to call this the sample mean so what we want from this what we want from this is that I have some lower bound and some upper bound I'm going to put that upper bound so we're going to have that x is less than the upper bound but it is more than the lower bound and so if we have these two bounds we're going to say we think and we usually we're going to express this as that is a confidence level and these are then going to this is then going to be my confidence interval how confident are we that you know this value is represent this value is representative of that and we say we are for instance 95 percent confident that this value is between these two bounds and there is a calculation for this we have x bar minus c times s over square root of n in a simple case and we have x bar plus c times s divided by so this multiplication multiplication square root of n and it's my sample standard deviation n is the sample size the number of subjects that I have and this is going to be my lower bound and this is going to be my upper bound and so that's how we would calculate these bounds if I knew what c was and what s and what n is I can calculate these bounds then in some textbooks we talk about the width and the width is the three simply going to be the upper bound minus the lower bound and so we're going to have x bar plus c times s over the square root of n minus x bar minus c s over the square root of n so you don't have to know anything about this to just follow along so let's distribute this negative there so I'll have x bar plus c s over the square root of n minus x bar now I'm going to have a positive c s divided by the square root of n this x bar make minus x bar cancels out and I have c s of n c s of a square root of n and if I add two of them I'm going to have that the width the width here well that's equal to twice c s divided by the square root of n and when I have this I can solve for anything so imagine I knew the width I knew s and I knew n I can definitely solve for c let's do that up here I'm just going to use w for width and say that's two c s divided by the square root of n let's solve for instance for c now how would I solve for c well I can immediately rewrite this on the other side let's get this on the left hand side s divided by the square root of n equals w now I can multiply both sides by a half and a half times two is just one so I'm left with c s divided by the square root of n equals w width divided by two and now I can make use of that reciprocal rule where I'm just going to multiply by the reciprocal which means everything here would cancel out and I'm left with c on its own and on the right hand side I have that reciprocal so I'm going to have the square root of n over s and then multiply by the width over two and you can rewrite this but now I can solve for c see we call the confidence coefficient and so I could solve for any one of these values if I knew the other so if you tell me the width the sample standard deviation and the number of subjects I can calculate c now usually that's not something that we would do but I might ask this in an exam question just to show that you understand some algebraic manipulation and now of course you do understand algebraic manipulation