<<

Johanna M Debrecht Page | 1 Euler’s Method with Python Differential Equations

Lab Description In this lab, we are going to explore Euler’s method of solving first-order, initial value problem differential equations by writing a program in Python. You do not need to be an expert at Python, or even know the language yet to complete the lab. You also do not need to have python installed on your computer, but you will need access to the internet. All the code you need is contained in this document.

Remember, Euler’s method uses tangent lines and the Linear Approximation function from to approximate solutions to differential equations. The primary value of studying Euler’s method is pedagogical, as it is a good introduction to the ideas used in numerical integration of differential equations (DEs). However, it has limited use because of the error that increases with each step.

Euler’s Method Overview and Review Given a first-order, initial value problem of the form:

y′ = f( xy,) , yx( 00) = y,

we will build a program to approximate the solution using Euler’s method. To begin, we  need to decide over what interval xx0 , p we wish to find a solution. We will also need to decide how many points n within the interval that we wish to approximate. Thus, the lengths of our “steps” h will be given by

xx− h = p 0 . n −1 Johanna M Debrecht Page | 2

This will generate n evenly spaced points xx01, ,... xp , where xk = x0 +⋅ kh. Our goal is to

produce a table like the following, with the program filling in the yx( k ) values (similar to Table 2.6.1 or Table 2.6.2 on p. 78 of the textbook).

xy

xy00

x11 yx( )

x22 yx( ) 

xpp yx( )

Recall that the accuracy of Euler’s method improves if you make the “step” size h smaller; that is, if you take more points on the interval (increase n). The width of the interval will also affect the accuracy of the approximation. Larger intervals will be less accurate, so you would want to use more points on the interval.

We know that yx( 00) = y, which means that yx′( 0) = fxy( 00,.) Using the linear approximation function, (which is a tangent line approximation to the function), we can write

yx( ) ≈ yx( 0) + y′( x 000000)( x −=+ x) y f( x, y)( x − x), for all x close to x0 .

Hence, we can approximate that

yx( 1) ≈= y 1 Lx( 1) = yx( 0) + f( x 00, y)( x 1 − x 0) =+ y 0 hfx( 00, y).

Then, since yx( 11) ≈ y, we can substitute into the DE to get

yx′( 1) = fx( 1, yx( 1)) ≈ fx( 11 , y).

Therefore, the linear (tangent line) approximation function becomes

yx( ) ≈ yx( 1) + y′( x 111111)( x − x) ≈+ y f( x, y)( x − x), for all x close to x1.

Using the same process, we approximate that

yx( 2) ≈ yx( 1) + fxyx( 11, )( 2 −≈=+ x 1) y 2 y 1 fxyx( 11, )( 2 −=+ x 1) yhfxy 1( 11, ). Johanna M Debrecht Page | 3

In this fashion, we can find approximations for yx( kk) ≈ y, where the yk are defined recursively by the formula

yk+1 = y k + hf( x kk, y ).

The table of values produced in this way generates a list of points that approximate the solution to the DE. This is Euler’s method.

Coding Euler’s Method Using Python: Part 1

Step 1 SageMath is a free open-source mathematics software system licensed under the GPL (General Public License). Through it, you can get free access to python, (used in ), Octave, java, ++, fortran, SageMath, Julia, and others. Go to the following website and create an account https://cocalc.com (Collaborative Calculation in the Cloud).

Step 2 Click on the orange ball surrounded by the blue arcs on the upper left of your home page.

Click on “Create a New Project,” give it a title, then click on “Create Project.” When created, click on the title to open it.

Johanna M Debrecht Page | 4

Step 3 At the top, in the banner, you will see the following. Click on “New.”

Click on “Sage worksheet” in the first row, upper left.

You should now see something like the following.

Step 4 We will be writing our code in the big empty space, starting where you see the horizontal blue line. We need to load some software packages, written by others, to assist us in our calculations Johanna M Debrecht Page | 5

and graphing. For example, numpy is a library containing a vast number of routines for numerical calculation in python, and matplotlib contains packages for plotting and graphing. You will also need to put your name into the file. You can do that by enclosing it between triple quotation marks. Anything between triple quotation marks will be ignored by Python. (See Substep G for a note about quote marks.) For a single line comment, you can put a hashtag or # at the beginning of that one line.

Substep A Type in the following code:

Import Packages from External Libraries """Put Your Name Here""" import numpy as np from matplotlib import pyplot as plt

You should be able to copy/paste it in.

Substep B Now we need to enter some information about our initial value, the width of the interval, the number of data points we want approximated, and the size of our steps h. For the purposes of this lab, I am going to use the following DE as an example

y′ =+=0.1 y 0.4 xy2 , (2) 4.

Suppose we would like to approximate over the interval [2, 2.5] with n = 101. Then

x00=2, y = 4, xpp = 2.5, n = 101, and hxx =( −0) ( n −=1) 0.005. Type in the following code to

enter this information. Johanna M Debrecht Page | 6

Define Your Basic Values x0=2 y0=4 xp=2.5 n=101 step_h=(xp-x0)/(n-1)

Substep C In order to enter our x-values, we need to create a 101-tuple, or vector. The entries will be our x- values, [2.0, 2.005, 2.01, 2.015, , 2.5] . Enter the following code to define this vector.

Create a Vector of the x-Values x=np.linspace(x0,xp,n)

Substep D Now that we have coded our x-values, we need to code how to generate the y-values. We will have to create a place to store the y-values. We will use an array (an ordered list with only one row or only one column) with n entries all set to 0.0. Enter the following code to create an array for storing the y-values.

Create an Array for the y-Values y=np.zeros([n])

Substep E We are now ready to code the part that uses Euler’s method. We need to replace the entries in the y array (initially set to 0) with the approximations generated by Euler’s method. Since this is an iterative process, we will use what is called a for loop in programming. This will cause the computer to repeat the steps inside the for loop a specified number of times.

The first line in the following box resets the first entry in the y array to the value of y0 = 4. (Remember that we set this in the code already with y0=4 in Substep B.) Johanna M Debrecht Page | 7

The second line sets up a “dummy” variable to iterate for our for loop. Because the next line is indented (you must use a tab), then the variable will only be available for this level or one below it. When we move out of the tabbed area, it won’t apply any more. The tab is critical; this is how python knows what belongs to what. Everything that is indented after the for will be considered part of the loop until the first line that is not indented.

The next line sets the kth entry of our y array to be the value of the (k − 1)th entry of the y array added to h times the approximated value of the DE’s derivative. This line will input the approximated values of the solution to the DE into the y array, using Euler’s method.

Create a for loop y[0]=y0 for k in range(1,n): y[k]=y[k-1]+step_h*(0.1*(np.sqrt(y[k-1]))+0.4*(np.power(x[k-1],2)))

Substep F Since we have gone to all this trouble, we should definitely print out our results! We will use another for loop to print out our approximated values for the solution.

Print the Approximated Solution Values for k in range(n): print(x[k],y[k])

Substep G Finally, we want to make a graph of our result. We can use the plot function from matplotlib to do this (in the second line we called it in as plt).

Caution! Depending on the font you are using, python may not like your single and/or double quote marks. If you see the error in red (below the code in Plot the Solution), that is what happened. You can type them directly into the worksheet. (You may not have noticed, but if they were incorrect, they would have shown up as red in the code.) Johanna M Debrecht Page | 8

Plot the Solution plt.plot(x,y,’o’) plt.xlabel(“Value of x”) plt.ylabel(“Value of y”) plt.title(“Approximate Solution with Euler’s Method”) plt.show()

Let me guess—you fixed all the single and double quotes, but you still have an error. Did you notice that there is a single quote in “Euler’s?” If that one is curved, python will give you an error message. You have two choices: replace it with the ascii straight single quote or put a u just before the text string in the double quotes. The u will cause it to ignore any non-ascii characters and to print them as is. (The Unicode for the ascii double quote is x22 then hit Alt + x. The Unicode for the ascii single quote is x27.) See the second option in the next box.

Option to Print Non-ascii Code plt.title(u"Approximate Solution with Euler’s Method")

Step 5 It is finally time to run the code and see how precise your typing skills are!

Click the green arrow at the top left of the page that says “Run” to run your code.

Johanna M Debrecht Page | 9

Provided you have eliminated all of your typing errors, you should see something like the screenshots below.

Johanna M Debrecht Page | 10

Assigned Task 1 Now that you have a very basic program running Euler’s method in Python, use the program to approximate a solution to the following initial value problem. You will need to solve for the derivative first. You will also need to use the numpy command for sine, which is np.sin(),the division command, np.divide(a,b), which results in a/b, and the command for pi (i.e., π), np.pi. (Just FYI, Euler’s number e is np.e.)

2 π xy′ −= y xsin( x ), y − =0, 2

π over the interval − , 10 , with n = 101 again. 2

To make it easier to compute, you can copy and paste your code from the example below your output. When you want to run the “new code” with the task DE, highlight just those lines of code, then hit run. It will only run the selected code.

Coding Euler’s Method Using Python: Part 2 Now that we have a bit of experience coding with python, let us get a bit more information about the approximation with our code.

Step 1 The actual true solution to the DE in Assigned Task 1 is yxx= − cos . Highlight the code from Task 1, then copy and paste it below your results from Task 1. Insert the following code after the print command, but do NOT indent it. The plt.plot(x,y,’o’) command should follow this code.

Code to Print Actual Solution on Same Graph t=np.linspace(-np.divide(np.pi,2),10.,400) a = -t*(np.cos(t)) plt.plot(t, a, 'r-')

Johanna M Debrecht Page | 11

Step 2 Highlight the recopied and edited code, then hit run. The actual solution will be graphed with a red line. If you wish to graph the approximation with a line, you could change the ‘o’ in the plt.plot(x,y,’o’) command to a dash ‘-‘. Two dashes, ‘--’ will produce a dashed line.

Assigned Task 2 Answer the following questions. You may answer them in your worksheet between triple quotations, or you may use a separate Word file, but they should be typed. Please use complete sentences and fully explain your answers, as if you were giving a presentation at work.

1. How closely does your approximation fit the actual solution? Is it closer on the left side or the right side of the graphs, or neither? Why or why not?

2. Does the graph of the approximation get further away from the true graph at some points compared to others? If not, explain why not. If so, describe the shape of the graph where it is closer, and the shape of the graph when it is further away, then explain why you believe this is happening.

3. Now copy the code below the results for the approximation and the true solution and change the value of n to 201. Rerun the code. What changes do you observe when comparing the approximate solution to the true solution? Is this a better approximation or a worse approximation? Why?

4. What do you think would happen if you changed the value of n to 401? To 51?

Items to Turn In Turn in the following items in pdf form in class or in the class folder within the system.

1. The code for the example followed by its output.

2. The code for Task 1 followed by its output.

3. The code for Task 2 followed by its output, with n = 101.

4. The code for Task 2 followed by its output, with n = 201.

5. The typed, written answers to questions 1–5 in Task 2. Johanna M Debrecht Page | 12

The Complete Code for Task 2, n = 101 import numpy as np from matplotlib import pyplot as plt x0=-np.divide(np.pi,2) y0=0 xp=10 n=101 step_h=(xp-x0)/(n-1) x=np.linspace(x0,xp,n) y=np.zeros([n]) y[0]=y0 for k in range(1,n): y[k]=y[k-1]+step_h*(np.divide(y[k-1],x[k-1])+(x[k-1])*(np.sin(x[k-1]))) for k in range(n): print(x[k],y[k]) t=np.linspace(-np.divide(np.pi,2),10.,400) a = -t*(np.cos(t)) plt.plot(t, a, 'r-') plt.plot(x,y,'o') plt.xlabel("x-value") plt.ylabel("y-value") plt.title(u"Approximate Solution with Euler’s Method") plt.show() Application Lab - Mathematica Direction Fields and Solution Curves

Plotting Direction Fields (also called slope fields)

Let the differential equation (DE) be given by y’ = F(x, y), a function of two variables. Then, if a solution,

y = y(x), curve for the DE passes through the point (x0, y0), then it has to have a tangent line at that point of y’(x0) = f(x0, y0). Repeating this process over and over is what produces the direction field. At each point, a small portion of the tangent line is drawn. It’s a lot of work to do by hand, but simple for a CAS like Mathematica.

When you are also given an initial condition, you can plot a specific solution curve within the direction field.

