 In this video lecture, I just want to do a bit of fun algebra and we're going to solve for x. First of all, let's try and get the roots of polynomials. I'm going to import SMPI as my abbreviation SYM. I'm going to print to the screen using pretty printing. In other words, sym.init underscore printing, open and close parentheses. And I'm going to have my variables x, y and z separated by comma say as symbols. So it's sym dot symbols, open and close parentheses. And I have x, y and z in that order so that the variable x is the first listed there, becomes the first listed there, symbol x, etc. And you'll note one little difference from the code I used before, where as I put no commas there, as the arguments and the symbols section here, you can put commas, not going to make a difference. And I'm going to print to the screen the string, the equation, colon, and then on the next line, I'm going to have an equation, sym dot eq. It takes two arguments here. Before the comma, I have my expression x squared minus x, the comma, and then on the right-hand side, whatever I want, on the right-hand side of the equation, I put after the comma as the second argument. And if I run that code very beautifully, I have x squared minus x equals zero. So that's what the equation does. It takes the two arguments there, what is on the left-hand side, what's on the right-hand side of the equal sign. So I can get the roots of this equation. Just be careful. You have to convert the equation in your head, or on paper, just to an expression. In other words, you just got to have zero on the right-hand side so that all your variables and your constants are on the left-hand side. So I can only have x squared minus x. That's the expression. So it's sym dot solve is how to get the roots of an expression. So on the left-hand side of this comma, the first argument is my expression, x squared minus x. And on the right-hand side, I want what variable I want the roots for. I want the roots for variable x. So if I run this, I see indeed my roots are zero and one. And we know if we take out x, we're going to have x and then x minus one in brackets equaling zero. So x is either zero or x equals one. So that's quite correct there. So it will solve that. Here's another equation. I have x squared plus two, or it could have been, remember if I just had the equation, I could have had x squared equals negative two. But I've brought it all to the left-hand side now, so it's going to be pretty x squared plus two equals zero. And I can show you that somebody can do complex roots as well. So sym dot solve again to get the roots. I have x squared plus two, and I want the roots for x. So that'll be negative square root of two i. It'll be imaginary number i or square root of two i. So that works very well. I just want to show you here. So if this was negative two on this side, so if I just did that, it would do that for me, x squared minus two. But if I want the roots of that, I've got to take that minus two over to the other side so that I just have my expression, the homogeneous equation, in other words, it being equal to zero. So I have everything in my expression that was on the left-hand side here, and I want the roots for x. Let's factor something. This expression can be factorized. x squared minus four, let's just print it to the screen. I have x squared minus four, and if I want to factorize it, so I'm not looking for the roots, I'm just factorizing it. And the keyword for that is factor. So it's sym.factor, lower case f, x squared minus four, and if I print that, it will factorize it as x minus two and x plus two. So the opposite of factorization is simplification. So here again, I'm going to use this x minus two times x plus two, which is what we had up there. I'm just going to print it to the screen, and there I have x minus two, x plus two. So in the pretty printing, it just removes this multiplication sign, which I have to put in the code, but in the printing it's just going to do it the way that you used to do it on paper. And now instead of factor, I'm going to simplify. So sym.simplify, and then open and close parentheses, and I have x minus two times x plus two, and I have these parentheses here just so that I have the order of erythematical calculations just correct there. So if I do that, I'm going to simplify x minus two and x plus two back to x squared minus four. Now you might not say that is a simplification, but that's the way the key words for sym.i are if you want this multiplied out, you use the simplify, and if you want it to be written in a simpler form, meaning it's the x squared, the power there is broken down into first-order variables there, first-order polynomials, each one of these. The factors you use the factor keyword. So look at this very long expression here. xq plus x squared minus x minus one over x squared plus two x plus one, so quite a daunting both numerator and denominator polynomials in both. And if I use factor now, so what's factor going to do, remember it's going to expand these, but what it will also do, it will do cancellation all in one go. Let me show you. So I have sym.factor, I have my numerator, my denominator, exactly the same as up there, and if I run that code, I'm just going to be left with x minus one. The reason for that is let's just factorize the numerator. There I have the numerator, and I'm using factor. If I do that, I see it's x minus one and x plus one squared, and if I factorize the denominator, I have this, and lo and behold, this x plus one all squared and x plus one all squared are we're going to cancel out, and I'm left with x minus one. So it's not going to give you, when you use factor there, all of these factors, it's also going to do the cancellation for you. You can though have a list of all the factors. So if I use this keyword factor underscore list, and there again I am with my, with my same expression here that I had in my numerator before, if I ask for the factor list, now look what it does. It says there's an x minus one once. It appears once, the x minus one. The x plus one appears twice. Hence it was x plus one squared, all squared. And all of them combined just occur once. So I just have this one, two, three. I have these three factors, and they just appear once. If all of them were repeated, this would have been a two. So just carefully look at the way that this is constructed. This part here, x minus one is one of the factors, x plus one is one of the factors. This value after the comma tells me how many times that factor appears. The x plus one appears twice. And then both of them combined appear once. Now for one of the beauties of Sympi, and that's the, just relieving the pain of doing partial fractions. Always a pain, takes a while to do. Easy to make, tiny little mistakes when you do it on paper. And it's not to say that you should not have the skill to do any of these things on paper, but just to check your results, or in the real world, just to get the quick and dirty answer. I have this huge expression that I want the partial fractions of. 4x cubed plus 21x squared plus 10x plus 12 over x to the power of four plus 5x cubed plus 5x squared plus 4x. And the keyword for that is apart. sym dot apart, which is going to give me the partial fractions at the push of a button. Imagine all the paperwork that had to go into that. And boom, within milliseconds there is my solution. Is that not a thing of beauty? Now I can go backwards by simplifying this. Remember, simplifying is now going to find a common denominator and reconstruct this for me. I put this in here just to show you. So the code that I've put down here, my expression after the simplifier is exactly this. If I run that, it's not going to bring me back completely to what I had there. It was just going to have that x outside, but if I had distributed that x into this factor in the denominator, it was going to be exactly the same as that. So I can get the partial fractions beautifully and I can recombine them with a common denominator back into the original expression. Now I am not only stuck in some part just with one single equation. I can also solve, more than one occasion, a system of equations. Once again, I just wanted to warn you that you have to have everything on the left-hand side equal 0. So it's x plus y minus 1 equals 0. And my second is x minus y minus 1 equals 0. So I bought that minus 1 over from the right-hand side. That must have been x plus y equals 1 and y minus 1 equals 1, which you've got to bring it all to the side. They've got to equal 0. So you've got to have this homogeneous set of equations. So I'm solving the system, but just note slightly different syntax. I have my after-solve, which we've used before, for single expression solutions. I've got open and closed parentheses and I've got the two arguments separated by a comma, but they do have to go into square brackets. So I have my two expressions here from my two equations, comma, and again in square brackets, the two variables that I'm after. It's a system of solutions, and I want a solution for x and for y. So if I run that, I see x equals 1 and y equals 0. Just to show you, we can get a bit more complex. Remember, right in the beginning, I made the variable z a symbol z or z as well. So it's going to work here, and I have three of them. Still within the solve, I have my open and closed parentheses, but now I'm taking the two arguments still. My first argument goes in square brackets there, and there, comma, my second argument in square brackets there. You'll see I want solutions for x, y, and z. It's a system of three equations and three unknowns. So it's 3 times x plus 2y plus z minus 10. My second is x plus 2y plus 4z minus 12, and my last one is 2x plus 2y plus z minus 8. Lo and behold, it will do that system of equations. Solve that for me, x equals 2, y equals 1, z equals 2. If you were to put these values into these variables, you'll see all three expressions, they equal 0. So a beautiful way to do algebra and really simplifying your life or just to check your homework with. Beautiful.