Hi everyone and welcome to finding limits using Python, we've seen lots of examples where we found limits algebraically using certain tricks or techniques. In this video, I'll show how to find limits three different ways. One is going to be using a graph to motivate where the limit's going to be. Remember this is not an exact way, we don't know if the actual number is a little above or a little below what the image looks like on the graph, but it's a good way to motivate what the number should be or verify some other results. We're going to look at finding the limit numerically using a table doing numerical approximation, same as before, not exact way, but again gets us very close and builds intuition. Then of course we're going to use Python's built-in functions to actually solve for the limit. Let's get started. The first thing we're going to do is find limits using a graph. We're going to use this SymPy library, so let's import it. From SymPy import everything and we're going to define a function to graph, so this will seem pretty familiar list to find x equals symbol x, where to use capital S on your symbol. Then we're going to define a function here, this one is a little weird with the Python code. We'd write it out algebraically, we're going to use square roots or raised to the 0.5, both are equivalent. We're going to say f equals and then parentheses here comes the numerator, 1 plus x, raise the 0.5 or square root, 1 plus x minus square root of 1 minus x. We get two square roots that are being subtracted from each other, that is the entire numerator, and then divide all of that by x. Now if you notice x is in the denominator, so we want limit as x goes to zero. Notice that I cannot substitute x in. If you do, you get a divide-by-zero error, so we're trying to find the limit, where does the function want to go? Is it even defined? Does it exist? Well, let's graph this and see what happens. From SymPy.plotting import the plot, and let's plot our function here we'll call the plot function the function name, which is f and then we do a tuple, which is the symbol or variable x comma, and then where we want to start and where we want to finish. Since we're interested in an area around zero, let's do minus 2-2, just some interval containing zero, we'll close up the function and we will hit Enter. Now it seems to me if I follow the coordinates with my mouse, then this graph wants to go as x approaches zero from the left, as x approaches zero from the right, this graph really wants to go to y equals 1. Again, don't get thrown off for the axis are, focus on the numbers that are showing in the bottom right corner. It seems from the graph that the limit is one. There's our first guess, there's our first hint at what the limit's going to be using a graph. When we find the limit numerically, we're going to need a bunch of values around zero, around the point that we're taking the limit of. If the limit were one, we use different values. Let's do a little bit to the left of zero and a little bit to the right. How about negative 0.1, negative 0.01, negative 0.001, and we'll do one more and that brings us closer to zero as we approach from the left. Now we go to the right, so how about 0.0001, 0.001, 0.01 and last but not least 0.1. We get further and further away, there's a list of x-values. We obviously could pick more or less or refine this list to get even closer, but this is good enough for what we want to do. Notice this is a list in Python and we want to find the y values of the function evaluated at this list, so we're going to do our f.subs , remember how this works. We take those symbol of the variable that we're using and then we introduce i as our index, and this will go through all values in our list, xval, so i in xval. Close up the brackets to make it match and hit Enter. Again, nothing happens but y-value is created. If you want to see the values, we're going to print yval and we get these numbers. Here's our list for plugging in the numbers and if you notice what's happening as you read from left to right, we are getting closer and closer to one. There's a lot of decimals here, it's a little tricky to see this is probably more decimal than anyone needs, so let's round these decimals. Let's create a new list called rounded yval, and the way this works is there's a built-in round function that we can use. We'll go through the list of yval, and we'll round it to four decimal places for no good reason. It'd be three, it could be five, you could do whatever you want here, we're going to round each entry for i in yval. Enter, all the variables are now rounded and we can print rounded yval. Now we can really see that this limit as I approach zero, as I move in from the left, I get to one, and then as I move away I get away from one. Again, this table, this numerical approximation is also hinting at the limit to be one. Now let's do it the exact way. This is exciting tool about Python, it has a built-in limit function. If I call L equal to the limit of f comma the symbol, and then where I'm taking the limit of, now remember we're going to as x approaches zero, so I plug in zero here. Remember all that algebra we did, remember all the tricks and techniques that you have to know. Yes, they're important, yes, it's important to be able to use those roles, but watch this. When one single line, I can then look at what L is and Python tells me that it's one. It does all these things for us and prints it. If you wanted one-sided limits, the way that that works is you can use the limit function. Let's do L_left, we'll do the function, we'll do x, we got to do zero again. But then you put in as a string a negative sign, which means from the left and you have L_left, let's print it just to see what it is, it's one. Remember in calculus if the limit exists, then the left and right limit will match to exposure you have to take left sided limits and for all the same reasons you could take right-sided limits, we should get back to one again without a problem. But sometimes they are different as you know, so I would just replace the minus in the string with the plus and I would see that I also get one again. If you wanted a one-sided limit, you can do that. Last but not least, just to show you another example, just to switch it up. We're going to do a limit at infinity and just to pick a very common example with limit at infinity, let's look at 1/x. You can think about what this graph is, if you want to pause the video here for a second to know what graph is, please do so so that you know we're talking about. So 1/x, we put the function in. Notice you don't have to define the function prior, you can do it right inside the limit command, which I forgot to type and I'll put it there now. We'll do limit of the function comma s, now we want to go to infinity. This is the third parameter, how do you put in infinity? Well, there's a class with the definition of infinity and you do s.infinity then you close it up. This is how Python knows to infinity, do not put it in as a text, you don't put it in anything else, use this. Again, think of the graph 1/x, think about the limit as I go to infinity, where does the function want to go? As x gets larger, 1/x gets smaller, so in the limit, this would want to go to zero, and if I print L, I get zero as well. You have a lot of power with Python to evaluate those for you graphically, numerically, and then absolutely using this built-in limit function, add up certain point at a finite value or at infinity. Feel free to use this to expand your knowledge on how to calculate limits. Excellent job on this video, will see you next time.