The two basic commands for plotting solutions to ODEs (the direction fields) are VectorPlot and Stream- Plot. First, we have defined a function called F, which is a function of two variables, x and y, (hence the underscore after them). The colon equal defines a function. Notice in the command line for Vector Plot below that we have divided by the square root of one plus the functions squared. This results in our line segments being length one. If you take this out, the line segments will have different lengths. You could also use the magnitude of the to give a length of one: Sqrt[(F[{x, y}].F[{x, y}]).

The first entry in the curly brackets will always be a one because we are assuming that x is a function of itself, x(x). Then its derivative is, of course, 1.

The best way to get help in Mathematica is to click on the “Help” tab in the top banner. Select the first option in the drop-down menu, Documentation Center. When it opens, you can type in any command into the Search box, and find out what options there are for it. Ÿ You must be precise and perfect with punctuation, upper- and lowercase, etc.! Ÿ Items in red font are things you should replace with your particular values. Ÿ Mathematica likes to be told exactly what to do. If you type xy, it doesn’t know what to do. If you type x*y, it will multiply the variables. Ÿ If it starts with a capital letter, it is a command. Otherwise, it is just a string of text. Many commands also have an uppercase letter in the middle. Ÿ If you type e, Mathematica thinks it is Text, not the exponental function. The command for the constant e (Euler’s number) is uppercase, E. I find it easier to use the palette for the Basic Math Assistant, and to select it from the drop-down menu. Ÿ To type a text entry, click in between two sections, then hit Alt + 7. You can also select “Format” from the top banner, then “Style” from the drop-down menu, then “Text”. 2 Direction Fields Lab JMD.nb

Ÿ To “enter” a line, hold the shift key and hit “Enter.” F[x_, y_]:= x^2 - y^2 VectorPlot[ {1, F[x, y]}/Sqrt[1 + F[x, y]^2], {x, -4, 4}, {y, -4, 4}, VectorScale -> 0.02, VectorPoints -> Fine, VectorStyle -> “Segment”, PlotLegends -> “F(x, y)” ]

Here’s what is would look like in Mathematica, with its associated output, after you hit Shift + Enter to execute.

In[82]:= F x_, y_ := x^2 - y^2 VectorPlot @ 1, FD x, y Sqrt 1 + F x, y ^2 , x, -4@, 4 , y, -4, 4 , 8VectorScale@ D<-> 0.02@ , @ D D 8VectorPoints< 8-> Fine, < VectorStyle -> "Segment", PlotLegends ® "F x, y "

H L D4

2

Out[83]= 0 F x, y

H L

-2

-4

-4 -2 0 2 4

If you prefer to have arrows on you lineal elements, change VectorStyle from “Segment” to “Arrow.” (See new commands and output below.)

Be aware, however, that this is misleading. Arrows generally do NOT point in the direction of the solu- tion curve, which go in either direction.

Here’s what is would look like in Mathematica, with its associated output. If you prefer to have arrows on you lineal elements, change VectorStyle from “Segment” to “Arrow.” (See new commands and output below.) Direction Fields Lab JMD.nb 3 Be aware, however, that this is misleading. Arrows generally do NOT point in the direction of the solu- tion curve, which go in either direction.

Here’s what is would look like in Mathematica, with its associated output.

In[84]:= F x_, y_ := x^2 - y^2 VectorPlot @ 1, FD x, y Sqrt 1 + F x, y ^2 , x, -4@, 4 , y, -4, 4 , 8VectorScale@ D<-> 0.02@ , @ D D 8VectorPoints< 8-> Fine, < VectorStyle -> "Arrow", PlotLegends ® "F x, y with arrows"

H L D4

2

Out[85]= 0 F x, y with arrows

H L

-2

-4

-4 -2 0 2 4

Let’s reproduce the direction fields using StreamPlot. Notice that the code is the same, except the word “Stream” has been substituted for the word “Vector” below:

StreamPlot[ {1, F[x, y]}/Sqrt[1 + F[x, y]^2], {x, -4, 4}, {y, -4, 4}, StreamScale -> 0.02, StreamPoints -> Fine, StreamStyle -> “Segment”, PlotLegends®”F(x, y)” ]

Here is what it would look like in Mathematica: 4 Direction Fields Lab JMD.nb

In[86]:= F x_, y_ := x^2 - y^2 StreamPlot @ 1, FD x, y Sqrt 1 + F x, y ^2 , x, -4@, 4 , y, -4, 4 , StreamScale8 @ D<-> 0.02@ , @ D D StreamPoints8 < 8-> Fine, < StreamStyle -> "Segment", PlotLegends ® "F x, y "

H L D4

2

Out[87]= 0 F x, y

H L

-2

-4

-4 -2 0 2 4

We can change them to arrows if we like. I increased the scale to help them show up better. Here is the code for that:

StreamPlot[ {1, F[x, y]}/Sqrt[1 + F[x, y]^2], {x, -4, 4}, {y, -4, 4}, StreamScale -> 0.04, StreamPoints -> Fine, StreamStyle -> “Arrow”, PlotLegends®”#1 F(x, y) with arrows” ]

Here is what it would look like in Mathematica: Direction Fields Lab JMD.nb 5

In[89]:= StreamPlot 1, F x, y Sqrt 1 + F x, y ^2 , x, -4@, 4 , y, -4, 4 , 8StreamScale@ D<®0.04 @ @ D D StreamPoints8 < 8-> Fine, < StreamStyle -> "Arrow", PlotLegends ® "ð1 F x, y with arrows"

H L D 4

2

Out[89]= 0 ð1 F x, y with arrows

H L

-2

-4

-4 -2 0 2 4

Assigned Tasks Part I.

For the DEs below, first produce a direction field with line segments instead of arrows, using the Vector- Plot command. You will want to choose names for the functions, such as F, G, or H. Be sure to change the names (F, G, etc.) inside the commands. You may produce these one at a time or all at once.

Then reproduce the direction field using the StreamPlot command. This time, keep the arrows. Play around with the scale, points and style until you are happy with your pictures. You may produce these one at a time or all at once.

You should end up with 8 graphs. Be sure to label them appropriately so I know which one is which (e.g., “#1 F(x, y) with VectorPlot”). 1. y ' x = x - y 2. y ' x = y2 - xy + 2 x H L H L 6 Direction Fields Lab JMD.nb

2 3. y ' x = - y x2 4. y ' x = y3 - x3 H L

H L Finding Solutions to DEs

Finding Solutions to DEs Analytically (algebraically)

Not all DEs have solutions that can be found algebraically. If they can, however, Mathematica can do the work for you. You will use the “DSolve” command. If Mathematica cannot find the general solution analytically, it will simply echo the input.

Usually, it is best to define your DE equation separately, so you don’t have to change it as often in the code. The command below establishes a new equation called “de” that has the value given. (We could have used this in the beginning to define “F[x_,y_]”.)

de = y’[x] ==x

Here’s what is would look like in Mathematica, with its associated output. If y appears in the equation, it must be followed by x in square brackets to indicate that y is a function of x. Otherwise, you will get an error message like the one in orange below when you try to execute the DSolve command.

DSolve::dvnoarg : The function y appears with no arguments. ‡

de = y' x == x y¢ x Š x @ D Now@ D we will define a new function to identify the solution equation and call it “soln”.

soln = DSolve[de, y[x], x]

Here’s what is would look like in Mathematica, with its associated output.

soln = DSolve de, y x , x x2 y x ® +@C 1 @ D D 2 If: :y appears@ D in the@ DE,D>> be sure to put the argument “[x]” after the y, to properly define it. (It is a function of x, after all.)

2 In our current case, we got a general solution of y x ® x + C 1 . 2

We can define the general solution explicitly as a function@ D of x, @callingD it yg for general y, by taking the 2nd element of the 1st element of the 1st element of the nested list solution:

yg[x_] = soln[[1, 1, 2]]

Here’s what is would look like in Mathematica, with its associated output. If y appears in the DE, be sure to put the argument “[x]” after the y, to properly define it. (It is a function of x, after all.)

2 In our current case, we got a general solution of y x ® x + C 1 . 2

We can define the general solution explicitly as a function@ D of x, @callingD it yg for general y, by taking the 2nd element of the 1st element of the 1st element of the nested list solution: Direction Fields Lab JMD.nb 7

yg[x_] = soln[[1, 1, 2]]

Here’s what is would look like in Mathematica, with its associated output.

yg x_ = soln 1, 1, 2 x2 @+ CD1 @@ DD 2 We can@ checkD that this solution is correct by evaluating the following command. The “/.” command is the ReplaceAll command to apply a rule or list of rules after the command to the expression before the command:

de /. y -> yg

Here’s what is would look like in Mathematica, with its associated output.

de . y ® yg True 

Assigned Tasks Part II.

For your four DEs given in Part I., look for the analytical solution using the DSolve command by follow- ing the instructions below.

You should have four analytical solutions for Part II., as well as the answer to the questions in # 3 below. 1. Rename your DEs using de1, de2, de3, and de4. 2. Define their analytical solutions using the names soln1, soln2, soln3, and soln4. 3. Which of the four DEs have analytical solutions? Which ones do not? Here are the problems again, for convenience. y ' x = x - y IV y(0) = 1 y ' x = y2 - xy + 2 x IV y(-2) = 1 and y(1) = 2 H L y2 y ' x = - IV y(1) = 1 H L x2 y ' x = y3 - x3 IV y(1) = 0 or y(0) = 0 H L Finding specificH L solutions to IVPs analytically We can get a particular solution satisfying a given initial condition by specifying it in the DSolve com- mand as follows:

y1 = DSolve[{de, y[0]==0}, y[x], x]; y1=y1[[1, 1, 2]] // Simplify

Here’s what is would look like in Mathematica, with its associated output. 8 Direction Fields Lab JMD.nb

y1 = DSolve de, y 0 Š -3 , y x , x ; y1 = y1 1, 1, 2 Simplify 1 @8 @ D < @ D D -6 +@x@2 DD  2 Instead,I youM could use the general equation defined by yg and specify the constant value, as follows:

y2=yg[x] /. C[1] -> -3

Here’s what is would look like in Mathematica, with its associated output.

y2 = yg x . C 1 ® -3 x2 -3 + @ D  @ D 2

2 Of course, this is the same result as above, since 1 -6 + x2 = -3 + x . 2 2

Solution Curves for Known (algebraically orI analyticallyM derived) Solutions Once you have a solution to the DE, you can plot some solution curves in several different ways. Let’s ây 2 use a more interesting example than the previous function. The DE = x has a solution given by âx 1-y2 -x3 + 3 y - y3 = c. First, define the function G, then a new direction field. You will notice that I have given a name to the direction field plot for the function G, called “dirfieldplotG”. This will allow me to use the direction field later by referencing the name, without having to reproduce all the code.

G x_, y_ := x^2 1 - y^2 dirfieldplotG = VectorPlot @ 1, DG x, y  HSqrt 1 L+ G x, y ^2 , x, -4, 4 , y, -4, 4 @, 8VectorScale@ D< -> 0.02@ , @ D D 8VectorPoints< 8-> Fine, < VectorStyle -> "Segment", PlotLegends ® "new G x, y called dirfieldplotG"

H L Here’D s what is would look like in Mathematica, with its associated output.

In[240]:= G x_, y_ := x^2 1 - y^2

@ D  H L Direction Fields Lab JMD.nb 9

In[183]:= dirfieldplotG = VectorPlot 1, G x, y Sqrt 1 + G x, y ^2 , x, -4, 4 , y, -4, 4 @, 8VectorScale@ D< -> 0.02@ , @ D D 8VectorPoints< 8-> Fine, < VectorStyle -> "Segment", PlotLegends ® "new G x, y called dirfieldplotG"

H L D4

2

Out[183]= 0 new G x, y called dirfieldplotG

H L

-2

-4

-4 -2 0 2 4

Version 1 for producing solution curves. Ÿ Before the VectorPlot command, insert “Show[“. Ÿ After the final “]” after either “Arrow” or “Segment” in “VectorStyle”, insert a comma, followed by “Table[ContourPlot[-x3 + 3 y - y3 == c, {x, -4, 4}, {y, -4, 4}, ContourStyle -> {Red, Thick}], {c, {-4, -1, 1, 4}}]]”, where the general solution is input in the red section. Ÿ You can, of course, choose different min and max values, different values for c, and different colors and thicknesses. You would either need to type in the solution, which is not always practical, or use the “/.” command to replace y[x] with the particular solution (see Version 2). The command using the actual solution would be:

Show[dirfieldplotG, Table[ContourPlot[-x3 + 3 y - y3 == c, {x, -4, 4}, {y, -4, 4}, ContourStyle -> {Red, Thick}], {c, {-4, -1, 1, 4}}]]

Here’s what is would look like in Mathematica, with its associated output. 10 Direction Fields Lab JMD.nb

Show dirfieldplotG, Table ContourPlot -x3 + 3 y - y3 == c, x, -4, 4 , y, -4, 4 , ContourStyle ® Red, Thick , c, -4, -1, 1, 4 A A A 8 < 4 8 < 8

2

0

-2

-4

-4 -2 0 2 4

If you want the solution curves to be different colors, you can specify each curve.

Here’s what is would look like in Mathematica, with its associated output. I have also added labels for the different plots. Direction Fields Lab JMD.nb 11

In[221]:= Show dirfieldplotG, Table ContourPlot -x3 + 3 y - y3 Š -4, -x3 + 3 y - y3 Š -1, -x3 + 3 y - y3 Š 1, A -x3 + 3 y - y3 Š 4 , x, -4, 4 , y, -4, 4 , ContourStyle ® A A9 Red, Thick , Blue, Thick , Green, Thick , Magenta, Thick , = 8 < 8 < PlotLabel ® Style -x3 + 3 y - y3 Š -4, Red , Style -x3 + 3 y - y3 Š -1, Blue , 88 < 8 < 8 < 8 <

2

Out[221]= 0 new G x, y called dirfieldplotG

H L

-2

-4

-4 -2 0 2 4

Version 2 for producing solution curves Here is a way to give solution curves for values of c from -4 to 4, by 1s. That is, c = -4, c = -3,...c = 3, c = 4.

Show[dirfieldplotG,Plot[Evaluate[Table[y[x] /. soln5,{c,-4,4,1}]],{x,-4,4},PlotRange®All]]

Here’s what is would look like in Mathematica, with its associated output. 12 Direction Fields Lab JMD.nb

Show dirfieldplotG, Plot Evaluate Table y x . soln5, c, -4, 4, 1 , x, -4, 4 , PlotRange ® All, PlotStyle ® Thick @ @ @ @ @ D  8

2

0

-2

-4

-4 -2 0 2 4

Version 3 for producing solution curves for specific, given initial conditions. You can also graph particular values for c, by putting them in { }s following c.

Here’s what is would look like in Mathematica, with its associated output. Direction Fields Lab JMD.nb 13

Show dirfieldplotG, Plot Evaluate Table y x . soln5, c, -4, -1, 1, 4 , x, -4, 4 , PlotRange ® All, PlotStyle ® Red, Thick, Dashed @ @ @ @ @ D  8 8 <

2

0

-2

-4

-4 -2 0 2 4

Version 4 for producing solution curves for specific, given initial conditions when solving for C is not practical. If solving for the constant C is too difficult (for example, if the general solution is extremely long or complicated), then you can rerun the DSolve command, and specify the intial condition within it. Here is an example of that.

Suppose we know the initial condition for the graph G to be y -1 = 0, which in our case would result in C = 1. We will assign the new name “deNew” to be the DE. We will name the solution to this DE “solnNew1”. H L

Suppose we also want a solution curve for the initial condition y 1 = 0, which in our case would result in C = -1. We will assign the name “solnNew2” to this solution. The semi-colon suppresses output. H L 2 deNew = y' x == x 1- y x 2 solnNew1=DSolve[{deNew, y[-1] == 0}, y[x], x] H @ DL solnNew2=DSolve[{deNew,@ D y[1] == 0}, y[x], x]

x2 In[243]:= deNew = y' x == 1 - y x 2 @x2D ¢ Out[243]= y x Š H @ DL 1 - y x 2 @ D @ D 14 Direction Fields Lab JMD.nb

In[273]:= solnNew1 = DSolve deNew, y -1 == 0 , y x , x ; solnNew2 = DSolve deNew, y 1 == 0 , y x , x ; @8 @ D < @ D D DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution. ‡ @8 @ D < @ D D DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution. ‡

DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution. ‡

DSolve::bvnul : For some branches of the general solution, the given boundary conditions lead to an empty solution. ‡

Now we want to define a single curve to be each solution curve, one we will call “curveNew1” and the other “curveNew2”.

curveNew1 = Plot[y[x] /. solnNew,{x,-4,4},PlotRange®{{x,-4,4},{y,-4,4}},PlotStyle®Red]

In[269]:= Clear curveNew1, curveNew2 curveNew1 = Plot@y x . solnNew1, xD, -4, 4 , PlotRange ® Automatic, PlotStyle ® Red curveNew2 = Plot y x . solnNew2, x, -4, 4 , PlotRange ® All, PlotStyle ® Blue

@ @ D  8 1.0 < D @ @ D  8 < D

0.5

Out[270]= -1.0 -0.5 0.5 1.0

-0.5

-1.0

1.0

0.5

Out[271]= -1.0 -0.5 0.5 1.0

-0.5

-1.0

To plot the solution curves with the direction field, put them together into a single command,

Show[dirfieldplotG,curveNew1,curveNew2, PlotRange®{{-4,4},{-4,4}}] Direction Fields Lab JMD.nb 15

In[272]:= Show dirfieldplotG, curveNew1, curveNew2, PlotRange ® Automatic

4 @ D

2

Out[272]= 0 new G x, y called dirfieldplotG

H L

-2

-4

-4 -2 0 2 4

Mathematica is having trouble drawing the full solution curve because the general solution it found was far more complex than the solution I gave. Even with the initial condition, it does not have enough information to draw the full graph. For these curves, if we don’t know the simpler solution we are look- ing for, we can use a numerical solution to the DE instead.

Assigned Tasks Part III.

Only three of the DEs in Part II have analytical solutions, but one of them is so complicated that we will approximate its solution numerically. For the two DEs that had (simple) solutions (#1 and #3), produce solution curves for the given initial conditions below.

You should have two graphs for Part III.

1. Use Version 1 to produce the specific solution curve for problem # 1, y ' x = x - y, with the initial condition y 0 = 1. 1.1. You will need to solve for the value of C first, using the inital condition.H L H L 1.2. Label your plot with the solution curve, using the correct value of the constant C. Use the same color for the label that you used for the solution curve.

2 2. Use any version you prefer to produce the specific solution curves for problem # 3: y ' x = - y x2 with the initial condition y(1) = 1. 2.1. Do you think the solution curve produced is entirely accurate? Why or why not? H L

Finding solutions to DEs numerically (when they don’t have a known algebraic solution) 16 Direction Fields Lab JMD.nb

Finding solutions to DEs numerically (when they don’t have a known algebraic solution)

What if the DE does not have a known solution? That is, what if DSolve does not return a usable general function for the value of y(x)?

In this case, we need a numerical solution. Later this semester, we will learn a couple of methods for computing approximate solutions for DEs, but for now, we will again let Mathematica do the work for us. We will use the NDSolve command.

Let us begin from the beginning by defining a new function, deq. (If you have previously used this name, you need to Clear it first.)

Clear [deq] deq = y’[x] == x^2 - y[x]^2

Here’s what is would look like in Mathematica, with its associated output.

deq = y' x Š x^2 - y x ^2

y¢ x Š x2 - y x 2 @ D @ D We will again define a solution equation, soln1, for the numerical solution to the DE, after first clearing @ D @ D it. You can check if it’s cleared by reentering it, then hitting Shift + Enter. If it just returns it as a string of characters, it’s cleared.

Clear [soln1] soln1

Here’s what is would look like in Mathematica, with its associated output.

Clear soln1

soln1 @ D soln1

Now we define the solution value, using NDSolve.

soln1 = NDSolve[{deq, y[-2] == 1}, y[x], {x, -4, 4}]

Here’s what is would look like in Mathematica, with its associated output.

soln1 = NDSolve deq, y -2 Š 1 , y x , x, -4, 4 y x ® InterpolatingFunction -4., 4. , <> x @8 @ D < @ D 8

soln1 /. x -> 2

Here’s what is would look like in Mathematica, with its associated output. Direction Fields Lab JMD.nb 17

soln1 . x ® 2 y 2 ® 1.67044  88 @ D << Solution Curves for Numerical Solutions You can plot a single solution curve, using the Plot command.

Plot[y[x] /. soln1, {x, -4, 4}]

Here’s what is would look like in Mathematica, with its associated output. We have assigned the name “sCurve1” to this first solution curve. sCurve1 = Plot y x . soln1, x, -4, 4 , PlotStyle ® Red

4 @ @ D  8 < D

2

-4 -2 2 4

-2

-4

Similarly, we can define three other specific solutions, each with its own intial value, and associated solution curve. Here are the commands, with semi-colons to suppress some of the output.

In the next input command section, note that the graph of sCurve 3 had an asymptote in it, which required playing around with the range values of x to get an appropriate view of the solution curve. The range of the graph was controlled with the command, PlotRange. soln2 = NDSolve[{deq, y[3] == 0, y[x], {x, -4, 4}]; soln3 = NDSolve[{deq, y[0] == 2, y[x], {x, -4, 4}]; soln2 = NDSolve[{deq, y[0] == 0, y[x], {x, -4, 4}]; sCurve2 = Plot[y[x] /. soln2, {x, -4, 4}, PlotRange -> {{x, -4, 4}, {y, -4, 4}}] sCurve3 = Plot[y[x] /. soln3,{x, -1.3, 4}, PlotRange ® {{x, -4, 4}, {y, -4, 4}}] sCurve4 = Plot[y[x] /. soln4, {x, -4, 4}, PlotRange ® {{x, -4, 4}, {y, -4, 4}}]

Here’s what is would look like in Mathematica, with its associated output. 18 Direction Fields Lab JMD.nb

soln2 = NDSolve deq, y 3 Š 0 , y x , x, -4, 4 ; soln3 = NDSolve deq, y 0 Š 2 , y x , x, -4, 4 ; soln4 = NDSolve@8deq, y@0D Š 0<, y@xD, 8x, -4, 4 x, -4, 4 , y, -4, 4 is not All, 88 < 8 << D Full, Automatic, a positive machine number, or an appropriate list of range specifications. ‡ 88 < 8 << 4

2

-4 -2 2 4

-2

-4

InterpolatingFunction::dmval : Input value -1.29989 lies outside the range of data in the interpolating function. Extrapolation will be used. ‡

Plot::prng : Value8 of option< PlotRange -> x, -4, 4 , y, -4, 4 is not All, Full, Automatic, a positive machine number, or an appropriate list of range specifications. ‡ 88 < 8 <<

6

4

2

-1 1 2 3 4

-2

Why do you think the solution curve above has a vertical asymptote in it? Is this really part of the solu- tion curve? Direction Fields Lab JMD.nb 19

Plot::prng : Value of option PlotRange -> x, -4, 4 , y, -4, 4 is not All, Full, Automatic, a positive machine number, or an appropriate list of range specifications. ‡ 88 < 8 << 4

2

-4 -2 2 4

-2

-4

You can see from Mathematica’s responses (in orange), that we are, indeed, getting a numerical approxi- mation and that not all values will graph within the given x and y ranges. It is not able to compute values for everything in those ranges, so it approximates.

Now we can show the direction field, with the four solution curves, all at the same time, using the command Show.

Show[dirfieldplot,sCurve1,sCurve2,sCurve3,sCurve4, PlotRange®{{-4,4},{-4,4}}]

Here’s what is would look like in Mathematica, with its associated output. Note that Mathematica is incorrectly drawing the asymptote for the third solution curve. 20 Direction Fields Lab JMD.nb

Show dirfieldplot, sCurve1, sCurve2, sCurve3, sCurve4, PlotRange ® -4, 4 , -4, 4

4 @ 88 < 8 <

2

0

-2

-4 -4 -2 0 2 4

Assigned Tasks Part IV.

One of the DEs had no analytical solution (#4), and one of them had a very complicated general solu- tion (#2). Let’s approximate their solution for several given initial conditions. but one of them is so complicated that we will approximate its solution numerically.

1. Approximate the solution curves for problem #2 y ' x = y2 - xy + 2 x, with the initial conditions y -2 = 1 and y 1 = 2. You will need: 1.1. Two solutions and two solution curves. H L H L H L 1.2. Produce a graph of the direction field for the function in problem #2, with the two solution curves corresponding to the initial conditions on it. 1.3. Make one solution curve red and the other blue. 2. Approximate the solution curves for problem #4 y ' x = y3 - x3, with the initial condition y(1) = 0. Produce a graph of the direction field for the function in problem #4, with the solution curve corresponding to the initial condition on it. H L You should have two graphs for Part IV. How to use Mathematica

•Open Mathematica 8 by finding 8 under the programs submenu. •After it opens, click on “New Notebook.”

Ÿ This is where you’ll type the expressions you want Mathematica to compute, and it’s where it will produce its results. Ÿ Anything I want you to type into Mathematica, I’ll use this color font. Type it in exactly as it appears. Ÿ Let’s play. Type in 2+2 then press ENTER or RETURN while holding down the SHIFT key. The SHIFT key tells Mathematica that it has something to compute. If you don’t hold it down, it interprets what you entered as text. 2 + 2

4

Ÿ You should have gotten something like you see above. Let’s play some more. Enter 3-5 4*8 4 8 7^2 1/3 You can hit ENTER after each line. On the final line, after 1/3, hit SHIFT + ENTER.

Ÿ Notice that Mathematica automatically interprets a blank space between 2 numbers as multiplication. 3 - 5 4 * 8 4 ´ 8 7^2 1 3 -2  32

32

49

1 3 2 Lesson-1.nb

Ÿ Mathematica also tries to use exact values whenever possible. If you want a decimal approximation, you have several options. Ÿ enter any part of the calculation to be done with a decimal point somewhere. Type 1/3. 1 3.

0.333333  Ÿ The presence of the decimal point indicates you want an approximation. Ÿ You can also use the N funtion in one of two ways: 1. type 1/3 //N . Both // marks are necessary. One / mark means division. 1 3 N

0.333333   2. type N[1/3]. N 1 3

0.333333 @  D Ÿ You can also go to the Palettes drop down menu at the top, and select Basic Math Assistant. Under Basic Commands, on the x button, you will find Numeric Functions. The N function is the first one listed. You can have more than one Palette open at a time. You’ll find almost all the functions you’ll need here as well. Ÿ Just for fun, let’s ask Mathematica to calculate a googol. Type 10^100 10^100

10 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 000 „ 000 000 000 000 000 000 000 000 Ÿ And a googolplex? Type 10^googol or 10^(10^100) 10^ 10^100

GeneralH ::ovfl : OverflowL occurred in computation. ‡ Overflow

@D Lesson-1.nb 3

Ÿ You should have gotten an error message. Something along the lines of An error occurs because the result is larger than the value of $MaxNumber on this computer:

Mathematica has a specialized language to instruct how and what it is you want to compute. With Mathematica 8, however, you no longer have to learn it. You can use the Palettes to enter functions, or you can use what’s called Free Form entry. That’s where Mathematica tries to guess what you want it to do.

We aren’t going to do anything so advanced that you’ll need to learn the language, but you can, if you like!

Language Pitfalls

Ÿ Under the Help menu (at the top of the screen), the first option is called the Documentation Center. If you click on that, you can find “Getting Started” videos, open a virtual book to search for a topic, or click on the topics to open the subtopics underneath them. This is a good place to go if you need help. Ÿ The Help menu also has a Find Selected Function option, which will help you find what Mathematica calls a particular function. Ÿ If you know the name of the function, but just need more information about it, precede it with a ?. ? Abs

Abs z gives the absolute value of the real or complex number z. ‡

? Plot@ D

Plot f , x, xmin, xmax generates a plot of f as a function of x from xmin to xmax.

Plot f1, f2, … , x, xmin, xmax plots several functions fi. ‡ @ 8

Ÿ Tricky points Ÿ Mathematica uses square brackets for the arguments of functions like sine or cosine, or the N function we saw earlier. Ÿ Arguments to trig functions are assumed to be in radians. Ÿ The square of trig functions, cos^2 (x) = (cosx)(cosx), is typed Cos[x]^2. The cosine of x squared would be typed Cos[x^2]. Ÿ Π can be found in the Basic Math Assistant, Basic Commands, Mathematical Constants. It can also be written Pi. (Note the capital P.) Ÿ Function names are always capitalized. Ÿ The log function is NOT base 10. You guessed it, it’s base e, the natural log. You can use other bases, but you have to let Mathematica know. Type in Log[5,125] or use the Palettes to do it. Log 5, 125

3 @ D Ÿ Euler’s number, e, is typed E. log E

log ã @ D

Ÿ Notice@ D that if you don’t capitalize log, you won’t get the correct response. Log E

1 @ D Ÿ The imaginary number, i, is written I.

Defining functions

Ÿ To define a function, you can use a colon equals := coupled with an underscore _ following the variable x. Type F[x_] := B Sin[x] F x_ := B Sin x

Ÿ Then@ D to evaluate,@ D type F[Pi/2] F Pi 2

B @  D Ÿ If you want to assign a value to B, you can. Just don’t forget to clear it when you’re done! You may forget, but Mathematica won’t. Headaches and hassles ensue. You can also clear all variables before you use them. B = 5

5

F Pi 2

5 @  D Clear B

@ D Lesson-1.nb 5

F Pi 2

B @  D

Helpful Hints

Ÿ Putting a semi-colon at the end of a line will suppress the output for that input. Ÿ You can stop the execution of a calculation by typing either ALT-Comma or COMMAND- Comma.

You try...

Ÿ Use Mathematica to find the value of ãiΠ.

Graphs

Ÿ Using free-form, you can tell Mathematica to graph sin(x). The default is the Mathematica language though, so you need to tell it you’re using free-form.

Click below the last line you see in your Notebook. See the small gray + sign?

Now click on that and choose Free-Form input. Or you can just start the line with an = sign.

Try both methods now.

1.0

0.5

-6 -4 -2 2 4 6

-0.5

-1.0 Ÿ What if you don’t like the domain interval used?

You don’t have to redo anything. Simply go to the output produced by Mathematica and change the interval to whatever you want.

Don’t forget to hit SHIFT + ENTER again to tell Mathematica to recompute. 6 Lesson-1.nb What if you don’t like the domain interval used?

You don’t have to redo anything. Simply go to the output produced by Mathematica and change the interval to whatever you want.

Don’t forget to hit SHIFT + ENTER again to tell Mathematica to recompute. Ÿ You will also find the Plot function on the Basic Math Assistant, Basic Commands, under the 2D button. It looks like Plot function , var , min , max .

Ÿ If you want to plot more than one function, separate them with commas. A 9 =E

14

12

10

8

6

4

2

-4 -2 2 4

You try....

x+2 x-1 Ÿ Use Mathematica to plot the function f(x) = for - 4 £ x £ 4, and - 10 £ y £ 20. Do you 3 x+2 x-3 I M I M think this a full and complete picture? Why or why not? I M I M

Ÿ Approximating Derivatives using the Difference Quotient: How accurate is it?

Let’s look at a particular function, f(x) = x3. Define f(x) in Mathematica by typing f[x_]:=x^3

In[23]:= f x_ := x^3

Ÿ Now@ D we’re going to define a new function, which we’ll name diffQuot, using f[x]. We’re going âf ' f x + Dx -f x f x + Dx -f x to use the Dx version of the Difference Quotient. = f x = limD ® » âx x 0 Dx Dx for Dx sufficiently small. H L H L H L H L f x + deltax - f x H L In[24]:= diffQuot x_ := deltax @ D @ D Ÿ Remember@ toD hit SHIFT+ENTER and to use square brackets [ ] and NOT the round parentheses. Ÿ Let’s use various values of Dx to see how close the difference quotient is to the derivative. We’ll plot f(x) and the approximation diffQuot on the same axes. Enter the commands you see below. You can use the Palettes or type it in directly.

In[25]:= deltax = 4; Plot f x , diffQuot x , x, -5, 5 , PlotStyle ® Red , Blue @8 @ D @ D< 8 < 150 88 < 8 <

100

50

Out[26]=

-4 -2 2 4

-50

-100 2 Lesson-2.nb

Ÿ The blue line is our approximation of the derivative. How accurate is it? Consider the slope of the tangent line on the actual function (red curve) at x = 0. The slope of the tangent line, the derivative, should be 0, but our approximation is giving a value between 10 and 20! Ÿ Try it again, but use deltax = 1. I’m going to reproduce all the code below, but you can simply return to your lines above, change the value of deltax to 1, and reexecute (SHIFT+ENTER).

In[27]:= deltax = 1; Plot f x , diffQuot x , x, -5, 5 , PlotStyle ® Red , Blue @8 @ D @ D< 8 < 88 < 8 <

50

Out[28]= -4 -2 2 4

-50

-100

Ÿ This approximation is better. Let’s try deltax = 0.005

In[29]:= deltax = .005; Plot f x , diffQuot x , x, -5, 5 , PlotStyle ® Red , Blue @8 @ D @ D< 8 < 88 < 8 <

50

Out[30]= -4 -2 2 4

-50

-100 Lesson-2.nb 3

Ÿ Using our Rules for Derivatives, we can calculate that âf = â (x3) = 3x2. Let’s graph the actual âx âx derivative on the same graph, but we’ll turn its curve green.

In[31]:= deltax = 4; Plot f x , diffQuot x , 3 x2 , x, -5, 5 , PlotStyle ® Red , Blue , Darker Green A9 @ D @ D = 8 < 150 88 < 8 < 8 @ D<

100

50

Out[32]=

-4 -2 2 4

-50

-100

Ÿ With a deltax of 4, we can see that our approximation to the derivative is not great. (Remember, the function is red, the approximation is blue, and now the real derivative function is green.)

Let’s do the same thing, but use deltax = 0.005.

In[33]:= deltax = .005; Plot f x , diffQuot x , 3 x2 , x, -5, 5 , PlotStyle ® Red , Blue , Darker Green A9 @ D @ D = 8 < 88 < 8 < 8 @ D<

50

Out[34]=

-4 -2 2 4

-50 4 Lesson-2.nb

Ÿ Now our approximation is very close. You can’t tell the difference between the blue and green curves unless you magnify the graph.

You try....

Ÿ This time, you will have something to turn in. 1. Define a new function f(x). 2. Graph f(x), the Difference Quotient approximation to f’ with deltax = 4, and the actual value of the derivative function on the same graph. Instead of the same scheme above, make the function a dashed line, the approximation a dotted line and the real derivative a thick line. You’ll find these under the 2D options, below Combining Graphic Objects, on the Directives drop down menu. 3. Repeat step 2 using deltax = 0.5. 4. Print out each graph above. 5. Repeat steps 1 - 4 for each of the functions below. 5.1. f(x) = x2(x - 1)(x + 4) 5.2. f(x) = 3x2 5.3. f(x) = (2x+3)(5x - 1)(3x + 11)

Ÿ I’ve worked the original example, f(x) = x3, below.

In[35]:= deltax = .5; Plot f x , diffQuot x , 3 x2 , x, -5, 5 , PlotStyle ® A9Red@ D, Dashed @, D Blue=, 8Dotted,

888 < 8 << 88 < 8 @ D<< 88 @ D< 8 <<

50

Out[36]=

-4 -2 2 4

-50 Let’s examine several curves and study their concavity and inflection points.

You try....

Ÿ Plot the following functions to turn in. 1. y(x) = 88x8+8x2+8

2. y(x) = x x -2x 3. y(x) = x + 3Sin 2 x 3 4. x2ãx A E 5. ln x 2+x (Remember, Mathematica uses log for the natural log, ln.) Ÿ Print out the previous 5 graphs. Use two different color highlighters to show the concavity of theH graphs.H LL For example, you might highlight all concave up sections in blue and all concave down sections in yellow. Label which color is used for concave up and which for concave down. (By sight) Ÿ Put an x on each inflection point on each of the five graphs. Some graphs may have more than one; some may have none.

Now let’s find the local minimums and local maximums.

Mathematica has two functions, FindMinimum and FindMaximum, for computing the extrema of curves.

We’ll use the following curve as an example:

f(x) = x5-9x3-x2+9

f x_ := x5 - 9 x3 - x2 + 9

@ D Let’s examine several curves and study their concavity and inflection points.

You try....

Ÿ Plot the following functions to turn in. 1. y(x) = 88x8+8x2+8

2. y(x) = x x -2x 3. y(x) = x + 3Sin 2 x 3 4. x2ãx A E 5. ln x 2+x (Remember, Mathematica uses log for the natural log, ln.) Ÿ Print out the previous 5 graphs. Use two different color highlighters to show the concavity of theH graphs.H LL For example, you might highlight all concave up sections in blue and all concave down sections in yellow. Label which color is used for concave up and which for concave down. (By sight) Ÿ Put an x on each inflection point on each of the five graphs. Some graphs may have more than one; some may have none.

Now let’s find the local minimums and local maximums.

Mathematica has two functions, FindMinimum and FindMaximum, for computing the extrema of curves.

We’ll use the following curve as an example:

f(x) = x5-9x3-x2+9

f x_ := x5 - 9 x3 - x2 + 9

@ D 2 Lesson-3.nb

Plot f x , x, -5, 5 , PlotRange ® -50, 50

@ @ D 8 < 8

20

-4 -2 2 4

-20

-40

Ÿ To find a local minimum of f(x), we need to let Mathematica know where we would like it to start checking. By looking at the graph, it appears there is a minimum near x = 2.

Here is the form of the FindMinimum command

FindMinimum f , x, x0

searches for a local minimum in f , starting from the point x = x0. @ 8

-41.6597, x ® 2.35998 @ @ D 8

Ÿ 8There is a minimum8 value<< of y = - 41.6597ish when x = 2.35998ish.

It looks like there could be another minimum near x = 0. You could adjust the window to examine more closely, but what would Mathematica do if you just told it to find it? FindMinimum f x , x, -1

8.99817, x ® -0.0741496 @ @ D 8

8 8 << 2 Lesson-3.nb

Plot f x , x, -5, 5 , PlotRange ® -50, 50

@ @ D 8 < 8

20

-4 -2 2 4

-20

-40

Ÿ To find a local minimum of f(x), we need to let Mathematica know where we would like it to start checking. By looking at the graph, it appears there is a minimum near x = 2.

Here is the form of the FindMinimum command

FindMinimum f , x, x0

searches for a local minimum in f , starting from the point x = x0. @ 8

-41.6597, x ® 2.35998 @ @ D 8

Ÿ 8There is a minimum8 value<< of y = - 41.6597ish when x = 2.35998ish.

It looks like there could be another minimum near x = 0. You could adjust the window to examine more closely, but what would Mathematica do if you just told it to find it? FindMinimum f x , x, -1

8.99817, x ® -0.0741496 @ @ D 8

8 8 << Lesson-3.nb 3

Ÿ Yes, in fact there is another minimum. Note that adjusting the window (below) would have given the same result. Plot f x , x, -.5, .5 , PlotRange ® 8.75, 9.25

@ @ D 8 < 8

9.1

9.0

8.9

8.8

-0.4 -0.2 0.2 0.4 Ÿ Be careful when choosing an initial search value! Watch what happens when I choose poorly. FindMaximum f x , x, 0

FindMaximum::fmgz : Encountered a gradient that is effectively @ @ D 8

FindMaximum f x , x, 5 8 8 <<

FindMaximum::cvmit@ @ : DFailed8 to converge

Ÿ 9Mathematica is trying to find9 a finite value on a= function= whose limit is infinity. So choose wisely!

You try....

Ÿ Find the minima and for the following functions using Mathematica. Be sure you find them all. 1. y = x4-11x3+30 x2-10x+50 2. y = Sin x ãx, only for 0£x£3þ 3. x2ln(x + 1) @ D 4. x - sin2(x), only for - þ£x£þ Ÿ Print out your results with your commands. You will want to include a graph of the curve. Lesson-3.nb 3

Ÿ Yes, in fact there is another minimum. Note that adjusting the window (below) would have given the same result. Plot f x , x, -.5, .5 , PlotRange ® 8.75, 9.25

@ @ D 8 < 8

9.1

9.0

8.9

8.8

-0.4 -0.2 0.2 0.4 Ÿ Be careful when choosing an initial search value! Watch what happens when I choose poorly. FindMaximum f x , x, 0

FindMaximum::fmgz : Encountered a gradient that is effectively @ @ D 8

FindMaximum f x , x, 5 8 8 <<

FindMaximum::cvmit@ @ : DFailed8 to converge

Ÿ 9Mathematica is trying to find9 a finite value on a= function= whose limit is infinity. So choose wisely!

You try....

Ÿ Find the minima and maxima for the following functions using Mathematica. Be sure you find them all. 1. y = x4-11x3+30 x2-10x+50 2. y = Sin x ãx, only for 0£x£3þ 3. x2ln(x + 1) @ D 4. x - sin2(x), only for - þ£x£þ Ÿ Print out your results with your commands. You will want to include a graph of the curve. Lesson 5: Riemann Sums, the Lower, The Upper, the Midpoint

Mathematica is the ideal tool to use to calculate vast numbers of tedious, mathematical calculations. It definitely beats doing it by hand! Let’s use Mathematica to perform the left sum, right sum and midpoint Riemann sums of the function f(x)=x3ã-x, on the closed interval [0,8].

Since x3 and ã-x are both defined for all Reals, and both continuous and differentiable for all Reals, their product is as well.

First, let’s graph it, just to get a feel for the function.

graph f x =x^3E^-x for x = 0 to x=8 Plot H L

1.2

1.0

0.8

0.6

0.4

0.2

2 4 6 8

min max

We’re going to use the Table command to produce our table of values for these sums. The form of this command is

Table expr, i, imin, imax, di and you can list more than one expression by uses steps di. @ 8

The Grid command separates the expressions into a two or more column table.

Grid expr11, expr12, … , expr21, expr22, … , … is an object that formats with the exprij arranged in a two-dimensional@88 grid.< 8 <

First, we’ll use the left sum formula. In the left sum, xk = a + k - 1 Dx, provided the sum runs from k = 1 to k = n. H L For our function and interval, a = 0. Let’s define Dx as deltax, a, b, n and three functions corresponding to the left sum, right sum and the midpoint sum. First, to be safe, we clear all these “names.” 2 Lesson-5.nb

We’re going to use the Table command to produce our table of values for these sums. The form of this command is

Table expr, i, imin, imax, di and you can list more than one expression by uses steps di. @ 8

The Grid command separates the expressions into a two or more column table.

Grid expr11, expr12, … , expr21, expr22, … , …

is an object that formats with the exprij arranged in a two-dimensional@88 grid.< 8 <

First, we’ll use the left sum formula. In the left sum, xk = a + k - 1 Dx, provided the sum runs from k = 1 to k = n. H L For our function and interval, a = 0. Let’s define Dx as deltax, a, b, n and three functions corresponding to the left sum, right sum and the midpoint sum. First, to be safe, we clear all these “names.”

Clear f, deltax, leftsum, rightsum, midpointsum, a, b, n

@ D Now, after doing the algebra on separate paper, we define them.

f x_ := x^3 ãx a = 0 b@= 8D  n = 4 deltax = b - a n 0 H L  8

4

2

Remember that all the formulas for xk I’ve given you, assume that k will start at 1 and go to n. Lesson-5.nb 3

Remember that all the formulas for xk I’ve given you, assume that k will start at 1 and go to n.

Grid Table k, f a + deltax * k - 1 , k, 1, n

1 0 @ @8 @ H LD< 8

Now that we have our table of values, we’ll plot them using the rectangles.

We want our x values to range from 0 to 8, or a to b. Since we’ve already studied the actual graph, we know that a range of 0 to 1.5 will be sufficient for the y values.

We’re going to use another command, Rectangle, which will produce our rectangles. The form is

Graphics Rectangle primitives and directives , x max , y max or the form @8 @ 8

Rectangle x min , y min , x max , y max

Our minimum@8 y value< 8 is 0, since

Color directives specify the face colors of rectangles:

Table Graphics c, Rectangle , c, Red, Green, Blue, Yellow

@ @8 @D

yPlot = Plot f x , x, a, b , PlotRange ® 0, 1.5 , PlotStyle -> Red, Thick ; leftrectangles = Table Rectangle x, 0 , x + deltax, f x , x, a, b - deltax, deltax ; Show yPlot,@Graphics@ D 8 < 8 < 8

1.2

1.0

0.8

0.6

0.4

0.2

0 2 4 6 8 5.58059

Thus, our left Riemann sum gives an approximation of the area as 5.58059 square units.

We’ve done the hard work of defining everything and setting up our graphs so they are easy to interpret.

Now let’s just copy all the commands in each section by clicking on the appropriate brackets, ], on the right, copying (Ctrl + c), and pasting below (Ctrl + v), twice. Then we’ll change the definition of xk, and re-execute each line, once for the right sum and once for the midpoint sum.

First step: copy the commands.

yPlot = Plot f x , x, a, b , PlotRange ® 0, 1.5 , PlotStyle -> Red, Thick ; leftrectangles = Table Rectangle x, 0 , x + deltax, f x , x, a, b - deltax, deltax ; Show yPlot,@Graphics@ D 8 < 8 < 8

yPlot = Plot f x , x, a, b , PlotRange ® 0, 1.5 , PlotStyle -> Red, Thick ; leftrectangles = Table Rectangle x, 0 , x + deltax, f x , x, a, b - deltax, deltax ; Show yPlot,@Graphics@ D 8 < 8 < 8

Now change the first copied command, by changing the items highlighted in red below. yPlot = Plot f x , x, a, b , PlotRange ® 0, 1.5 , PlotStyle -> Red, Thick ; rightrectangles@ @ D= Table8 Rectangle< x, 0 , x + deltax, f x +deltax8 ,

Grid Table k, f@a + deltaxD * k , k,@1, nD

1 8 @ @ D 8

1. 1.08268 @ @8 @ H LD< 8

yPlot = Plot f x , x, a, b , PlotRange ® 0, 1.5 , PlotStyle -> Red, Thick ; rightrectangles = Table Rectangle@ @ D 8 x, 0 ,< x + deltax, f x8+ deltax< , x, a, b -8deltax, deltax

1.2

1.0

0.8

0.6

0.4

0.2

0 2 4 6 8 5.9241

Midpoint Riemann Sum

Now for the Midpoint. See if you can follow what I’ve done. Note that using 1/2 produces exact values, while .5 produces approximate ones.

Grid Table k, f a + deltax * k - 1 2 , k, 1, n

1 1 ã@ @8 @ H  LD< 8

1 0.367879 @ @8 @ H LD< 8

Make the following changes in red.

yPlot = Plot f x , x, a, b , PlotRange ® 0, 1.5 , PlotStyle -> Red, Thick ; midpointrectangles@ @ D 8= Table< Rectangle x8, 0 , Red, Thick ; midpointrectangles@ @ D 8= Table< Rectangle x8, 0 , Red, Thick ; midpointrectangles = Table Rectangle@ @ D 8 x, 0 ,< x + deltax, f x8+ .5 * deltax< , x, a8, b - deltax,

1.2

1.0

0.8

0.6

0.4

0.2

0 2 4 6 8 5.7343

Suppose I change the number of partitions (or boxes), n? Let’s let n = 16 and re-execute. (Remember, since deltax depends on n, and we’ve changed n, we must re-execute deltax as well.)

n = 16; deltax = b - a n 1 H L  2 8 Lesson-5.nb

Grid Table k, f a + deltax * k - 1 2 , k, 1, n Grid Table k, f a + deltax * k - 1 2 , k, 1, n N yPlot@ = Plot@8f x @, x, 0, b , HPlotRange LD<® 80, 1.5 <,DPlotStyleD -> Red, Thick ; midpointrectangles@ @8 @ = H  LD< 8

1.4

1.2

1.0

0.8

0.6

0.4

0.2

0 2 4 6 8 5.74641

You try....

Ÿ Use the examples above to approximate the area under the curve of f(x) = ã-x from x = 1 to x = 3 using Mathematica. Compute the left sum, right sum and midpoint sum using first n = 4, then n = 8, and then n = 16. 3 -x â 1. 1 e x Left Sum only: n = 4, n = 8, n = 16 2. 3e-x â x Right Sum only: n = 4, n = 8, n = 16 Ù1 3. 3e-x â x Midpoint Sum only: n = 4, n = 8, n = 16 Ù1 Ÿ The actual value is 1 - 1 » 0.318092372. How accurate were your approximations? Which Ù e ã3 approximation was closest? Lesson 6: Approximating the area under a curve--Riemann Sums, the Trapezoid Rule and Simpson’s Rule

We’ve already examined the Riemann sums in detail. Now let’s take the same function, f(x)=x3ã-x, and study it with the Trapezoid Rule and Simpson’s Rule.

In a sense, then, Lesson 6 is a continuation of Lesson 5.

Trapezoid Rule

We’re going to use the same basic method we used for the rectangles in the Riemann sums, but we’ll adjust the shape to reflect a trapezoid.

First, we need a new command called Polygon. Its form is below.

Polygon pt1, pt2, … is a graphics primitive that represents a filled polygon. The four points of our kth@ 8trapezoid are< givenD by xk-1, f xk-1 ,f(xk , and xk, listed in clockwise order. Clear f, deltax, trapezoidsum, simpsonssum, a, b,Hn L L

@ D 2 Lesson-6.nb

graph f x =x^3E^-x for x = 0 to x=8 Plot H L

1.2

1.0

0.8

0.6

0.4

0.2

2 4 6 8

min max

f x_ := x^3 ãx a = 0; b@= 8D;  n = 4; deltax = b - a n 2 H L  Lesson-6.nb 3

Note the similarities below to the rectangle commands. We’ll use trapezoids to define the new shapes

yPlot = Plot f x , x, a, b , PlotRange ® 0, 1.5 , PlotStyle -> Red, Thick ; trapezoids = Table Polygon x, 0 , x, f x , x + deltax, f x + deltax , x + deltax, 0 , x, a, b -@deltax@ D 8, deltax< ; 8 < 8

1.2

1.0

0.8

0.6

0.4

0.2

0 2 4 6 8 5.75234

Now we’ll reset using n=8.

f x_ := x^3 ãx a = 0; b@= 8D;  n = 8; deltax = b - a n 1 H L  4 Lesson-6.nb

yPlot = Plot f x , x, a, b , PlotRange ® 0, 1.5 , PlotStyle -> Red, Thick ; trapezoids = Table Polygon x, 0 , x, f x , x + deltax, f x + deltax , x + deltax, 0 , x, a, b -@deltax@ D 8, deltax< ; 8 < 8

1.2

1.0

0.8

0.6

0.4

0.2

0 2 4 6 8 5.74332

Now we’ll reset using n=16.

f x_ := x^3 ãx a = 0; b@= 8D;  n = 16; deltax = b - a n 1 H L  2 Lesson-6.nb 5

yPlot = Plot f x , x, a, b , PlotRange ® 0, 1.5 , PlotStyle -> Red, Thick ; trapezoids = Table Polygon x, 0 , x, f x , x + deltax, f x + deltax , x + deltax, 0 , x, a, b -@deltax@ D 8, deltax< ; 8 < 8

1.2

1.0

0.8

0.6

0.4

0.2

0 2 4 6 8 5.74398

Note that all I had to change in the last two sections was n = 8 or 16. Then re-execute each set of commands.

How do these values compare to the Riemann sum values? Better? Worse?

You try....

Ÿ Use the examples above to approximate the area under the curve of f(x) = ã-x from x = 1 to x = 3 using the Trapezoid Rule on Mathematica. Compute using first n = 4, then n = 8, and then n = 16. 3 -x â 1. 1 e x Ÿ The actual value is 1 - 1 » 0.318092372. How accurate were your approximations? Ù e ã3

Simpson’s Rule

Simpson’s Rule uses a parabola to approximate the top of each consecutive pair of partitions. We will NOT attempt to draw the tops as that is non-trivial. (If I can get it working, I’ll let you know:)

Remember that now n MUST be an even number. The area under one such approximating parabola can be written simpsonssum = ( 1 f x + 4 f x + Dx + 1 f x + 2 Dx )Dx. 3 3 3

H L H L H L 6 Lesson-6.nb Simpson’s Rule uses a parabola to approximate the top of each consecutive pair of partitions. We will NOT attempt to draw the tops as that is non-trivial. (If I can get it working, I’ll let you know:)

Remember that now n MUST be an even number. The area under one such approximating parabola can be written

simpsonssum = ( 1 f x + 4 f x + Dx + 1 f x + 2 Dx )Dx. 3 3 3 f x_ := x^3 ãx a = 0; H L H L H L b@= 8D;  n = 4; deltax = b - a n 2 H L  simpsonssum = Sum 1 3 * f i + 4 3 * f i + deltax + 1 3 * f i + 2 * deltax * deltax, i, a, b - 2 * deltax, 2 * deltax N @H  @ D  @ D  @ DL 5.99235 8

f x_ := x^3 ãx a = 0; b@= 8D;  n = 8; deltax = b - a n 1 H L  simpsonssum = Sum 1 3 * f i + 4 3 * f i + deltax + 1 3 * f i + 2 * deltax * deltax, i, a, b - 2 * deltax, 2 * deltax N @H  @ D  @ D  @ DL 5.74031 8

f x_ := x^3 ãx a = 0; b@= 8D;  n = 16; deltax = b - a n 1 H L  2 simpsonssum = Sum 1 3 * f i + 4 3 * f i + deltax + 1 3 * f i + 2 * deltax * deltax, i, a, b - 2 * deltax, 2 * deltax N @H  @ D  @ D  @ DL 5.74419 8

You try....

Ÿ Use the examples above to approximate the area under the curve of f(x) = ã-x from x = 1 to x = 3 using Simpson’s Rule on Mathematica. Compute using first n = 4, then n = 8, and then n = 16. 3 -x â 1. 1 e x Ÿ The actual value is 1 - 1 » 0.318092372. How accurate were your approximations? Ù e ã3 Johanna M Debrecht Page | 1 Limits with Python Calculus 1

Lab Description In this lab, we are going to explore limits by writing a few short programs in Python. You do not need to be an expert at Python, or even know the language yet to complete the lab. You also do not need to have python installed on your computer, but you will need access to the internet. All the code you need is contained in this document.

We will use Python at first to look at some graphs for which you could easily compute the limit algebraically. Then we will use it to find limits for things we cannot yet compute. In all cases, we will also produce the graph of the function in the region of a so that we can connect the value of the limit with the graph.

Studying Limits Using Python: Part 1

Step 1: Get an Account on CoCalc SageMath is a free open-source mathematics software system licensed under the GPL (General Public License). Through it, you can get free access to python, R (used in statistics), Octave, java, C++, fortran, SageMath, Julia, and others. Go to the CoCalc (Collaborative Calculation in the Cloud) website (at https://cocalc.com) and create an account.

Step 2: Create a Project for Each New Program Application Click on the orange ball surrounded by the blue arcs on the upper left of your home page.

Click on “Create a New Project,” give it a title, then click on “Create Project.” When created, click on the title to open it. Johanna M Debrecht Page | 2

Step 3: Specify Jupyter as the Type of Notebook At the top, in the banner, you will see the following. Click on “New.”

Click on “Jupyter notebook” in the first row, second from the left. Name it something logical.

You should now see something like the following. Johanna M Debrecht Page | 3

Step 4: Specify Python as the Program We have to tell the system what software to use. We will be writing in Python, so we will choose Python 3 (system-wide). This is the first Suggested kernel. (A kernel is the system’s programming that runs the software program and interprets it.) Click on your choice. You should see something like the picture below.

Step 5: Where to Enter Code We will be writing our code in the big empty space, starting where you see the horizontal line with the blue stripe on the left. We need to load some software packages, written by others, to assist us in our calculations and graphing. For example, numpy is a library containing a vast number of routines for numerical calculation in python, and matplotlib contains packages for plotting and graphing.

Step 6: Saving the File, Commenting, Caveats & the Code You will want to save your file often. There is a green button with a picture of a floppy disk and the word Save on it. Click there to save. (See picture above.) Johanna M Debrecht Page | 4

Entering Comments You will also need to put your name into the file. You can do that by enclosing it between triple quotation marks. Anything between triple quotation marks will be ignored by Python. (See Substep G for a note about quote marks.) For a single line comment, you can put a hashtag or # at the beginning of that one line, but for longer comments, use the triple quote marks.

Substep A: Importing Libraries of Routines to Use Type in the following code:

Import Packages from External Libraries """Put Your Name Here""" import numpy as np from matplotlib import pyplot as plt

You should be able to copy/paste it in. To get Python to execute the code in a particular “In[#]” line, hold down the Shift key on the keyboard and hit the Enter key at the same time. Numpy is the main scientific package for computing with Python. So we don’t have to keep typing “numpy,” we have nicknamed it “np.” Pyplot is a simple way to plot graphs, obtained from a large library of 2D plotting routines called Matplotlib. We have nicknamed it “plt.”

Here is what my output in Python looks like:

Johanna M Debrecht Page | 5

Warning about Quote Marks: Straight versus Curved Caution! Depending on the font you are using, python may not like your single and/or double quote marks. If you see the error in red below, that is what happened. (You may not have noticed, but if the single or double quote marks were incorrect, they would have shown up as red in the code.) The problem is that in some fonts, like this one (Times New Roman), quotes are curved, like “these are curved” and ‘so are these.’ In other fonts, (such as Futura or Comic Sans), the quotes are straight lines, “this is Comin Sans.”

How can we handle this issue? If the quote is in a comment, and not part of a command, we do not care if it is curved. Then we can put a u just before the text string in the double (straight) quotes. The u will cause it to ignore any non-ascii characters and to print them as is. See the the curved apostrophe in the word “Johanna’s” in the next box. The command plt.title tells Python that what follows in the parentheses between the two straight quotes is the title to print above a plot.

Option to Print Non-ascii Code

plt.title(u"Johanna’s work for Limit Lab")

Output:

Johanna M Debrecht Page | 6

How do we print the straight double quotes? On a Windows-based machine, the Unicode for the ascii double quote is to type the characters x22 with no spaces. Immediately after the second 2, then hit Alt + x (i.e., hit the Alt key on the keyboard followed by the x key). Try it in a Word document; it works! The Unicode for the ascii single quote is x27.

On a Mac computer, straight quotes are the default, except in Word. Type them curly, then hit the key command for , which is Command + z.

Warning about CoCalc losing Access to the Internet If CoCalc goes to sleep while you are reading through the lab, or while you take a break, or if there is a break in your Internet connection, you will have to re-execute all the code from the beginning. That is, CoCalc forgets where you were and suddenly knows nothing about anything done before. You can tell this has happened by noticing that the input lines have started over at 1. Simply scroll to the top, click into each input line anywhere, and re-execute the code down to where you left off. (Re-executing the code means holding down the SHIFT key while pressing the ENTER key.) This only needs to be done once inside each input line, not once per line. Warning about spacing and tabs in Python To get the spacing to look right in Microsoft Word, I had to insert either spaces or tabs. However, Python will not recognize these as the appropriate spacing marks. You will need to remove them by deleting them and using the ENTER while within Python to get the spacing correct. For example, we often need to define a function in Python. Here is the code to do that:

Code to Define a Function in Python def f(x): return (x**2-4)/(x + 2)

If you copy and paste the code, you will need to put the cursor immediately after the colon (:) then hit Delete until the cursor is between the colon and the “r” in “return.” Then hit ENTER. Python will automatically put in the correct indentation. Alternatively, you can use the tab command while in Python. If you type the code in directly to Python, you will not have this difficulty. Johanna M Debrecht Page | 7

Substep B: Guessing A Limit by Trying Numbers Near the Target x-value x2 − 4 Let’s try to guess the value of limit for a function you know. Let fx()= . Using the x + 2 algebraic methods used in class, you know this reduces to

x2 − 4 ( xx+−22)( ) fx() = = =x − 2. xx++22( )

Let’s use this information to find limfx ( ). Plugging in, we know the limit should be – 4. So, we x →−2 will guess values near x = – 2.

Here are some notes about the code needed. Note the use of the double asterisk for a power instead of the ^ symbol. The command linspace has the form (start, end, number, True or False). It starts plotting at the start value and goes to the end value, dividing into number of evenly spaced intervals. If it has a value of true, it uses the last value. If it has the value False, it does not.

Code to Guess the Value of the Limit plt.title(u"Johanna’s work to Guess the Value of the Limit") # define the function and a list of points to try def f(x): return (x**2-4)/(x + 2) # make a list of x-values to use and put them in a vector xvals1 = np.linspace(-1.9999, -1.9,4,True) """make a 2nd list of x-values to the right of x = – 2 and put them in a vector""" xvals2 = np.linspace(-2.1, -2.0001,4,True) # plot both graphs on the same graph plt.plot(xvals1, f(xvals1)) plt.plot(xvals2, f(xvals2)) # Show the plot Johanna M Debrecht Page | 8

plt.show()

Here is what my code looked like in CoCalc:

Johanna M Debrecht Page | 9

Where the two colors meet is where x = – 2. What do you think the y-value is there? Yes, it does look like – 4, as we expected.

You Try: Assignment 1 Repeat Substep B to guess the value of the following limit:

x −1 lim . x →1 x −1 You may want to call this function g(x) to distinguish it from the first effort, and change the name of the xvalues to xvals3 and xvals4. For the square root of x, use the command np.sqrt(x) Remember to change your points, this time going from 0 to .9999 using 20 points and from 1.0001 to 1.9 using 20 points. Keep saving your file as you work. You will turn it in as a pdf file. What do you think the value of the limit is? Where do the two colored sections meet? Johanna M Debrecht Page | 10

Substep C: Finding the True, Exact Limit Value (When It Exists) Now let us call up another library that will handle symbolic mathematics, called sympy. We will use this to directly compute the limit. Later, you will need the square root function, so you may want to add it to your list of commands to call up through sympy, by adding sqrt to the list. Here is the code:

Call up the Symbolic Library from sympy import symbols, limit, sin, cos, sqrt, init_printing

You will not get an output for this command, but it has called up these symbols. (Don’t forget to hold the Shift key while you press Enter, to get the line to execute.)

The command init_printing prints things out in a “pretty” format. We also need to define x as a symbol. (Note the straight apostrophe marks. That’s x27 then Alt + x.) Then find the limit. The limit command has three parts (function, variable, number x is approaching).

Compute the True Limit Value x = symbols('x') init_printing() limit((x**2-4)/(x + 2), x, -2)

Here is my code and its output.

Johanna M Debrecht Page | 11

You Try: Assignment 2 Repeat Substep C to guess the value of the following limit:

x −1 lim . x →1 x −1 You may want to call this function g(x) to distinguish it from the first effort. For the square root of x, use the command sqrt(x) that you added to your symbol list. (Computing a limit requires sympy, and sympy won’t recognize np.sqrt. It requires the symbol sqrt.) Don’t forget to change the value of a in the limit command, so that x is approaching 1. Continue to save your file to turn in. (It can all be done in one larger file.) What value did you get this time? Did it agree with where the two colors met in the graph?

Substep D: Finding an Infinite Limit Let us use what we have learned to find the value of a limit that turns out to be infinite. We will also graph the function. First, we will plot the graph so we will have an intuition about the results to expect. We will consider the following function:

( x + 3) lim . x →3 (x2 − 9)

Plotting a graph # create a list of values to calculate from -5 to 5 by 0.1 x = np.arange(-5, 5, 0.1) # let the y values be calculated according to the following function y = (x + 3)/(x**2 - 9) # We want to plot the (x, y) coordinates. plt.plot(x,y) # We want the graph to show and label from x is – 5 to 5. plt.xlim(-5,5) # We want the graph to show and label from y is – 10 to 10. Johanna M Debrecht Page | 12

plt.ylim(-10,10) # We want to label the x-axis. plt.xlabel('x-axis') # We want to label the y-axis. plt.ylabel('y-axis') # We want to show the plot. plt.show()

Below you will see my code and the graph it produced. Why is there a vertical line in the graph? Is it really on the graph of the function?

The limit does not exist (DNE), since the limit from the right is positive infinity and the limit from the left is negative infinity.

The Two-Sided Limit Let us ask for the value of the limit at x = 3 now. We do not need to reload sympy and the other commands; they are already in use in my Jupyter notebook. However! I do need to reset x as a variable, since in the plot above it was the list of numbers from –5 to 5 by 0.1 Johanna M Debrecht Page | 13

Compute the True Limit Value # Reset x as a variable, not a list of values x = symbols('x') # Now ask for the limit. limit((x + 3)/(x**2 - 9), x, 3)

We got a very strange result, positive infinity, but we know it should be DNE. What’s wrong?

The default for sympy is from the right, so, since I did not tell it what the direction was, that is what it did. Let’s try again, and tell it to look at both directions by putting +- in straight apostrophes.

Compute the True Limit Value # Reset x as a variable, not a list of values x = symbols('x') # Now ask for the limit. limit((x + 3)/(x**2 - 9), x, 3, '+-')

Johanna M Debrecht Page | 14

Our result indicates that the program believes we have an error. However, the last line reveals the reason: “The limit does not exist since left hand limit = – ∞ and right hand limit = ∞. Success!

One-sided Limits Now let’s try evaluating the two one-sided limits. We will add either a '+' or a '–' to the argument limit, at the end. Note that the straight apostrophes are required.

Compute the One-sided Limit Value # Reset x as a variable, not a list of values x = symbols('x') # Now ask for the limit from the right. limit((x + 3)/(x**2 - 9), x, 3, '+')

This is correct for the limit from the right. How about the limit from the left?

Compute the One-sided Limit Value # Reset x as a variable, not a list of values Johanna M Debrecht Page | 15

x = symbols('x') # Now ask for the limit from the left. limit((x + 3)/(x**2 - 9), x, 3, '-')

Now the values of the limits meet our expectations, based on the original graph of the function.

You Try: Assignment 3 Repeat Substep D to compute the value of the following limits: xxx−−−111 lim , lim , lim . x →1 xxx−−−111xx→→11+− For the square root of x, use the command sqrt(x) Do not try to graph the function first; simply compute the limits. Continue to save your file to turn in. (It can all be done in one larger file.) Substep E: Finding a Limit at Infinity Now let’s find a limit as x goes to ∞ or – ∞. To do this, we need to first import infinity from sympy. The symbol for infinity is two, side-by-side o’s, or oo, as in the letter, not the number zero.

Call up the Symbolic Library from sympy import oo

x + 3 Now we can compute some limits at infinity. Let’s find lim . Here is the code. x →∞x2 − 9

Johanna M Debrecht Page | 16

Compute the Limit at Infinity # ask for the limit as x goes to infinity. limit((x + 3)/(x**2 - 9), x, oo)

x + 3 How about the limit at – ∞? lim . x →−∞x2 − 9

Compute the Limit atNegative Infinity # ask for the limit as x goes to negative infinity. limit((x + 3)/(x**2 - 9), x, -oo)

You Try: Assignment 4 Repeat Substep E to compute the value of the following limits: xx−−44 lim , lim . xx→∞ xx22++22→−∞ For the square root of x, use the command sqrt(x) as sympy requires. Keep saving your file to turn in. (It can all be done in one larger file.) To help you out, I have already graphed the function for you. (I used the code below to produce the graph. You are welcome to repeat this step, but it is not required. If you do produce the graph, be sure you then return x to a symbol before finding the limits at infinity.)

Johanna M Debrecht Page | 17

Plotting a graph # create a list of values to calculate from -20 to 50 by 0.1 x = np.arange(-20, 50, 0.1) # let the y values be calculated according to the following function y = (x - 3)/np.sqrt(x**2 + 2) # We want to plot the (x, y) coordinates. plt.plot(x,y) # We want the graph to show and label from x is – 20 to 50. plt.xlim(-20,50) # We want the graph to show and label from y is – 3 to 3. plt.ylim(-3,3) # We want to label the x-axis. plt.xlabel('x-axis') # We want to label the y-axis. plt.ylabel('y-axis') # We want to show the plot. plt.show()

The code and graph output are below. Johanna M Debrecht Page | 18

Now use the oo symbol for infinity to find the limits at ∞ or – ∞. You can see from the graph above that they are NOT the same value. (If you graphed the function, be sure to return x to a symbol with the x = symbols('x') command.)  ÿ ÿ

45ÿ789@ ABBBCDEFGGFÿIPQRPSETUÿVPWTDGBXÿYPTED`UÿaPRXbDGÿcBBB

sA’789@ tu‚ve55eÿwr‘rxv’™ÿyrz’‚5 xÿ{r’v‚—™ÿ|r‘x˜‚5ÿgt

45ÿ7de9@ fghiÿpqirqÿsirhgtÿu

45ÿ7d89@ vwxy€‚ƒx„ v †

45ÿ7d‡9@ ˆ‰xy€ÿwÿx‘’„v†ÿ“ÿvuu„”e†ÿ”ÿ8

45ÿ7d•9@ ˆ‰xy€

sA’7d•9@

45ÿ7d–9@ —ˆ—v‰xy€ÿwÿ—˜ˆˆ„ˆ‰xy€™v†

45ÿ7dd9@ —ˆ—v‰xy€

sA’7dd9@

45ÿ7dd9@ ˆÿwÿƒe€—˜ˆy„7v9™ÿˆ‰xy€†

45ÿ7df9@ ˆ„g†

sA’7df9@ ”gph

45ÿ7dh9@ —ˆ—vÿwÿƒe€—˜ˆy„7v9™ÿ—ˆ—v‰xy€†

45ÿ7dg9@ —ˆ—v„g†

sA’7dg9@ ”gp•

45ÿ7de9@ sirhgtÿiitrjhtjsklrqrjhtÿipÿrjt

45ÿ7d89@ sirhgtÿmnirqÿipÿmr

45ÿ7d‡9@ vÿwÿ5ope‘e5qr„hphhg™gh™hpg†

45ÿ7d•9@ yÿwÿˆ„v†

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 3  ÿ ÿ

45ÿ789@A BCDEFGHCI5PQRSTUÿVWCWXSYB`XBCPYUCFaPCSYGbFGIcYd BCDEBCWDQGURUVWCWXSYeXPP5YUÿCFaPCSYfYd BCDEGCFaPCQYGbFGIcYd BCDERCFaPCQYRbFGIcYd BCDECPeP5gQd BCDEcHWhQd

r`D789@A

45ÿ78i@A BCDEFGHCI5PQRSTUÿVWCWXSYB`XBCPYUCFaPCSYGbFGIcYd BCDEBCWDQGURUVWCWXSYeXPP5YUÿCFaPCSYfYd BCDERCIpQbqTUÿqTd BCDEGCFaPCQYGbFGIcYd BCDERCFaPCQYRbFGIcYd BCDECPeP5gQd BCDEcHWhQd

r`D78i@A

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 3  ÿ ÿ

45ÿ7889@ ABCDEFGBH5IPQRSTÿUVBVWRXAYWABIXTBE`IBRXFaEFHbXc ABCDABVCPFTQTUVBVWRXdWII5XTÿBE`IBRXeXc ABCDFBHfPSTgSc ABCDQBHfPahTÿic ABCDFBE`IBPXFaEFHbXc ABCDQBE`IBPXQaEFHbXc ABCDBIdI5pPc ABCDbGVqPc

uYC7889@

45ÿ78r9@ bIIpÿRÿSDi bICsIWWVWÿRÿDSSSSg fEFsHCbÿRÿtS

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" (3  ÿ ÿ

45ÿ789@A BCDÿEFGHI5PQRÿSQSTRÿT9RÿFUUIUVAÿ ÿÿÿQWXY`aFÿbÿQPT9Vÿ ÿÿÿcHFUYHcI5WdIa5HFUÿbÿ9ÿ ÿÿÿefghCÿYipPQWXY`aFVÿqÿFUUIUÿrsBÿcHFUYHcI5WdIa5HFUÿtuYTWcHpAÿ ÿÿÿÿÿÿÿvUc5HÿPQwxvvUITcuYHFÿUIIHÿcpÿy€‚RÿY5SÿHƒFÿ5auiFUÿIQÿcHFUYHcI5pÿpIÿQYUÿ cpÿyg„C r„g†s‡ˆ†‰s„C ‚wVÿ ÿÿÿÿÿÿÿ„ ‘Aÿ ÿÿÿÿÿÿÿÿÿÿÿT9ÿbÿT9ÿ’ÿQ`IYHPQWXY`aFV“SQSTPT9Vÿ ÿÿÿÿÿÿÿC€ˆC”„ÿ•C †–g—g˜g†s™ † Aÿ ÿÿÿÿÿÿÿÿÿÿÿvUc5HÿPdeUUIUfÿ’ÿSFUcXYHcXFÿcpÿgFUIÿQIUÿTÿbÿdRÿT9Vÿ ÿÿÿÿÿÿÿÿÿÿÿphpFTcHPiVÿÿÿjÿlmnoÿpqrstuvwxÿpvwtqÿyqÿurzqÿrÿm{oqÿ|ÿqssns}ÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿQWXY`aFÿbÿQPT9Vÿ ÿÿÿÿÿÿÿcHFUYHcI5WdIa5HFUÿ~bÿiÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿ€qÿyvÿqvmuqsÿ‚vwƒÿrÿpn„mvnwÿwny ÿnsÿvmÿyvÿ†mv‡qÿn„m†ÿyuqwÿvmÿsqrt uqpÿmuqÿ‡rˆv‡„‡ÿw„‡‰qsÿn‚ÿvmqsrmvnwp}ÿ ÿÿÿgDÿYipPQWXY`aFVÿqÿFUUIUAÿ ÿÿÿÿÿÿÿcHFUYHcI5WdIa5HFUÿbÿ’iÿ ÿÿÿ C„‰ sÿT9RÿcHFUYHcI5WdIa5HFUÿ

pI`aHcI5Rÿ5IWcHFUYHcI5pÿbÿEFGHI5PQRÿSQSTRÿT9ÿbÿpFFSRÿFUUIUÿbÿpFHWFUUIUVÿ

gDÿ5IWcHFUYHcI5pÿqÿ9AÿÿÿÿÿÿÿjÿŠÿpn„mvnwÿyrpÿ‚n„wƒ}ÿ ÿÿÿvUc5HÿPQwEauiFUÿIQÿQa5dHcI5ÿdY``pÿGYpÿ‹iÿ~ÿŒ5IWcHFUYHcI5pŽwVÿ ÿÿÿvUc5HÿPQwEauiFUÿIQÿcHFUYHcI5pÿGYpÿ‹iÿ~ÿ5IWcHFUYHcI5pŽwVÿ ÿÿÿvUc5HÿPQwxÿpI`aHcI5ÿcpÿy˜†h‰„g†s‚wV Ch˜CAÿ ÿÿÿvUc5HÿPQwEIÿpI`aHcI5ÿQIa5SÿƒFÿ`YpHÿYvvUITcuYHcI5ÿGYpÿy˜†h‰„g†s‚ÿƒapÿHƒ Fÿ5auiFUÿIQÿcHFUYHcI5pÿGYpÿys†‡g„C r„g†s˜‚RÿGƒcdƒÿcpÿ5IHÿvIppci`FfwV

xvvUITcuYHFÿUIIHÿcpÿ9RÿY5SÿHƒFÿ5auiFUÿIQÿcHFUYHcI5pÿpIÿQYUÿcpÿ9ÿ xvvUITcuYHFÿUIIHÿcpÿ9‘ii‘Œ’“’9‘Œ“8”RÿY5SÿHƒFÿ5auiFUÿIQÿcHFUYHcI5pÿpIÿQYUÿc pÿiÿ xvvUITcuYHFÿUIIHÿcpÿ9‘‘’”i‘•’9“‘8’‘“RÿY5SÿHƒFÿ5auiFUÿIQÿcHFUYHcI5pÿpIÿQYUÿc pÿŒÿ xvvUITcuYHFÿUIIHÿcpÿ9‘’’”•Œ’Œ9Œ“iŒRÿY5SÿHƒFÿ5auiFUÿIQÿcHFUYHcI5pÿpIÿQYUÿc pÿ•ÿ EauiFUÿIQÿQa5dHcI5ÿdY``pÿGYpÿ8ÿ EauiFUÿIQÿcHFUYHcI5pÿGYpÿÿ xÿpI`aHcI5ÿcpÿ9‘’’’8‘99•Œ898•‘ÿ

45ÿ78i@A QPpI`aHcI5V

–aH78i@A ’”8‘””8‘’’“•‘F’9’

45ÿ78Œ@A pFFSÿbÿ9 pFHWFUUIUÿbÿii9P’i9V uYTWcHpÿbÿ9

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" '3  ÿ ÿ

45ÿ789@A BCDÿEFGHI5PQRÿSQSTRÿTURÿFVVIVWAÿ ÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿdHFV`HdI5XeIb5HFVÿcÿUÿ ÿÿÿfghiCÿ`pqPQXY`abFWÿrÿFVVIVÿstBÿdHFV`HdI5XeIb5HFVÿuv`TXdHqAÿ ÿÿÿÿÿÿÿwVd5HÿPQxywwVITdv`HFÿVIIHÿdqÿ€‚ƒRÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿ dqÿ€h C†s h‡tˆ‰‡t C†ƒ‘xWÿ ÿÿÿÿÿÿÿ †’Aÿ ÿÿÿÿÿÿÿÿÿÿÿTUÿcÿTUÿ“ÿQaI`HPQXY`abFW”SQSTPTUWÿ ÿÿÿÿÿÿÿC‰C• ÿ–C†‡—h˜h™h‡td††‡†Aÿ ÿÿÿÿÿÿÿÿÿÿÿwVd5HÿPefVVIVgÿ“ÿSFVdY`HdYFÿdqÿhFVIÿQIVÿTÿcÿeRÿTUWÿ ÿÿÿÿÿÿÿÿÿÿÿqiq‘FTdHPjWÿÿÿkÿmnopÿqrstuvwxyÿqwxurÿzrÿvs{rÿsÿn|prÿ}ÿrttot~ÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿcÿjÿ ÿÿÿÿÿÿÿÿ ÿÿÿ€€€ÿrÿzw‚‚ÿrwnvrtÿƒwx„ÿsÿqo‚ nwoxÿxoz†ÿotÿwnÿzw‚‚ÿ‡nwˆrÿo n‡ÿzvrxÿwnÿtrsu vrqÿnvrÿˆs‰wˆ ˆÿx ˆŠrtÿoƒÿwnrtsnwoxq~€€€ÿ ÿÿÿhDÿ`pqPQXY`abFWÿrÿFVVIVAÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿcÿ“jÿ ÿÿÿ†C †tÿTURÿdHFV`HdI5XeIb5HFVÿ

qIabHdI5Rÿ5IXdHFV`HdI5qÿcÿEFGHI5PQRÿSQSTRÿTUÿcÿqFFSRÿFVVIVÿcÿqFHXFVVIVWÿ

hDÿ5IXdHFV`HdI5qÿrÿUAÿÿÿÿÿÿÿkÿ‹ÿqo‚ nwoxÿzsqÿƒo x„~ÿ ÿÿÿwVd5HÿPQxEbvpFVÿIQÿQb5eHdI5ÿe`aaqÿG`qÿŒjÿÿŽ5IXdHFV`HdI5qxWÿ ÿÿÿwVd5HÿPQxEbvpFVÿIQÿdHFV`HdI5qÿG`qÿŒjÿÿ5IXdHFV`HdI5qxWÿ ÿÿÿwVd5HÿPQxyÿqIabHdI5ÿdqÿ€™‡i h‡tƒxW Ci™CAÿ ÿÿÿwVd5HÿPQxEIÿqIabHdI5ÿQIb5S‘ÿ„Fÿa`qHÿ`wwVITdv`HdI5ÿG`qÿ€™‡i h‡tƒ‘ÿ„bqÿH„ Fÿ5bvpFVÿIQÿdHFV`HdI5qÿG`qÿ€t‡ˆh C†s h‡t™ƒRÿG„de„ÿdqÿ5IHÿwIqqdpaFgxW

ywwVITdv`HFÿVIIHÿdqÿU‘‘Rÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`VÿdqÿU‘ÿ ywwVITdv`HFÿVIIHÿdqÿU‘’jj’“”‘“U’‘”8•Rÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿd qÿj‘ÿ ywwVITdv`HFÿVIIHÿdqÿU‘’’“•j’9“U”’8‘“’”Rÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿd qÿ‘ÿ ywwVITdv`HFÿVIIHÿdqÿU‘’““‘‘•‘9“U”jRÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿd qÿ9‘ÿ ywwVITdv`HFÿVIIHÿdqÿU‘’“““8’UU98‘U89’Rÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿd qÿ”‘ÿ EbvpFVÿIQÿQb5eHdI5ÿe`aaqÿG`qÿjjÿ EbvpFVÿIQÿdHFV`HdI5qÿG`qÿ’ÿ yÿqIabHdI5ÿdqÿU‘’“““8’j98U•9U“8ÿ

45ÿ78‘@A QPqIabHdI5W

–bH78‘@A ‘‘•Uj‘•9U8••’”F“j9

45ÿ78’@A qFFSÿcÿ8

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 13  ÿ ÿ

45ÿ789@A BCDÿEFGHI5PQRÿSQSTRÿTURÿFVVIVWAÿ ÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿdHFV`HdI5XeIb5HFVÿcÿUÿ ÿÿÿfghiCÿ`pqPQXY`abFWÿrÿFVVIVÿstBÿdHFV`HdI5XeIb5HFVÿuv`TXdHqAÿ ÿÿÿÿÿÿÿwVd5HÿPQxywwVITdv`HFÿVIIHÿdqÿ€‚ƒRÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿ dqÿ€h C†s h‡tˆ‰‡t C†ƒ‘xWÿ ÿÿÿÿÿÿÿ †’Aÿ ÿÿÿÿÿÿÿÿÿÿÿTUÿcÿTUÿ“ÿQaI`HPQXY`abFW”SQSTPTUWÿ ÿÿÿÿÿÿÿC‰C• ÿ–C†‡—h˜h™h‡td††‡†Aÿ ÿÿÿÿÿÿÿÿÿÿÿwVd5HÿPefVVIVgÿ“ÿSFVdY`HdYFÿdqÿhFVIÿQIVÿTÿcÿeRÿTUWÿ ÿÿÿÿÿÿÿÿÿÿÿqiq‘FTdHPjWÿÿÿkÿmnopÿqrstuvwxyÿqwxurÿzrÿvs{rÿsÿn|prÿ}ÿrttot~ÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿcÿjÿ ÿÿÿÿÿÿÿÿ ÿÿÿ€€€ÿrÿzw‚‚ÿrwnvrtÿƒwx„ÿsÿqo‚ nwoxÿxoz†ÿotÿwnÿzw‚‚ÿ‡nwˆrÿo n‡ÿzvrxÿwnÿtrsu vrqÿnvrÿˆs‰wˆ ˆÿx ˆŠrtÿoƒÿwnrtsnwoxq~€€€ÿ ÿÿÿhDÿ`pqPQXY`abFWÿrÿFVVIVAÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿcÿ“jÿ ÿÿÿ†C †tÿTURÿdHFV`HdI5XeIb5HFVÿ

qIabHdI5Rÿ5IXdHFV`HdI5qÿcÿEFGHI5PQRÿSQSTRÿTUÿcÿqFFSRÿFVVIVÿcÿqFHXFVVIVWÿ

hDÿ5IXdHFV`HdI5qÿrÿUAÿÿÿÿÿÿÿkÿ‹ÿqo‚ nwoxÿzsqÿƒo x„~ÿ ÿÿÿwVd5HÿPQxEbvpFVÿIQÿQb5eHdI5ÿe`aaqÿG`qÿŒjÿÿŽ5IXdHFV`HdI5qxWÿ ÿÿÿwVd5HÿPQxEbvpFVÿIQÿdHFV`HdI5qÿG`qÿŒjÿÿ5IXdHFV`HdI5qxWÿ ÿÿÿwVd5HÿPQxyÿqIabHdI5ÿdqÿ€™‡i h‡tƒxW Ci™CAÿ ÿÿÿwVd5HÿPQxEIÿqIabHdI5ÿQIb5S‘ÿ„Fÿa`qHÿ`wwVITdv`HdI5ÿG`qÿ€™‡i h‡tƒ‘ÿ„bqÿH„ Fÿ5bvpFVÿIQÿdHFV`HdI5qÿG`qÿ€t‡ˆh C†s h‡t™ƒRÿG„de„ÿdqÿ5IHÿwIqqdpaFgxW

ywwVITdv`HFÿVIIHÿdqÿ8Rÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`VÿdqÿU‘ÿ ywwVITdv`HFÿVIIHÿdqÿ‘‘8”•‘•j8”•‘•Rÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿdqÿ j‘ÿ EbvpFVÿIQÿQb5eHdI5ÿe`aaqÿG`qÿ–ÿ EbvpFVÿIQÿdHFV`HdI5qÿG`qÿ’ÿ yÿqIabHdI5ÿdqÿ‘‘8”‘’U–U9U’”8‘jÿ

45ÿ78‘@A QPqIabHdI5W

—bH78‘@A “‘‘998’‘9•’’––U•‘”F“jj

45ÿ7’’@A D†‡“ÿ™’“•’ÿh“•‡† ÿŽ

45ÿ7’”@A TcqivpIaqPxTxW

45ÿ7’•@A QXqivÿcÿTŽŽ’ÿ“ÿŽTÿÿ

45ÿ7’9@A QXqiv

—bH7’9@A

45ÿ7’‘@A SQSTXqivÿcÿSdQQPQXqivRTW

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 33  ÿ ÿ

45ÿ789@A BCBDEFGH

ˆƒ789@A

45ÿ7IP@A CÿQÿRSHTBUCGV7D@WÿCEFGHX

45ÿ7II@A CVYX

ˆƒ7II@A s

45ÿ7IY@A BCBDÿQÿRSHTBUCGV7D@WÿBCBDEFGHX

45ÿ7I8@A BCBDVYX

ˆƒ7I8@A vP

45ÿ7I`@A abcdefÿbgfchdfhaipcqchdfÿgrÿchf

45ÿ7Is@A abcdefÿtubcqÿgrÿtc

45ÿ7`v@A DÿQÿ5wxSyS5€V‚vPWvPWPxvX

45ÿ7`Y@A GÿQÿCVDX

45ÿ7`8@A wRƒxSD„RU5VGQPWÿ †R†yQ‡wˆywR‡WRSTRQ‡D‚SDUF‡X wRƒxwR†ƒVDWGW †R†yQ‡€y5‡WÿRSTRQ‡C‡X wRƒxDRSTRV‡D‚SDUF‡X wRƒxGRSTRV‡G‚SDUF‡X wRƒxR€5BVX wRƒxF„†‰VX

ˆƒ7`8@A

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 03  ÿ ÿ

45ÿ7889@ ABCDEFGBH5IPQRSTÿUVBVWRXAYWABIXTBE`IBRXFaEFHbXc ABCDABVCPFTQTUVBVWRXdWII5XTÿBE`IBRXeXc ABCDFBHfPagD8TgD8c ABCDQBHfPagTÿ8c ABCDFBE`IBPXFaEFHbXc ABCDQBE`IBPXQaEFHbXc ABCDBIdI5hPc ABCDbGViPc

tYC7889@

45ÿ78p9@ bIIhÿRÿS bICqIWWVWÿRÿrsrSssParSc fEFqHCbÿRÿ8S

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 3  ÿ ÿ

45ÿ789@A BCDÿEFGHI5PQRÿSQSTRÿTURÿFVVIVWAÿ ÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿdHFV`HdI5XeIb5HFVÿcÿUÿ ÿÿÿfghiCÿ`pqPQXY`abFWÿrÿFVVIVÿstBÿdHFV`HdI5XeIb5HFVÿuv`TXdHqAÿ ÿÿÿÿÿÿÿwVd5HÿPQxywwVITdv`HFÿVIIHÿdqÿ€‚ƒRÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿ dqÿ€h C†s h‡tˆ‰‡t C†ƒ‘xWÿ ÿÿÿÿÿÿÿ †’Aÿ ÿÿÿÿÿÿÿÿÿÿÿTUÿcÿTUÿ“ÿQaI`HPQXY`abFW”SQSTPTUWÿ ÿÿÿÿÿÿÿC‰C• ÿ–C†‡—h˜h™h‡td††‡†Aÿ ÿÿÿÿÿÿÿÿÿÿÿwVd5HÿPefVVIVgÿ“ÿSFVdY`HdYFÿdqÿhFVIÿQIVÿTÿcÿeRÿTUWÿ ÿÿÿÿÿÿÿÿÿÿÿqiq‘FTdHPjWÿÿÿkÿmnopÿqrstuvwxyÿqwxurÿzrÿvs{rÿsÿn|prÿ}ÿrttot~ÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿcÿjÿ ÿÿÿÿÿÿÿÿ ÿÿÿ€€€ÿrÿzw‚‚ÿrwnvrtÿƒwx„ÿsÿqo‚ nwoxÿxoz†ÿotÿwnÿzw‚‚ÿ‡nwˆrÿo n‡ÿzvrxÿwnÿtrsu vrqÿnvrÿˆs‰wˆ ˆÿx ˆŠrtÿoƒÿwnrtsnwoxq~€€€ÿ ÿÿÿhDÿ`pqPQXY`abFWÿrÿFVVIVAÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿcÿ“jÿ ÿÿÿ†C †tÿTURÿdHFV`HdI5XeIb5HFVÿ

qIabHdI5Rÿ5IXdHFV`HdI5qÿcÿEFGHI5PQRÿSQSTRÿTUÿcÿqFFSRÿFVVIVÿcÿqFHXFVVIVWÿ

hDÿ5IXdHFV`HdI5qÿrÿUAÿÿÿÿÿÿÿkÿ‹ÿqo‚ nwoxÿzsqÿƒo x„~ÿ ÿÿÿwVd5HÿPQxEbvpFVÿIQÿQb5eHdI5ÿe`aaqÿG`qÿŒjÿÿŽ5IXdHFV`HdI5qxWÿ ÿÿÿwVd5HÿPQxEbvpFVÿIQÿdHFV`HdI5qÿG`qÿŒjÿÿ5IXdHFV`HdI5qxWÿ ÿÿÿwVd5HÿPQxyÿqIabHdI5ÿdqÿ€™‡i h‡tƒxW Ci™CAÿ ÿÿÿwVd5HÿPQxEIÿqIabHdI5ÿQIb5S‘ÿ„Fÿa`qHÿ`wwVITdv`HdI5ÿG`qÿ€™‡i h‡tƒ‘ÿ„bqÿH„ Fÿ5bvpFVÿIQÿdHFV`HdI5qÿG`qÿ€t‡ˆh C†s h‡t™ƒRÿG„de„ÿdqÿ5IHÿwIqqdpaFgxW

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 3  ÿ ÿ

HIIPQRSTUVCÿPQQVÿSBÿWXÿU5DÿVYCÿ5`TaCPÿQbÿSVCP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Q5BÿBQÿbUPÿSBÿficÿ pQÿBQq`VSQ5ÿbQ`5DcÿrYCÿqUBVÿUIIPQRSTUVSQ5ÿsUBÿWcWcÿrY`BÿVYCÿ5`TaCPÿQbÿSVCPUVS Q5BÿsUBÿFdXÿsYStYÿSBÿ5QVÿIQBBSaqCuÿ

45ÿ789@A BCCDÿEÿFG

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 3  ÿ ÿ

45ÿ7889@ ABCÿDEFGH5IPQÿRPRSQÿSTQÿEUUHUV@ÿ ÿÿÿPWXY`aEÿbÿPISTVÿ ÿÿÿcGEUYGcH5WdHa5GEUÿbÿTÿ ÿÿÿefghBÿYipIPWXY`aEVÿqÿEUUHUÿrsAÿcGEUYGcH5WdHa5GEUÿtuYSWcGp@ÿ ÿÿÿÿÿÿÿvUc5GÿIPwxvvUHScuYGEÿUHHGÿcpÿy€‚QÿY5RÿGƒEÿ5auiEUÿHPÿcGEUYGcH5pÿpHÿPYUÿ cpÿyg„B r„g†s‡ˆ†‰s„B ‚wVÿ ÿÿÿÿÿÿÿ„ ‘@ÿ ÿÿÿÿÿÿÿÿÿÿÿSTÿbÿSTÿ’ÿP`HYGIPWXY`aEV“RPRSISTVÿ ÿÿÿÿÿÿÿB€ˆB”„ÿ•B †–g—g˜g†s™ † @ÿ ÿÿÿÿÿÿÿÿÿÿÿvUc5GÿIdeUUHUfÿ’ÿREUcXYGcXEÿcpÿgEUHÿPHUÿSÿbÿdQÿSTVÿ ÿÿÿÿÿÿÿÿÿÿÿphpEScGIiVÿÿÿjÿlmnoÿpqrstuvwxÿpvwtqÿyqÿurzqÿrÿm{oqÿ|ÿqssns}ÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿPWXY`aEÿbÿPISTVÿ ÿÿÿÿÿÿÿcGEUYGcH5WdHa5GEUÿ~bÿiÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿ€qÿyvÿqvmuqsÿ‚vwƒÿrÿpn„mvnwÿwny ÿnsÿvmÿyvÿ†mv‡qÿn„m†ÿyuqwÿvmÿsqrt uqpÿmuqÿ‡rˆv‡„‡ÿw„‡‰qsÿn‚ÿvmqsrmvnwp}ÿ ÿÿÿgCÿYipIPWXY`aEVÿqÿEUUHU@ÿ ÿÿÿÿÿÿÿcGEUYGcH5WdHa5GEUÿbÿ’iÿ ÿÿÿ B„‰ sÿSTQÿcGEUYGcH5WdHa5GEUÿ

pH`aGcH5Qÿ5HWcGEUYGcH5pÿbÿDEFGH5IPQÿRPRSQÿSTÿbÿpEERQÿEUUHUÿbÿpEGWEUUHUVÿ

gCÿ5HWcGEUYGcH5pÿqÿT@ÿÿÿÿÿÿÿjÿŠÿpn„mvnwÿyrpÿ‚n„wƒ}ÿ ÿÿÿvUc5GÿIPwDauiEUÿHPÿPa5dGcH5ÿdY``pÿFYpÿ‹iÿ~ÿŒ5HWcGEUYGcH5pŽwVÿ ÿÿÿvUc5GÿIPwDauiEUÿHPÿcGEUYGcH5pÿFYpÿ‹iÿ~ÿ5HWcGEUYGcH5pŽwVÿ ÿÿÿvUc5GÿIPwxÿpH`aGcH5ÿcpÿy˜†h‰„g†s‚wV Bh˜B@ÿ ÿÿÿvUc5GÿIPwDHÿpH`aGcH5ÿPHa5RÿƒEÿ`YpGÿYvvUHScuYGcH5ÿFYpÿy˜†h‰„g†s‚ÿƒapÿGƒ Eÿ5auiEUÿHPÿcGEUYGcH5pÿFYpÿys†‡g„B r„g†s˜‚QÿFƒcdƒÿcpÿ5HGÿvHppci`EfwV

xvvUHScuYGEÿUHHGÿcpÿ’ŒQÿY5RÿGƒEÿ5auiEUÿHPÿcGEUYGcH5pÿpHÿPYUÿcpÿTÿ xvvUHScuYGEÿUHHGÿcpÿ’i‘QÿY5RÿGƒEÿ5auiEUÿHPÿcGEUYGcH5pÿpHÿPYUÿcpÿiÿ xvvUHScuYGEÿUHHGÿcpÿ’i8““”‘i‘8’Œ‘”“”QÿY5RÿGƒEÿ5auiEUÿHPÿcGEUYGcH5pÿpHÿPYUÿ cpÿŒÿ xvvUHScuYGEÿUHHGÿcpÿ’i8“Œ“Œ88Œ“T’“”iQÿY5RÿGƒEÿ5auiEUÿHPÿcGEUYGcH5pÿpHÿPYUÿc pÿ•ÿ DauiEUÿHPÿPa5dGcH5ÿdY``pÿFYpÿ“ÿ DauiEUÿHPÿcGEUYGcH5pÿFYpÿ’ÿ xÿpH`aGcH5ÿcpÿ’i8“Œ“Œ•’”Œ•‘8““‘ÿ

45ÿ789@ PIpH`aGcH5V

–aG789@ ’’T’••’ŒT‘T“•i•E’i•

45ÿ78‘9@ pEERÿbÿ’T pEGWEUUHUÿbÿiiTI’iTV uYSWcGpÿbÿŒT

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 3  ÿ ÿ

45ÿ789@A BCDÿEFGHI5PQRÿSQSTRÿTURÿFVVIVWAÿ ÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿdHFV`HdI5XeIb5HFVÿcÿUÿ ÿÿÿfghiCÿ`pqPQXY`abFWÿrÿFVVIVÿstBÿdHFV`HdI5XeIb5HFVÿuv`TXdHqAÿ ÿÿÿÿÿÿÿwVd5HÿPQxywwVITdv`HFÿVIIHÿdqÿ€‚ƒRÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿ dqÿ€h C†s h‡tˆ‰‡t C†ƒ‘xWÿ ÿÿÿÿÿÿÿ †’Aÿ ÿÿÿÿÿÿÿÿÿÿÿTUÿcÿTUÿ“ÿQaI`HPQXY`abFW”SQSTPTUWÿ ÿÿÿÿÿÿÿC‰C• ÿ–C†‡—h˜h™h‡td††‡†Aÿ ÿÿÿÿÿÿÿÿÿÿÿwVd5HÿPefVVIVgÿ“ÿSFVdY`HdYFÿdqÿhFVIÿQIVÿTÿcÿeRÿTUWÿ ÿÿÿÿÿÿÿÿÿÿÿqiq‘FTdHPjWÿÿÿkÿmnopÿqrstuvwxyÿqwxurÿzrÿvs{rÿsÿn|prÿ}ÿrttot~ÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿcÿjÿ ÿÿÿÿÿÿÿÿ ÿÿÿ€€€ÿrÿzw‚‚ÿrwnvrtÿƒwx„ÿsÿqo‚ nwoxÿxoz†ÿotÿwnÿzw‚‚ÿ‡nwˆrÿo n‡ÿzvrxÿwnÿtrsu vrqÿnvrÿˆs‰wˆ ˆÿx ˆŠrtÿoƒÿwnrtsnwoxq~€€€ÿ ÿÿÿhDÿ`pqPQXY`abFWÿrÿFVVIVAÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿcÿ“jÿ ÿÿÿ†C †tÿTURÿdHFV`HdI5XeIb5HFVÿ

qIabHdI5Rÿ5IXdHFV`HdI5qÿcÿEFGHI5PQRÿSQSTRÿTUÿcÿqFFSRÿFVVIVÿcÿqFHXFVVIVWÿ

hDÿ5IXdHFV`HdI5qÿrÿUAÿÿÿÿÿÿÿkÿ‹ÿqo‚ nwoxÿzsqÿƒo x„~ÿ ÿÿÿwVd5HÿPQxEbvpFVÿIQÿQb5eHdI5ÿe`aaqÿG`qÿŒjÿÿŽ5IXdHFV`HdI5qxWÿ ÿÿÿwVd5HÿPQxEbvpFVÿIQÿdHFV`HdI5qÿG`qÿŒjÿÿ5IXdHFV`HdI5qxWÿ ÿÿÿwVd5HÿPQxyÿqIabHdI5ÿdqÿ€™‡i h‡tƒxW Ci™CAÿ ÿÿÿwVd5HÿPQxEIÿqIabHdI5ÿQIb5S‘ÿ„Fÿa`qHÿ`wwVITdv`HdI5ÿG`qÿ€™‡i h‡tƒ‘ÿ„bqÿH„ Fÿ5bvpFVÿIQÿdHFV`HdI5qÿG`qÿ€t‡ˆh C†s h‡t™ƒRÿG„de„ÿdqÿ5IHÿwIqqdpaFgxW

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 3  ÿ ÿ

QRRSTDFBCG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&))% 0'12!  ÿ ÿ# $" (3  ÿ ÿ

45ÿ789@A BCDÿEFGHI5PQRÿSQSTRÿTURÿFVVIVWAÿ ÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿdHFV`HdI5XeIb5HFVÿcÿUÿ ÿÿÿfghiCÿ`pqPQXY`abFWÿrÿFVVIVÿstBÿdHFV`HdI5XeIb5HFVÿuv`TXdHqAÿ ÿÿÿÿÿÿÿwVd5HÿPQxywwVITdv`HFÿVIIHÿdqÿ€‚ƒRÿ`5SÿH„Fÿ5bvpFVÿIQÿdHFV`HdI5qÿqIÿQ`Vÿ dqÿ€h C†s h‡tˆ‰‡t C†ƒ‘xWÿ ÿÿÿÿÿÿÿ †’Aÿ ÿÿÿÿÿÿÿÿÿÿÿTUÿcÿTUÿ“ÿQaI`HPQXY`abFW”SQSTPTUWÿ ÿÿÿÿÿÿÿC‰C• ÿ–C†‡—h˜h™h‡td††‡†Aÿ ÿÿÿÿÿÿÿÿÿÿÿwVd5HÿPefVVIVgÿ“ÿSFVdY`HdYFÿdqÿhFVIÿQIVÿTÿcÿeRÿTUWÿ ÿÿÿÿÿÿÿÿÿÿÿqiq‘FTdHP9Wÿÿÿjÿlmnoÿpqrstuvwxÿpvwtqÿyqÿurzqÿrÿm{oqÿ|ÿqssns}ÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿQXY`abFÿcÿQPTUWÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿ~cÿ9ÿ ÿÿÿÿÿÿÿÿ ÿÿÿÿ€qÿyvÿqvmuqsÿ‚vwƒÿrÿpn„mvnwÿwny ÿnsÿvmÿyvÿ†mv‡qÿn„m†ÿyuqwÿvmÿsqrt uqpÿmuqÿ‡rˆv‡„‡ÿw„‡‰qsÿn‚ÿvmqsrmvnwp}ÿ ÿÿÿhDÿ`pqPQXY`abFWÿrÿFVVIVAÿ ÿÿÿÿÿÿÿdHFV`HdI5XeIb5HFVÿcÿ“9ÿ ÿÿÿ†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HIPÿCDDIÿFQÿ8S8TÿH5UÿIVPÿ5WGXPCÿDYÿFIPCHIFD5QÿQDÿYHCÿFQÿbeSÿ ABBCDEFGHIPÿCDDIÿFQÿRS8TÿH5UÿIVPÿ5WGXPCÿDYÿFIPCHIFD5QÿQDÿYHCÿFQÿbfSÿ ABBCDEFGHIPÿCDDIÿFQÿ8S8TÿH5UÿIVPÿ5WGXPCÿDYÿFIPCHIFD5QÿQDÿYHCÿFQÿbgSÿ hDÿQDiWIFD5ÿYDW5USÿpVPÿiHQIÿHBBCDEFGHIFD5ÿqHQÿRS8SÿpVWQÿIVPÿ5WGXPCÿDYÿFIPCHIF D5QÿqHQÿrRTÿqVFsVÿFQÿ5DIÿBDQQFXiPtÿ

45ÿ789@ ÿ

   !" # $ %%& %&'(%&%'&))% 0'12!  ÿ ÿ# $" 33 Johanna M Debrecht Page | 1 Newton’s Method with Python Calculus 1

Lab Description

In this lab, we are going to learn about Newton’s Method for solving equations of the form f(x) = 0 by writing a few short programs in Python. While we have primarily solved these problems with various algebraic techniques—quadratic formula, rational root theorem and synthetic division, and so forth—there are many equations for which finding the roots algebraically is very difficult or even impossible. In this lab, we study one method of approximating such roots.

You do not need to be an expert at Python, or even know the language yet to complete the lab. You also do not need to have python installed on your computer, but you will need access to the internet. All the code you need is contained in this document.

Using CoCalc to Access Python

Step 1: Get an Account on CoCalc SageMath is a free open-source mathematics software system licensed under the GPL (General Public License). Through it, you can get free access to python, R (used in statistics), Octave, java, C++, fortran, SageMath, Julia, and others. Go to the CoCalc (Collaborative Calculation in the Cloud) website (at https://cocalc.com) and create an account.

Step 2: Create a Project for Each New Program Application Click on the orange ball surrounded by the blue arcs on the upper left of your home page.

Click on “Create a New Project,” give it a title, then click on “Create Project.” When created, click on the title to open it. Johanna M Debrecht Page | 2

Step 3: Specify Jupyter as the Type of Notebook At the top, in the banner, you will see the following. Click on “New.”

Click on “Jupyter notebook” in the first row, second from the left. Name it something logical.

You should now see something like the following. Johanna M Debrecht Page | 3

Step 4: Specify Python as the Program We have to tell the system what software to use. We will be writing in Python, so we will choose Python 3 (system-wide). This is the first Suggested kernel. (A kernel is the system’s programming that runs the software program and interprets it.) Click on your choice. You should see something like the picture below.

Step 5: Where to Enter Code We will be writing our code in the big empty space, starting where you see the horizontal line with the blue stripe on the left. We need to load some software packages, written by others, to assist us in our calculations and graphing. For example, numpy is a library containing a vast number of routines for numerical calculation in python, and matplotlib contains packages for plotting and graphing.

Step 6: Saving the File, Commenting, Caveats You will want to save your file often. There is a green button with a picture of a floppy disk and the word Save on it. Click there to save. (See picture above.) Entering Comments You will also need to put your name into the file. You can do that by enclosing it between triple quotation marks. Anything between triple quotation marks will be ignored by Python. (See the Warning below for a note about quote marks.) For a single line comment, you can put a hashtag or # at the beginning of that one line, but for longer comments, use the triple quote marks. Johanna M Debrecht Page | 4 Note that the purple In[#] notation indicates where you need to enter code on different input lines. Make sure your code is lined up and indented exactly like the code in the pictures. If copying and pasting puts in tabs that aren’t in the picture of the code, take the tabs out! Also note that Word sometimes converts hyphens to longer dashes called en dashes. This is a hyphen -; this is an en dash –. See the difference? Python needs hyphens for subtractions and negatives, not en dashes.)

Type in the following code:

Inserting Comments into the Code In [#] """Put Your Name Here"""

You should be able to copy/paste it in. To get Python to execute the code in a particular In[#] line, hold down the Shift key on the keyboard and hit the Enter key at the same time.

Here is what my output in Python looks like:

Warning about Quote Marks: Straight versus Curved Caution! Depending on the font you are using, python may not like your single and/or double quote marks. If you see the error in red below, that is what happened. (You may not have noticed, but if the single or double quote marks were incorrect, they would have shown up as red in the code.) The problem is that in some fonts, like this one (Times New Roman), quotes are curved, like “these are curved” and ‘so are these.’ In other fonts, (such as Futura or Comic Sans), the quotes are straight lines, “this is Comin Sans.” In some fonts, sad to say, you can’t tell if they are curved or straight.

How can we handle this issue? If the quote is in a comment, and not part of a command, we do not care if it is curved. Then we can put a u just before the text string in the double (straight) quotes. The u will cause it to ignore any non-ascii characters and to print them as is. See the the curved apostrophe in the word “Johanna’s” in the next box. The command plt.title tells Python that what follows in the parentheses between the two straight quotes is the title to print above a plot. To use plt, you must first import MathPlotLib (the Math Plotting Johanna M Debrecht Page | 5 Library). Pyplot is a simple way to plot graphs, obtained from a large library of 2D plotting routines called Matplotlib. We have nicknamed it “plt.”

Option to Print Non-ascii Code

# The purple text represents the beginning of a new input line in Python. You do NOT type it.

# The first command imports the plotting function so we can use it.

In [#] from matplotlib import pyplot as plt

In [#] plt.title(u"Johanna’s work for the Newton’s Method Lab")

Here is the output:

How do we get the computer to produce the straight double quotes? On a Windows-based machine, the Unicode for the ascii double quote is to type the characters x22 with no spaces. Immediately after the second 2, hit Alt + x (i.e., hit the Alt key on the keyboard followed by the x key). Try it in a Word document; it works! The Unicode for the ascii single quote is x27.

On a Mac computer, straight quotes are the default, except in Microsoft Word. Type them curly, then hit the key command for , which is Command + z.

Warning about Python Going to Sleep If CoCalc goes to sleep while you are reading through the lab, or while you take a break, or if there is a break in your Internet connection, you will have to re-execute all the code from the beginning. That is, CoCalc forgets where you were and suddenly knows nothing about anything done before. You can tell this has happened by Johanna M Debrecht Page | 6 noticing that the input lines have started over at 1. Simply scroll to the top, click into each input line anywhere, and re-execute the code down to where you left off. (Re-executing the code means holding down the SHIFT key while pressing the ENTER key.) This only needs to be done once inside each input line, not once per line. Warning about spacing and tabs in Python To get the spacing to look right in Microsoft Word, I had to insert either spaces or tabs. However, Python will not recognize these as the appropriate spacing marks. You will need to remove them by deleting them and using the ENTER while within Python to get the spacing correct. For example, we often need to define a function in Python. Here is the code to do that:

Code to Define a Function in Python In [#] def f(x): return (x**2-4)/(x + 2)

If you copy and paste the code, you will need to put the cursor immediately after the colon (:) then hit Delete until the cursor is between the colon and the “r” in “return.” Then hit ENTER. Python will automatically put in the correct indentation. Alternatively, you can use the tab command while in Python. If you type the code in directly to Python, you will not have this difficulty. Some General Information about Newton’s Method Newton’s Method of finding the real roots of equations is also sometimes called the Newton–Raphson Method. It is one of the fastest methods, compared to other methods, but it does not guarantee that an existing solution will be found. In fact, there is currently no known theorem on predicting when Newton’s Method will work and when it will not work. You will want to read the section on Newton’s Method in your textbook before starting this lab. Newton’s Method Overview Newton’s Method uses the tangent line approximations we learned about earlier, called the Linear Approximation Function (aka, the tangent line to f(x) at x = a). f() x≈=+ Lx () f () a f′ ()( a x − a )

The requirement here is that f is differentiable at x = a, and that we stay “close” to a. Newton’s Method starts with an initial “guess” for the value of the root (aka, the solution, the zero, or the x-

intercept). We can call this initial guess the “seed” for Newton’s Method, x0. The tangent line to f at xx= 0 is drawn. Provided the slope of this tangent line is not 0, then it must cross the x-axis somewhere. Call this x-

intercept value x1. Generally, this x-intercept ( x1,0) is closer to the true x-intercept of the function f than the seed xx= 0 was. Next, the tangent line to f at xx= 1 is drawn. Provided the slope of this tangent line is not 0,

then it must also cross the x-axis somewhere. Call this x-intercept value x2. Generally, this x-intercept ( x2 ,0) is

closer to the true x-intercept of the function f than xx= 1 was. By continuing in this fashion, we can produce a

list of closer approximations, xxxx0123,,,, xn , , to the true value of the x-intercept to f. Johanna M Debrecht Page | 7

Figure 1. True root at x*, with approximations. Example in Graph Form for Newton’s Method 1 Consider the graph in Figure 2a, x +−3. It appears to have two real roots: near the values of 1 and 9. Each x2 of these values, in turn becomes the initial seed for Newton’s Method. Finding a good approximation of the root near ½ took several iterations of Newton’s Method (Figure 2b), but the root near 9 took only one (Figure 2c).

1 Figure2a. Graph of x +−3. x2 Johanna M Debrecht Page | 8

Figure 2b. The root near x = ½. Figure 2c. The root near x = 9. Finding the Seed To find the original guess for the root, or the seed, you will need to graph the function and estimate the x- intercept(s).

Finding the Next Guess, xn

Based on the explanation given previously, ( x1,0) is the x-intercept of the tangent line to f at xx= 0 , given by

y==+− Lx( 0) f( x 0) f′( x 00)( x x).

Since ( x1,0) is on this line, it satisfies the equation. Plugging it in, we get

0===+−→=+−y Lx( 0) fx( 0) f′′( x 01)( x x 0) 0.fx( 0) f( x 01)( x x 0)

fx( 0 ) ⇒=−xx10 fx′( 0 )

Similarly, ( x2 ,0) is on the tangent line to f at xx= 1. Hence,

fx( 1 ) xx21= − , fx′( 1 )

and, in general, for n > 0,

fx( n−1 ) xxnn=−1 − . fx′( n−1 )

These values, xn, are the approximations for the root near xx= 0. To make it easier to code, we can rewrite this formula in an equiavalent form as

fx( n ) xxnn+1 = − . fx′( n ) Johanna M Debrecht Page | 9 Failures of Newton’s Method Newton’s Method is usually quite fast at finding roots, but sometimes things can go wrong, particularly with bizarrely shaped functions. Here are some of the problems with Newton’s Method:

1. Suppose that one of your interim approximations for the root, xn, has a derivative whose value is 0. That

is, fx′( n ) = 0, meaning it has a horizontal tangent line, but fx( n ) ≠ 0. Then the tangent line does not

cross the x-axis, so there is no value to use for the next iteration, but xn is not a root for f. In this case, Newton’s Method fails completely, since there is no way to continue. (Fix: Try a different original seed,

x0.)

2. There is more than one real root for the function f, and you did not choose an original seed value, x0 , close enough to the one you are looking for. As a consequence, your approximations

xxxx0123,,,, xn , , approach a different root than the one you wanted. (Fix: Pick a value for x0 that is

closer to the root desired. You may have to zoom in on the graph to get a better approximate seed for x0. )

3. By extreme bad luck, you happen to choose a seed value x0 that causes Newton’s Method to alternate back and forth between two values without ever settling down to approach just one. This is the most dangerous error in a programming situation, since the computer will continue to look and look and look. To stop this from happening, we will give the computer a maximum number of xn to compute, usually

30–50. (Fix: Pick a value for x0 that is closer to the root desired. You may have to zoom in on the graph

to get a better approximate seed for x0.) See Figure 3, with a root near –2, for an example of this type.

Figure 2a. Graph of xx3 −+2 2. Figure 2b. Seed of x = 0, 30 iterations.

In Figure 2 above, the graph of fx()=−+ x3 2 x 2 shows that there is a root near x = –2. However, by choosing the original seed value x0 = 0, Newton’s Method gets caught in an endless cycle of approximations

xxxx0123,,,, xn , , that continue to bounce between 0 and 1, without ever approaching the true root near x = – 2. Johanna M Debrecht Page | 10 Coding Newton’s Method into Python Storage Issues For our purposes, we will only be computing roughly 30–50 iterations, at most, so we will have only that many

xn values. Certainly, we could keep all the approximations, but in theory, we only need the last one, since it should be the closest to the actual root value. In an industrial application, Newton’s Method could be solving millions of equations at once, and storage might become an issue. Consequently, we will overwrite our interim

values xi with the next value xi+1.This means we will only need one variable x which can be overwritten, until the final iteration. (Note: We will, however, print all the interim approximation values; we just won’t store them within the program.) The other consideration is limiting the number of times the program has to call up the function f and compute a value. While it is not an issue for us, in large industrial applications, the function f might be so enormously large and complex that it takes hours or even days to call up! Thus, we will limit the number of times we have to use the function by storing values that will be reused. Define the Function and the Derivative Function

Recall that Numpy and SciPy (scientific Python) are great libraries of functions, operations, and routines for dealing with numeric data, but they are not great at finding symbolic representation. That is, they are great at finding the derivative of f at x = 2, but not good at finding the derivative function f '(x) at all values of x. For that, we need the symbolic library, SymPy, or sympy.

Unfortunately, I cannot use a function called f in both Numpy and Sympy. Numpy and SciPy will only accept numeric data-valued functions, while Sympy wants only symbolic functions. To distinguish between the two, I will name the symbolic version of f f_sym and the numeric-valued version simply f.

We will use sympy’s command diff to find the derivative. Here is its format: diff(func, var, n) where func is the function you want the derivative of, var is the variable you want the derivative with respect to, and n is the particular derivative you want, with 1 begin the default if you omit n. Get Symbolic Representations for f and f ' You will first need to get a symbolic representation of the function, so we can find the symbolic representation of the derivative. This requires the use of sympy. 1 Example x +−3. x2 For example, after importing the diff command for sympy, and converting x to a symbol, here is how you would 1 find the derivative of x +−3. x2 Note that the purple In[#] notation indicates where you need to enter code on different input lines. Make sure your code is lined up and indented exactly like the code in the pictures. If copying and pasting puts in tabs that aren’t in the picture of the code, take the tabs out! (Put the cursor in fron of the r in return and hit “backspace” until the cursor is directly between the colon and the r in return. Then hit Enter. This will insert the correct return within Python. Johanna M Debrecht Page | 11 Also note that Word sometimes converts hyphens to longer dashes called en dashes. This is a hyphen -; this is an en dash –. See the difference? Python needs hyphens for subtractions and negatives, not en dashes.)

Defining the function and Derivative Using SymPy’s Diff Command In [#] "'Import the commands for sympy. Putting an asterisk will import all of sympy’s commands, though this is overkill. You could be specific instead, and import just the ones you need/use."' from sympy import * In [#] # Use x as a symbol (that is, a variable) instead of a number value x = symbols('x') In [#] "'Define a symbolic representation of the function, which will be returned as the math expression. We will reserve f(x) for the numeric calculations."' f_sym = sqrt(x) + x**(-2) – 3 In [#] #Make sure you entered it correctly by calling it up to check f_sym In [#] "'Define a symbolic representation of the derivative function, which will be returned as the math expression. We will reserve dfdx(x) for the numeric calculations."' dfdx_sym = diff(f_sym, x) In [#] #Make sure you entered it correctly by calling it up to check dfdx_sym

If you need to, you can also import the symbols for square root, sine, the exponential function, and natural log, in case you want to use them for functions later.

Here is what my code looked like in CoCalc:

Johanna M Debrecht Page | 12

Convert Symbolic Representations to Numeric Representations Sympy produces symbolic representations of functions, but it cannot use numeric data. Thus, we need to convert our function and derivative to forms that can be used with numeric data. Sympy has a command, called lambdify, that accomplishes this, usually with numpy or math. The primary purpose of this function is to provide a bridge from SymPy expressions to numerical libraries such as NumPy, SciPy, NumExpr, mpmath, and tensorflow. In general, SymPy functions do not work with objects from other libraries, such as NumPy arrays, and functions from numeric libraries like NumPy or mpmath do not work on SymPy expressions. Lambdify bridges the two by converting a SymPy expression to an equivalent numeric function. 1 Example x +−3. x2 Now we will convert our symbolic representations for the function and its derivative to ones we can use with numbers. Here is the code:

Convert the function and Derivative to Numeric Forms In [#] "'Import the commands for sympy. Putting an asterisk will import all of sympy’s commands, though this is overkill. You could be specific instead, and import just the ones you need/use. You may need to periodically re-execute the first line to import more of the sympy commands, particulary if Python or your computer go to sleep or there is a disruption to internet service."' from sympy import * In [#] #Turn the symbolic expression for f to a plain Python function f = lambdify([x], f_sym) # if this gives an error, try inserting (x) after f_sym as in “f_sym(x)” In [#] #put in 1 for x to check its operation. You should get -1. f(1) In [#] #Turn the symbolic expression for f ' to a plain Python function dfdx = lambdify([x], dfdx_sym) # if this gives an error, try inserting (x) after dfdx_sym In [#] #put in 1 for x to check its operation. You should get –1.5. Johanna M Debrecht Page | 13 dfdx(1)

Here is what my code looked like in CoCalc:

Graphing to find the Original Seed x0

We need a good value for the original seed, to ensure the computer locates the correct root. We will graph the function to accomplish this goal. MatPlotLib plotting We will need to import the numbers library of Python, if you haven’t already. (Recall Numpy is the main scientific package for computing with Python. So we don’t have to keep typing “numpy,” we have nicknamed it “np.”) We will also need to import the math plotting library with the nickname of plt. (Recall that Pyplot is a simple way to plot graphs, obtained from a large library of 2D plotting routines called Matplotlib. We have nicknamed it “plt.”) Then we are going to graph the function f to get an idea of where the root(s) (x- intercept(s)) will be. We will also need to graph the x-axis, since plt does not automatically draw the axis lines. Matplotlib has a command for this called axhline. You can specify y position and xmin and xmax in the data coordinate (i.e, your actual data range in the x axis).

Graphing the Function and its Derivatives

In [#] # Import matplotlib’s pyplot command as plt, if not already done import matplotlib.pyplot as plt In [#] # Import the number library numpy as np import numpy as np In [#] "'Define what x values to use in graphing the function (the window). Remember that you may have to adjust these values to find all possible roots. Note that our function here eliminates negative x values and 0 from the domain."' x = np.arange(0.001,10,0.1) Johanna M Debrecht Page | 14 In [#] # Set what the y values should be, that is, the function. y = f(x) In [#] "'Plot the x-axis or y = 0 with the axhline command. I chose purple for this graph."' plt.axhline(y = 0, color = 'purple', label="x-axis") "'This command will plot the ordered pairs given by (x, y), with the color green."' plt.plot(x,y,color='green', label='f')

#These commands put the labels on the graph. plt.xlabel('x-axis') plt.ylabel('y-axis') plt.legend() plt.show()

Here is what the output looked like:

Johanna M Debrecht Page | 15

You can barely see the purple x-axis sticking out the edges of the plot.

Analysis of the graph The graph approaches + ∞ as x approaches 0 from the right. The graph appears to stay low (closer to the x-axis from very close to 0 as it moves to the right). I need a graph with smaller y-values. Let’s zoom in on the picture by controlling the y-axis range, by setting a limit on it. This will add only one line of code to the graph: plt.ylim(-50, 50) Here is the code that we will reenter, with the new added line printed in dark red, so you can see it. Note that I only need to re-enter the plotting command. Controlling the x and y range of the Graph

Graphing the Function and its Derivatives "'Plot the x-axis or y = 0 with the axhline command. I chose purple for this graph."' In [#] plt.axhline(y = 0, color = 'purple', label="x-axis") "'This command will plot the ordered pairs given by (x, y), with the color green."' plt.plot(x,y,color='green', label='f') #new line of code below plt.ylim(-50, 50)

#These commands put the labels on the graph. plt.xlabel('x-axis') plt.ylabel('y-axis') plt.legend() Johanna M Debrecht Page | 16 plt.show()

Here is what the output looked like:

This appears to have all the key elements of the graph present and is beginning to reveal the roots. By continuing to play around with the graph, and limiting both the x and y ranges, I was able to produce the following:

Graphing the Function and its Derivatives "'Plot the x-axis or y = 0 with the axhline command. I chose purple for this graph."' In [#] plt.axhline(y = 0, color = 'purple', label="x-axis") "'This command will plot the ordered pairs given by (x, y), with the color green."' plt.plot(x,y,color='green', label='f') #new line of code below plt.xlim(0,10) plt.ylim(-2, 5)

#These commands put the labels on the graph. plt.xlabel('x-axis') plt.ylabel('y-axis') plt.legend() Johanna M Debrecht Page | 17 plt.show()

Here is what the output looked like:

Picking the Original Seeds

We have a good enough graph to now pick values for x0. Estimate where the x-intercepts are in the graph. First,

I will choose x0 = 0.5, then I will choose x0 = 9.

Code for Newton’s Method We have all the pieces we need to use Newton’s Method. Now all we have to do is code it. We will need to set the accuracy level of our approximation. Since we are looking for roots (x-intercepts), we need 0± error. We will use “error” for the degree of accuracy; some functions use epsilon, or eps, instead. We will also set the error and seed values at the beginning using “seed” and “set_error.” Set the Seed, Error, and Maximum Interation Values

Setting the Seed and Error Values "'Define the seed, error, and maximum number of iterations values."' In [#] seed = 0.5 set_error = .00001 max_its = 30 Johanna M Debrecht Page | 18

This command does not produce visible output.

Code for the Progam First, I am going to give you the code, then I will explain it in detail.

Newton’s Method Code In [#] def Newton(f, dfdx, x0, error): f_value = f(x0)

iteration_counter = 0

while abs(f_value) > error and iteration_counter

print (f'Approximate root is {x0}, and the number of iterations so far is {iteration_counter}.') #This is all one line, from “print” to “}.')”.

try:

x0 = x0 - float(f_value)/dfdx(x0)

except ZeroDivisionError:

print ("Error! - derivative is zero for x = ", x0)

sys.exit(1) # Stop searching since we have a type 1 error.

f_value = f(x0)

iteration_counter += 1

''' We will either find a solution now, or it will "time out" when it reaches the maximum number of iterations.''' #This is all one line, from “''' We” to “iterations.'''”.

if abs(f_value) > error: Johanna M Debrecht Page | 19 iteration_counter = -1

return x0, iteration_counter

solution, no_iterations = Newton(f, dfdx, x0 = seed, error = set_error)

if no_iterations > 0: # A solution was found.

print (f'Number of function calls was {1 + 2*no_iterations}')

print (f'Number of iterations was {1 + no_iterations}')

print (f'A solution is {solution}')

else:

print (f'No solution found! The last approximation was {x0}. Thus the number of iterations was {iteration_counter}, which is not possible!') #This is all one line, from “print” to “!')”.

Explanation of the Code, Line by Line Line 1 of the code In [#] def Newton(f, dfdx, x0, error): First we define a new function named “Newton” which has four arguments, f, dfdx, x, and error. The first argument is the function whose root we are trying to approximate. We have already defined f in our code. The second argument is the derivative of the function f, which is also already defined in the code. The third

argument is our initial guess for the value of the root, obtained from the graph, x0 or the seed. The final and fourth argument is the error in our estimation, or how far off the true value of the root we might be. Line 2 of the code

f_value = f(x0)

The line above sets the function value, f_value, to be the y value at xx= 0 initially. As it iterates, it overwrites the value of x0 with the new estimate and recomputes f_value. Since f_value is used in the formula twice, this eliminates having to compute it twice, which saves on computing time. Line 3 of the code

iteration_counter = 0 Johanna M Debrecht Page | 20 This line sets the counter to 0. We could start at any value, but it’s normal to start with 0, so the first iteration is number 1. Line 4 of the code

while abs(f_value) > error and iteration_counter

print (f'Approximate root is {x0}, and the number of iterations so far is {iteration_counter}.') This line of code will print out the values each time Newton’s Method iterates, so we can see what values it is generating for xn and how many iterations it is doing. The f at the beginning of the “print” command tells Python to expect some formatting directions; that is, you are going to input some data values inside of a text string. It prints the phrase “Approximate root is” followed by a space, then the value of x0, followed immediately by a comma, then another space, then the phrase “the number of iterations so far is”, followed by a space, then the number of iterations done so far, immediately followed by a period. Lines 6–14 of the code

try: x0 = x0 - float(f_value)/dfdx(x0) except ZeroDivisionError: print ("Error! - derivative is zero for x = ", x0) sys.exit(1) # Stop searching since we have a type 1 error.

f_value = f(x0) iteration_counter += 1

This section forms a loop in the code. That is, it will repeat these lines of code, so long as (while) the number of iterations is < the maximum number of iterations. Since all of these lines of code are contained within the loop (the while line), they are indented automatically by Python past the word “while” when you type it in directly. The “try” command is used to catch and handle exceptions in Python. Python executes the code following the try statement as a regular part of the code. (It is indented under the word “try”.) The code that follows the word “except” tells the program what to do when an exception is found in the preceding try clause (the regular part). Johanna M Debrecht Page | 21 Here, our “new” estimate of the root, x0, is set to be the previous value minus the ratio of the function value at x0 and the derivative at x0. (See the section, Finding the Next Guess, xn above.) This is from the formula

fx( n ) xxnn+1 = − . fx′( n )

The command “float” ensures that Python returns our value as a real number with a decimal point dividing the integer and fractional parts. In the unlikely event we managed to produce an interim approximation that was simply an integer, this will prevent Python from converting subsequent values to integers and truncating the decimal parts. Float will force the integer value 3 to be represented as 3.0 instead. The line “except ZeroDivisionError:” means that Python found an error in the line above, that is, in the “x0 = x0 - float(f_value)/dfdx(x0)” line. Note that “except” is even with “try”, but the directions for the exception are indented under “except”. We have a type 1 failure, where the slope of the tangent line at the approximation is 0, a horizontal line. We will have to stop the process, since Newton’s Method failed with that seed value. The two lines below tell the program what to do if the slope of the tangent line is 0. print ("Error! - derivative is zero for x = ", x0) sys.exit(1) # Stop searching since we have a type 1 error. It will print the error message and give the value for which the slope of the tangent line was 0. The sys.exit command tells the program to stop running. The 1 inside it is an optional argument that can be used by more advanced programmers to analyze the type of error. (1 is a general type of error on many systems, though 0 is the default if you leave it blank.) The following line is left blank because what follows is not part of the “try” command. It is still part of the “while” section. Omitting this line will not change the code. The second to last line of the “while” section, “f_value = f(x0)”, resets the number inside f_value to be the y- value at the newly overwritten x0 value. Since we need f_value to judge whether or not to keep iterating (in line 4 of the program, “while abs(f_value) > error and iteration_counter

''' We will either find a solution now, or it will "time out" when it reaches the maximum number of iterations.'''

if abs(f_value) > error:

iteration_counter = -1 Johanna M Debrecht Page | 22 return x0, iteration_counter

The first line is a comment line. These lines are not executed in Python until after the “while” loop has finished running. That means that either the method worked and it found a value, one of the derivatives equaled 0 and the process stopped, or the method reached the maximum number of iterations without getting within the error of y = 0. The second line is an “if” command. The code that immediately follows “if” and is on the same line provides the condition to be met. In this case, the condition is that the absolute value of f_value is greater than error; in other words, we still are not close enough to the root value to stop. That means that the “while” loop reached the maximum number of iterations without getting within the error of y = 0. The code on the next line, indented under “if”, tells what it should do provided the condition is met. In this case, the iteration counter is set to –1 since this is not an allowed value, to draw your attention to it. You could set it to any unusual number, such as pi or 3/7. Just do not use a counting number! The next line is a “return” statement, which ends the execution of the program and “returns” the result. We want to know where the process ended when it failed or succeeded, so we return these values, x0 and iteration_counter, to the calling function Newton. If you do not set a return value, the default is “None”. Line 20 of the code

solution, no_iterations = Newton(f, dfdx, x0 = seed, error = set_error)

This single line sets the definition for the two constant values that were “returned” by the program Newton. This first is the final value of x0, which is set to be the solution. The second value returned was the iteration_counter, which is set to be no_iterations. Notice that by giving the value of the set and error separately, we will not have to change this code to change the arguments to the Newton program.

Lines 21–27 of the code

if no_iterations > 0: # A solution was found.

print (f'Number of function calls was {1 + 2*no_iterations}')

print (f'Number of iterations was {1 + no_iterations}')

print (f'A solution is {solution}')

else: Johanna M Debrecht Page | 23 print (f'No solution found. The last approximation was {solution}. Thus the number of iterations was {no_iterations}, which is not possible!')

Line 21 is a blank line to separate the final “if” statement from the rest of the code. Omitting this line will not change the program. Line 22 begins another “if” statement. The condition here is that a solution is found. Since I set the iteration_counter to be –1 if it timed out, then this condition is only met if it worked. Under this condition, lines 23 and 24 tell the program to print out the result of Newton’s Method. Again, the “f'” (f followed by a single quote) command tells Python to expect formatting directions. What is inside the single quotes but not in curly brackets (braces) will print as is. What is in the braces prints the value instead. Thus, we get the phrase “ Anything inside the double quote marks and after “print” will print as is. The “%d” is a command telling Python to print a number (integer) where the % symbol appears with the value inside the following ()s. So, in line 23, it will print out how many time we had to call the function to produce this result. (For us, this is not a big issue, but for massive programs, knowing how often the function is computed might matter.) In line 24, the “%d” command tells Python to print out a numeric (integer) value for the total number of iterations in the program. In line 25, the “%f” command tells Python to print out the numeric value stored in the name inside the following ()s as a floating point decimal number. The program ends here with the output. Lines 26 and 27 are not executed. If the condition in line 22 is not met, then the program skips over lines 23–25 and does not execute them. It will then execute lines 26 and 27 instead. Line 26 is the “else” command, which indicates what to do if the condition in the “if” was not met. In this case, if the method failed to work, it will print a message to that effect, give the value of the last approximation calculated, and return the erroneous number of iterations value (–1). Johanna M Debrecht Page | 24 Output of the Code for the Example

Verify the Answer To verify that our method worked, let us substitute the solution into the function, and see if it gives us a value near 0. (It should, since we are looking for the roots, which are x-intercepts!)

Verifying the Answer to Newton’s Method In [#] f(solution)

Here is the output:

That is, the function value is 0.00000078968896577436, which is pretty close to 0. Johanna M Debrecht Page | 25 Changing the Arguments to Increase Accuracy To make the method more accurate, I can set the error to be a smaller value. In this case, I may also want to increase my number of iterations. To accomplish this, all I need to do is reset my “error” value and/or my “max_its” value. Note that I did not change my seed, since it worked well. Here are the changed lines of code:

Resetting the Maximum Iterations and Error Values "'Redefine the error and maximum number of iterations values."' In [#] seed = 0.5 set_error = 1*10**(-10) max_its = 50

Remember: this command does not produce visible output.

There will be absolutely no change to the code above. You can click into that single input line, hit CTRL + A (for control all, or Command A for Mac users), then hit CTRL + C to copy (Command C for Mac users). Then move below your reset values to a blank input line and hit CTRL + V for paste (Command V for Mac users). Don’t forget to execute the line with SHIFT + ENTER. Here is the output.

There is a slightly more accurate value, and it required more iterations. Now verify the solution; note the higher degree of accuracy.

Changing the Seed to find a Different Root Now that we have established how to use Newton’s Method, let us find the other root. I will leave the accuracy at 1 × 10 – 10 and the number of iterations at 50, but I will change the seed to 9. Insert the following line in a blank input line at the bottom. Here is the changed code you need now. Johanna M Debrecht Page | 26

Resetting the Seed Value "'Redefine the seed value."' In [#] seed = 9

Remember: this command does not produce visible output.

There will be absolutely no change to the code for the Newton’s Method program. You can click into that single input line, hit CTRL + A (for control all, or Command A for Mac users), then hit CTRL + C to copy (Command C for Mac users). Then move below your reset values to a blank input line and hit CTRL + V for paste (Command V for Mac users). Don’t forget to execute the line with SHIFT + ENTER. Here is the output.

Verify the solution:

Johanna M Debrecht Page | 27 Failures of Newton’s Methods Let’s examine a couple of the failures of Newton’s Method to test that our program works in those cases too. We will need to reset our function value and re-execute all the lines from there down. Let us use the function

3 fx( )=−+ x 2 x 2; x0 = 0.

Testing a Type 3 Error Here is all the code you need to enter/copy and reenter:

Testing a Failure of Type 3 In [#] from sympy import * In [#] x=symbols('x') In [#] f_sym = x**3 - 2*x + 2 # Note the change in the function to be used In [#] f_sym In [#] dfdx_sym = diff(f_sym,x) In [#] dfdx_sym In [#] f = lambdify([x], f_sym) In [#] f(2) # Note the change in the x-test point to be used In [#] dfdx = lambdify([x], dfdx_sym) In [#] dfdx(2) # Note the change in the x-test point to be used In [#] import matplotlib.pyplot as plt In [#] import numpy as np In [#] x = np.arange(-10,10,0.1) # Note the change in the x-values to be used. In [#] y = f(x) In [#] plt.axhline(y=0, color='purple',label='x-axis') plt.plot(x,y,color='green', label='f') plt.xlabel('x-axis') plt.ylabel('y-axis') plt.legend() plt.show()

You won’t necessarily need to re-execute all these lines, unless your program went to sleep, or there was an interruption to your internet. (You can tell when the notebook starts over at 1 in renumbering your input lines.) Johanna M Debrecht Page | 28 Here is the output produced so far:

Johanna M Debrecht Page | 29

It appears that the real solution(s) are near 0 on the x-axis, between –2.5 and 2.5. Playing around with the ranges leads to the following better graph:

Testing a Failure of Type 3 Continued Part 2 In [#] plt.axhline(y=0, color='purple',label='x-axis') plt.plot(x,y,color='green', label='f') plt.xlim(-2.5,2.5) plt.ylim(-2, 5) plt.xlabel('x-axis') plt.ylabel('y-axis') plt.legend() plt.show()

Here is the output: Johanna M Debrecht Page | 30

There is clearly only one root, near –2, but suppose you mistakenly enter the seed as 0.

Testing a Failure of Type 3 Continued Part 3 In [#] seed = 0 set_error = 1*10**(-10) max_its = 50

The code above produces no output:

Now reenter the Newton program and re-execute the code:

Testing a Failure of Type 3 Continued Part 4 In [#] def Newton(f, dfdx, x0, error): Johanna M Debrecht Page | 31 f_value = f(x0) iteration_counter = 0 while abs(f_value) > error and iteration_counter error: iteration_counter = -1 return x0, iteration_counter

solution, no_iterations = Newton(f, dfdx, x0 = seed, error = set_error)

if no_iterations > 0: # A solution was found. print (f'Number of function calls was {1 + 2*no_iterations}') print (f'Number of iterations was {1 + no_iterations}') print (f'A solution is {solution}') else: print (f'No solution found. The last approximation was {solution}. Thus the number of iterations was {no_iterations}, which is not possible!')

Here is the output: Johanna M Debrecht Page | 32

Note that the roots found are alternating between 0 and 1, which is why the program isn’t working. More iterations will not solve this issue. You must change the seed. Johanna M Debrecht Page | 33 Fixing a Failure Type 3 So, the program worked, but Newton’s Method failed. Choosing a better seed, say x = –2 will fix this problem. See the code below:

Fixing a Failure of Type 3 by Resetting the Seed In [#] seed = -2

Now copy and paste the program, and re-execute it.

Testing a Type 2 Error What if there is no x-intercept, or you start too far away and it times out before it finds it. Let’s test this on the previous example by setting the seed to 50 and using only 20 iterations. Johanna M Debrecht Page | 34

Copy and reenter the program and execute it. Here is the output:

The program gave up and returned the number of iterations as –1, indicating Newton’s Method failed. Fixing a Type 2 Error If the root does exist, and you just started too far away, changing the maximum number of iterations might work. However, changing the seed would be the best way to fix it. On the previous example, I changed the max_its to 50, but then it got caught up in the Type 3 error! Here is the output, without the program reproduced in the middle:

Johanna M Debrecht Page | 35

Moral of the story: Choose the seed wisely and well.

You Try: Here are some functions for you to practice your programming skills to find roots using Newton’s Method. Use the methods found in this lab to find ALL the real roots for the following functions. Print out your results, commands, and graphs and turn in or upload to D2L. Johanna M Debrecht Page | 36 1 1. xe2 x − 2 2. xx3 −+53  ÿÿ ÿ! "ÿ#ÿ $  

78ÿ@ABC DDDEFÿHIPQÿRSÿTUVIHHIWDDD

˜ƒw@ABC ™dtÿ8‡•ÿ€‰ÿ v†‡88‡y™

78ÿ@XBC Y`abcdÿef`agÿhiÿea pcb`ÿ`hdaqbdqYrÿY`abcdÿstsuvwÿhiÿsuw

78ÿ@xBC suwyw€wu‚ƒ„ v†‡88‡ˆ‰ÿv‘’ÿ“v‘ÿ”€•€wÿ”‡–„—

˜ƒw@xBC efw‚gyhiji™ v†‡88‡ˆ‰ÿv‘’ÿ“v‘ÿ”€•€wÿ”‡–™—

˜ƒw@xBC

%&! !'$!(! )0121!'"2" !20 0203!100405')6'# ÿÿ ÿ! "ÿ#ÿ $  ($ 4  ÿÿ ÿ! "ÿ#ÿ $  

78ÿ@ABC DEFGFHFEIPQRSTUV88VWXÿYT`aÿFTÿbQIXXÿFUIÿcVEQIÿTdÿFUIÿeHfHFRg hÿpqrstqÿuvqÿrwtxusytÿ€tpÿ€ÿs‚uÿyrÿƒystu‚ÿuyÿu„ †‡ˆÿdP‰gCÿ ÿÿÿ‡‘’“ÿP‰””•–—g˜P‰ÿ™ÿ•g hÿd€eqÿ€ÿs‚uÿyrÿfgh€wq‚ÿuyÿw‚qÿ€tpÿƒwuÿuvqdÿstÿ€ÿhqxuy„ ‰iVEXjÿkÿ8DGEH8XDVlIP–jGmmmmnÿ–jGmn—no’‡g pppd€eqÿ€ÿqtpÿs‚uÿyrÿfgh€wq‚ÿuyÿuvqÿ„srvuÿyrÿfÿsÿtÿqÿ€tpÿƒwuÿuvqdÿstÿ€ÿhqxuy „ppp ‰iVEX•ÿkÿ8DGEH8XDVlIP–•Gjnÿ–•Guuujn—no’‡g hÿƒyuÿvyuvÿr„€ƒv‚ÿytÿuvqÿ‚€dqÿr„€ƒv DEFGDETFP‰iVEXjnÿdP‰iVEXjgg DEFGDETFP‰iVEX•nÿdP‰iVEX•gg hÿwvyxÿuvqÿƒyu DEFGXUTYPg

yQF@ABC

%&! !'$!(! )0121!'"2" !20 0203!100405')6'# ÿÿ ÿ! "ÿ#ÿ $  ($ 4  ÿÿ ÿ! "ÿ#ÿ $  

78ÿ@ABCD EFGHGIGFPQRSTUVW88WXYÿ`UabÿGUÿcRPYYÿGVPÿdWFRPÿUeÿGVPÿfIgIGÿ`IGVÿGVPÿhiRWaPÿpUU GÿqÿhUFRGIU8Sr sÿuvwxyvÿ€vÿw‚yƒ€x„yÿ yuÿ ÿ†x‡€ÿ„wÿˆ„xy€‡ÿ€„ÿ€‰ ‘’“ÿ”Q•rDÿ ÿÿÿ–’—˜–™ÿQ8EHYiaGQ•rqArdQ•qAr sÿe fvÿ ÿ†x‡€ÿ„wÿghi †‚v‡ÿ€„ÿ‚‡vÿ yuÿˆ‚€ÿ€veÿxyÿ ÿivƒ€„‰ •jWFYkÿlÿ8EHFI8YEWmPQBnÿHoooonpBnq–˜’r rrre fvÿ ÿsyuÿ†x‡€ÿ„wÿghi †‚v‡ÿ€„ÿ€vÿ‰xt€ÿ„wÿgÿuÿvÿsÿ yuÿˆ‚€ÿ€veÿxyÿ ÿivƒ€„ ‰rrr •jWFYwÿlÿ8EHFI8YEWmPQAHBBBAnÿAHonpBnq–˜’r sÿˆ†„€ÿx„€ÿt‰ ˆ‡ÿ„yÿ€vÿ‡ evÿt‰ ˆ EFGHEFUGQ•jWFYknÿ”Q•jWFYkrr EFGHEFUGQ•jWFYwnÿ”Q•jWFYwrr sÿy„zÿ€vÿˆ†„€ EFGHYVU`Qr

‰RG@ABCD

78ÿ@AACD “–{|ÿ}~|~ÿ€|{–—ÿYg‚UFYnÿFIgIGnÿYI8nÿmUYnÿYiaGnÿI8IGƒEaI8GI8”

78ÿ@ApCD •ÿlÿYg‚UFYQ„•„r I8IGƒEaI8GI8”Qr FIgIGQQ• pqwrdQ•ÿ†ÿprnÿ•nÿqpr

‰RG@ApCD

78ÿ@AwCD rrry„†‚€x„yÿ€„ÿ†xex€ÿ„wÿ‡‡‚ ‰vÿ‰„„€ÿw‚yƒ€x„yˆrrr •ÿlÿYg‚UFYQ„•„r I8IGƒEaI8GI8”Qr FIgIGQQYiaGQ•rqArdQ•qArnÿ•nÿAr

‰RG@AwCD

%&! !'$!(! )0121!'"2" !20 0203!100405')6'# ÿÿ ÿ! "ÿ#ÿ $  ($ 34  ÿÿ ÿ! "ÿ#ÿ $  

78ÿ@ABCD EÿGHIPQIÿPÿRSTQÿUVÿWPRXITÿQUÿGPRGXRPQIÿVHUYÿ`aÿQUÿaÿbcÿdef gÿhÿ8ipqrq8stuvBwÿBwÿxpAy EÿRIQÿQ€IÿcÿWPRXITÿbIÿGPRGXRPQIÿPGGUHS‚ƒÿQUÿQ€IÿVURRU„S‚ƒÿVX‚GQSU‚ ÿhÿugÿ†ÿ‡yˆug‰‰ÿvÿ‘y Eÿ’Iÿ„P‚QÿQUÿ“RUQÿQ€Iÿ”•–ÿc—ÿGUUHS‚PQITe i˜™pi˜d™ugw y Eÿ’Iÿ„P‚QÿQ€IÿƒHP“€ÿQUÿT€U„ÿP‚ÿRPbIRÿVHUYÿ•ÿSTÿeÿaÿQUÿae i˜™pg˜fguvBwBy Eÿ’Iÿ„P‚QÿQ€IÿƒHP“€ÿQUÿT€U„ÿP‚ÿRPbIRÿVHUYÿcÿSTÿeÿfdÿQUÿfde i˜™p ˜fguvAxwAxy Eÿ’Iÿ„P‚QÿQUÿRPbIRÿQ€Iÿ•`P•STe i˜™pg˜qht˜uigvqgfjiy Eÿ’Iÿ„P‚QÿQUÿRPbIRÿQ€Iÿc`P•STe i˜™p ˜qht˜ui vqgfjiy Eÿ’Iÿ„P‚QÿQUÿT€U„ÿQ€Iÿ“RUQe i˜™pjkdluy

qr™@ABCD

78ÿ@AmCD EÿnITIQÿ•ÿPTÿPÿWPHSPbRI–ÿ‚UQÿPÿRSTQÿUVÿWPRXIT gÿhÿj ghd˜juigiy EÿoU„ÿPTpÿVUHÿQ€IÿRSYSQe ˜fgf™uugÿ†ÿ‡yˆug‰‰ÿvÿ‘ywÿgwÿ‡y

qr™@AmCD

%&! !'$!(! )0121!'"2" !20 0203!100405')6'# ÿÿ ÿ! "ÿ#ÿ $  ($ 4  ÿÿ ÿ! "ÿ#ÿ $  

78ÿ@ABCD EÿGHIHPÿQÿRIÿRÿSRTURVWHXÿY`PÿRÿWUIPÿ`aÿSRWbHI cÿdÿefghipeqrcrs Eÿt`uÿRIvÿa`TÿPwHÿWUxUPy p€g€qqcÿ‚ÿƒs„qc †ÿ‡ÿˆs‰ÿc‰ÿƒ‰ÿr‚‡rs

‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡‡ ghpijkddidÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿldhmjhhmnÿqgieÿdjmj8ÿmhppÿphesÿ o€pfqi8‡€8pi‡AB‡hABƒrrƒ†sÿ€8ÿogiripjs ÿÿÿÿÿuÿcÿdÿefghipeqrcrs ÿÿÿÿÿvÿwÿxiyÿhenÿzidÿqjÿp€g€{ ‡‡‡‡sÿ’ÿp€g€qqcÿ‚ÿƒs„qc †ÿ‡ÿˆs‰ÿc‰ÿƒ‰ÿr‚‡rsÿ

„ied„pimhp„p€h„pfqi8ƒ{|„r€e‡phmnh}je„efgpf„ejd€je„p€g€e{pfÿ€8ÿp€g€qj‰ÿ~‰ ~‰ÿr€ds ÿÿÿÿ€ÿÿÿÿÿÿÿÿÿÿÿÿÿdh€ejÿghpijkddidq‚lqjÿp€g€ÿrijeÿ8iÿjc€eÿe€8mjÿ‚ÿ ÿÿÿÿ€ƒÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ‚pjzÿqh8rÿp€g€ÿdÿ„eÿh8rÿd€}qÿqh8rÿp€g€ÿdÿ„e‚ ‡‡‡sÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ„ÿqpp€g‰ÿdp€gssÿ ÿÿÿÿ ÿÿÿÿÿjpejD ÿÿÿÿuÿÿÿÿÿÿÿÿÿdjid8ÿ†€g€qj‰ÿ~‰ÿ~‰ÿr€ds{ri€qrjjpd‡hpejsÿ

ghpijkddidDÿlqjÿp€g€ÿrijeÿ8iÿjc€eÿe€8mjÿpjzÿqh8rÿp€g€ÿdÿ‡iiÿh8rÿd€}qÿqh 8rÿp€g€ÿdÿii

78ÿ@ACD EÿGHIHPÿQÿRIÿRÿSRTURVWHXÿY`PÿRÿWUIPÿ`aÿSRWbHI cÿdÿefghipeqrcrs Eÿt`uÿRIvÿa`TÿPwHÿWUxUPÿaT`xÿPwHÿTU‘wPy p€g€qqcÿ‚ÿƒs„qc †ÿ‡ÿˆs‰ÿc‰ÿƒ‰ÿr‚rs

ˆi@ACD

78ÿ@AˆCD EÿGHIHPÿQÿRIÿRÿSRTURVWHXÿY`PÿRÿWUIPÿ`aÿSRWbHI cÿdÿefghipeqrcrs Eÿt`uÿRIvÿa`TÿPwHÿWUxUPÿaT`xÿPwHÿWHaPy p€g€qqcÿ‚ÿƒs„qc †ÿ‡ÿˆs‰ÿc‰ÿƒ‰ÿr‡rs

ˆi@AˆCD

78ÿ@†’CD Eÿ“`WbPU`YÿP`ÿPwHÿ”•IU–H–ÿWUxUPÿ`aÿI—bRTHÿT``PÿabY˜PU`Y cÿdÿefghipeqrcrs Eÿt`uÿRIvÿa`TÿPwHÿWUxUPÿaT`xÿPwHÿWHaPy p€g€qqe™dqcs‡As„qc‡As‰ÿc‰ÿA‰ÿr‚‡rs

ˆi@†’CD

78ÿ@†eCD Eÿ“`WbPU`YÿP`ÿPwHÿf•IU–H–ÿWUxUPÿaT`xÿPwHÿTU‘wPÿ`aÿI—bRTHÿT``PÿabY˜PU`Y cÿdÿefghipeqrcrs Eÿt`uÿRIvÿa`TÿPwHÿWUxUPÿaT`xÿPwHÿWHaPy p€g€qqe™dqcs‡As„qc‡As‰ÿc‰ÿA‰ÿr‚rs

ˆi@†eCD

%&! !'$!(! )0121!'"2" !20 0203!100405')6'# ÿÿ ÿ! "ÿ#ÿ $  ($ 54  ÿÿ ÿ! "ÿ#ÿ $  

78ÿ@ABCD EÿGHIPQRHSÿQHÿQTUÿVWXRYUYÿIR`RQÿabH`ÿQTUÿIUaQÿHaÿXcPdbUÿbHHQÿaPSeQRHS fÿgÿhipqrshtufuv EÿwHxÿdXyÿaHbÿQTUÿIR`RQÿabH`ÿQTUÿIUaQ€ sp‚tthƒ„‚tfv †v‡tf †vˆÿfˆÿ†ˆÿu uv

€‚@ABCD

78ÿ@‰ACD ‘’“ÿ”•“–•ÿ—“–’‘˜ÿrr

78ÿ@‰‰CD EÿdXyÿaHbÿQTUÿIR`RQÿdXÿ™ÿdHUXÿQHÿRSaRSRQe€ sp‚ttfÿfÿ‰v‡tfggAÿ ÿhvˆÿfˆÿrrv

€‚@‰‰CD

78ÿ@‰iCD EÿdXyÿaHbÿQTUÿIR`RQÿdXÿ™ÿdHUXÿQHÿSUddQRjUÿRSaRSRQe€ sp‚ttfÿfÿ‰v‡tfggAÿ ÿhvˆÿfˆÿ rrv

€‚@‰iCD

78ÿ@‰kCD EÿebUdQUÿdÿIRXQÿHaÿjdIPUXÿQHÿedIePIdQUÿabH`ÿWlmÿQHÿnmÿoeÿm€V fÿgÿ8pqr„r8stt Auˆÿkuˆÿuq†v EÿIUQÿQTUÿeÿjdIPUXÿoUÿedIePIdQUYÿdeeHbYRSdÿQHÿQTUÿaHIIHxRSdÿaPSeQRHS iÿgÿtfÿ ÿ‰v‡8pqhƒ„‚tfggAÿfÿAv EÿvUÿxdSQÿQHÿwIHQÿQTUÿx™yÿezÿeHHbYRSdQUX€ ps‚qpsr‚tfˆiv EÿvUÿxdSQÿQTUÿdbdwTÿQHÿXTHxÿdSYÿIdoUIÿabH`ÿ™ÿRXÿ{ÿlmÿQHÿnm€ ps‚qfspt Auˆkuv EÿvUÿxdSQÿQTUÿdbdwTÿQHÿXTHxÿdSYÿIdoUIÿabH`ÿeÿRXÿ{ÿ|ÿQHÿ|€ ps‚qispt ‰ˆ‰v EÿvUÿxdSQÿQHÿIdoUIÿQTUÿ™Wd™RX€ ps‚qfsrqtstuf rfhuv EÿvUÿxdSQÿQHÿIdoUIÿQTUÿeWd™RX€ ps‚qisrqtstui rfhuv EÿvUÿxdSQÿQHÿXTHxÿQTUÿwIHQ€ ps‚qh}r~tv

€‚@‰kCD

%&! !'$!(! )0121!'"2" !20 0203!100405')6'# ÿÿ ÿ! "ÿ#ÿ $  ($ 14  ÿÿ ÿ! "ÿ#ÿ $  

78ÿ@ABCD EÿFÿGHIPQRGSTETU

78ÿ@AVCD WÿY`abcd`eÿc`ÿfgbhipÿi``cÿqbercd`eÿq`iÿcspÿadtdcÿhfÿuÿv`pfÿc`ÿdeqdedcwx RyIy€SSE‚UƒSG„ €SE††‡ˆ‡UU‰ÿE‰ÿQQU

“”€@AVCD

78ÿ@ACD WÿY`abcd`eÿc`ÿfgbhipÿi``cÿqbercd`eÿq`iÿcspÿadtdcÿhfÿuÿv`pfÿc`ÿepvhcd‘pÿdeqdedc wx RyIy€SSE‚UƒSG„ €SE††‡ˆ‡UU‰ÿE‰ÿQQU

“”€@ACD

78ÿ@’CD ÿ

%&! !'$!(! )0121!'"2" !20 0203!100405')6'# ÿÿ ÿ! "ÿ#ÿ $  ($ 44