The first part of this worksheet contains examples. For Markdown (including Heading cells like the one above), you can double click the cell to see the text that generates the cell, then execute the cell again (by clicking the "run cell" button above) to get back to the output. The second part of this worksheet contains some exercises for you to do.
In a jupyter notebook, you can enter input and get output. Executing this block will typeset whatever you have typed here.
You can use Markdown mode from the dropdown list in the toolbar above to typeset text. You can also input and typeset mathematical formulas. You enclose them in dollar signs: for example, $f(x) = x^2$.
The advantage here is that you can make mathematical formulas fairly complicated, like $c = \lim_{x\rightarrow 0^+} \frac{(x-1)(x-2)}{x}$ or like $\int_0^2 x^3\sin(x^4)dx$.
Technically, what is in the dollar signs is LaTeX code. Most of the commands begin with a backslash. To see the formulas above better, we can add the displaystyle command: $\displaystyle c = \lim_{x\rightarrow 0^+} \frac{(x-1)(x-2)}{x}$ and $\displaystyle \int_0^2 x^3\sin(x^4)dx$.
The most common LaTeX mathmatical expressions are summarized here: http://web.ift.uib.no/Teori/KURS/WRK/TeX/symALL.html. You won't need very many of those for this course.
Double click a region to change it from code back to an editable region, then execute the code again when you are finished.
This jupyter notebook has a Kernel running SageMath, which is a computer algebra system. You can do mathematical computations, graphing, and elementary programming. The cells below give some examples of this. Jupyter notebooks can be set up with a variety of kernels, including Python, Octave -- which is kind of like Matlab -- and R (a statistical software package). We will probably only use the Sagemath kernel in this coruse.
The following code prints the values of $f(x)=x^2$ for $x = 0, 1, 2, \ldots, 9$. Note: As in a language like Python, range(0,10) gives the whole numbers from 0 to 9. If you want to include 10, you have to use range(0,11).
for x in range(0,10):
print(x,x^2)
A jupyter notebook can display graphs. Since $x$ was given a value above, we will start by declaring $x$ as a variable again.
x = var('x')
plot(x^2, (x,0,5),figsize=3)
You can also plot curves implicitly. The following command will plot the curve $x^3+y^2 = 2x$.
equation = x^3 + y ^2 == 2*x
implicit_plot(equation, (x,-3, 3), (y,-3, 3),figsize=3)
Here is a more complicated example of plotting. The goal is to plot $f(x) = x^2$, $g(x) = 2x^2$, and $h(x) = 3x^2$ in different colors on the same set of axes for $-2\leq x \leq 2$. We will also save this down to a file called our-graph.png. Outputting the result to a .png file is especially helpful if you need to include the graph in a written document or web submission. We will define each of the three plots to be equal to a symbol (a, b, or c), then make d the "sum" of the three plots. We can then perform methods on d (i.e. we can show or save the plot).
a = plot(x^2,(x,-2,2),color='red')
b = plot(2*x^2,(x,-2,2),color='green')
c = plot(3*x^2,(x,-2,2),color='blue')
d = a + b + c
d.show(figsize=3)
d.save('our-graph.png')
SageMath can also do basic computations such as evaluating, differentiating, and integrating expressions. More basic SageMath commands are given in Appendix B of the textbook. (Anything in side a block of code that begins with a "hashtag" symbol is a comment and is ignored when the cell is executed.)
x = var('x')
g = (x+2)*(x^2-9)
print(g) #This just prints g.
print(g.expand()) #This multiplies g out.
print(g.factor()) #This factors g.
print(g.substitute(x=1)) #This substitutes x=1 into g.
print(g.integrate(x)) #This integrates g with respect to x. Note that this command gives 0 as the "constant of integration."
print(g.differentiate(x)) #This differentiates g with respect to x.
#Let's also plot g and its derivative together:
a = plot(g,(x,-4,4))
b = plot(g.differentiate(x),(x,-4,4))
c = a+b
c.show(figsize=3)
$1$. Define a polynomial function $y=f(x)$ that has exactly four $x$-intercepts.
In the Markdown text provided below (the box that says "Answer 1"), write a paragraph in complete sentences explaining what your function is, what its $x$-intercepts are, and how you know. In the paragraph, give your polynomial in the Markdown text in both expanded and factored forms.
In the Code box provided, define your function in SageMath, and plot your function and its first two derivatives on the same set of axes. Be sure that all four $x$-intercepts show on your graph, and use a different color for each curve.
The function is a polynomial function that has its highest power to the 4th degree. Its x-intercepts are x=-4,x=-1,x=1, and x=2. g = x^4+2x^2-9x^2-2x+8 and factored form of g = (x+1)(x-2)(x+4)(x-1).
x = var('x')
g = (x^4+2*x^3-9*x^2-2*x+8)
a = plot(g,(x,-4,4),color='red')
b = plot(g.differentiate(x),(x,-4,4),color='green')
c = plot(g.differentiate(x, 2),(x,-4,4),color='blue')
d = a+b+c
d.show(figsize=10)
$2$. Suppose you start with 3 cents on Day 1, and the total amount of money that you have doubles each day. (So, on Day 2, you have 6 cents, and on Day 3, you have 12 cents.)
In the Markdown text provided below (the box that says "Answer 2"), write a paragraph in complete sentences explaining how to find a formula for $c(n)$, the number of cents you have on Day $n$. Then, find the day on which you pass \$1,000,000.
In the Code box provided, enter code to generate the amount of money you have on Day $n$ for $1\leq n\leq 25$. Have SageMath print out pairs of the form $(n,c(n))$.
For this question I started with the initial amount of pennies given then used a formula which doubled x which represented pennies and subtracted 1 day from the rest because it says day one you have 3 and dont start doubling until day 2. On day 19 $1,000,000 is passed.
for x in range(1,26):
print(x,3*(1-2^x)/(1-2))
$3$. Come up with an equation in $x$ and $y$ defining a curve in the $xy$-plane that cannot be solved algebraically for $x$ or $y$. Plot the curve over a range of values that shows the curve's interesting features. .
Answer 3.
x,y = var('x,y')
e = x^2-x*y+y^2==25
implicit_plot(e,(x,-8,8),(y,-8,8),color='green')