 We continue our look into this wonderful world of Sympi and let's have a look at doing some integrals. As per usual, I'm starting my first block of code in IPython notebook with importing Sympi and using the abbreviation SYM. I'm going to do one or two of these video lectures also referring to it in a different way. But we'll get to that for now. In this namespace, I'm just going to use the abbreviation SYM, meaning I still have to refer to it there, .init underscore printing, open and close parentheses, so I'm invoking pretty printing here and I'm setting X as a symbol, the variable X now becomes a symbol. So I'm going to print the definite integral and then here we have the printing of an integral itself. So it's capital I, and it says integral. Don't confuse it with integrate. We'll get to that. That's something different. So it's I want to do the sine function and because I've just imported Sympi as SYM in this fashion up here, I have to refer to Sympi in invoking the sine function. So it's SYM dot sine of X, comma with respect to X. And if it's an indefinite integral, I needn't put these parentheses here. I can just do that. But we'll see when we get to the definite integral. It's a good idea just to have those parentheses there. Let's run this block of code and is that not a thing of beauty? Lovely integral sine there, the sine of X with respect to X, this indefinite integral. Let's move on to the definite integral. Exactly the same thing. We're still going to have the sine of X and that's why I say get used to putting these parentheses after the comma here. So it's going to be with respect to X. That's the first argument and then your lower bound and your upper bound. Now I wanted to go to Pi. Pi is Pi, the value of Pi itself has to be invoked from Sympi itself. So you have to say Sympi dot Pi. Let's run this bit of code and learn, behold, the definite integral of going from 0 to Pi of the sine of X with respect to X. Lovely. As always there are two ways to do it. There's actually more than two ways. I'll just show you this do it. Do it, open and close parentheses, command at the end. So it's exactly the same. I'm just using the integral word there with the uppercase i and if we run this we're actually going to get the calculation. So the definite integral in going from 0 to Pi of the sine of X dx is 2 and we get our solution there. Perhaps the proper way of doing it is using this integrate keyword. There's a small lowercase i and it says integrate not integral. Don't get confused with those two. So it's still the sine of X and then my arguments after the comma here. So just look at the structure. There's open and close parentheses. There's my open and there's my close within that. I have two sets of code separated by a comma. Before the comma I have whatever my expression is. Here, there's the sine of X and comma and after that is my with respect to first argument the lower bound and the upper bound. So if I say integrate instead of integral and then having to put the dot do it at the end I can just do this and we're going to get the solution of 2 yet again. Remember I'm just printing out these strings just to make the notebook look good. So I have the print command there. I have to have these opening and close either single or double quotes and I'm saying print on the screen the solution to the different integral which is just then printed there with the solution. So I'm just making it look presentable. That's all I'm doing. Now let's move on to the integral requiring the product rule just to show you that Sympi is quite advanced. It can do quite a bit of integrals. There are one or two that are still outstanding. I'm sure the brain power behind Sympi is working on the issue. If it cannot do the integral it's just going to reprint that integral for you without actually calculating it. Remember this is capital I so it's not going to compute the solution for me. It's just going to do the pretty printing on the screen. So if I run this block of code I have now X squared times the sine of X. It's the product of two functions and just to show you Sympi has no problem in dealing with this and calculating it for you. So in this instance I'm using lowercase i the word integrate. So it's actually going to do the calculation for me with respect to X. So this is an indefinite integral and if I run that just be where it's going to give you the solution beautifully done but it's not going to have the plus c at the end even though this is an indefinite integral and you have to have a constant of integration here it is not added there so just be aware. Now the integral can also be done as there was the product of two functions we can also have the quotient one polynomial in the numerator polynomial denominator and what I've done here is I've got two variables one I've called NUM for numerator other one DEN I could call it anything I want except X because remember X is now not a variable anymore it is a symbol. So I've inverted this variable NUM and it's X squared plus four times X minus two X remember as with any Python I can't just write four X like that I've got to say four times X and I put the spaces in just so that it looks neat you needn't do that and of course we are going to follow the rules of arithmetic in other words the power is going to be done first and then the multiplication and division and then we're going to get the addition and subtraction so Python is clever enough to do that for you and then the denominator I'm just going to have three X plus two and and I'm going to just print out to the screen the numerator divided by the denominator so I needn't put the expressions in here itself and of course these parentheses that are put in here they just extraneous I don't really did not really need them okay there we go so it's just in the main parentheses there are two sets of code separated by the comma what comes before the comma it's just very simply your it's just very simply the expression that you want to integrate and with respect to what's with or without the bounds being a definite or indefinite integral if I run this code very beautifully rendered there I have my numerator I have my denominator and just to show you no problems then executing the code and and and giving you the solution to that integral one important thing to note we see the log there in Python that refers to the natural log not log base 10 it's log base e or the natural log just to show you a prove it to you there we have our last example I'm going to get the integral this is just printing the integral one over x the x I can run the code lo and behold there it is we're neatly done and the solution to that we all know should be the natural log the natural log of x so if it's written as log x there please note that refers to the natural log good