Review for test 1 in MTH 229

[Get this a an ipynb file.]

Test 1 will cover the first 4 projects. This review workbook serves two purposes:

To begin, you should "run all" so that these packages are loaded into your Julia session.

using MTH229

Calculator skills:

The basic ideas of a calculator easily correspond to ideas of julia:

Functions

Basic functions in julia and in math look almost identical: $f(x) = \sin(x) + \cos(2x)$ becomes

f(x) = sin(x) + cos(2x)
f (generic function with 1 method)

Julia has some alternative forms though, for example when parameters are involved these can be added as additional arguments to the function with default values.

Functions in math that involve cases are often easily handled with the ternary operator: predicate ? iftrue : iffalse. An example was a model for cost when the first 100 cost 5 dollars per unit and afterwards 4 dollars per unit:

cost(x) = (x <= 100) ? 5*x : 5*100 + 4*(x - 100)
cost (generic function with 1 method)

Here are some examples:

f(x) = sin(0) + (sin(pi/2) - sin(0)) / (pi/2 - 0) * (x - 0)
f (generic function with 1 method)
f(x) = 1000 * exp(0.05 * x)
f(2)
1105.1709180756477

Plotting

Plotting is done in julia through external packages. Loading the MTH229 package loads the Plots package which makes it easy to plot functions by name: plot(f, a, b). We can also plot two or more functions over $[a,b]$ – just place the functions into a [] container:

f(x) = x^2 - 2x + 3
plot(f, -3, 4)
f(x) = cos(x)
g(x) = 1 + f(2*x)
plot([f,g], 0, 2pi)

Making a plot is easy, where to plot is the possibly difficult question. This is because there are many different things we do with plots: looking at the "large" to find horizontal or slant asymptotes, or vertical asymptotes and looking small to see, for example, zeros of a function. Don't be afraid to change the values of a and b to make new plots over different domains.

Zeros

Finding zeros of a function is aided by some functions in the Roots package:

f(x) = (x-1) * (x-2) * (x^2 + 2x + 2)
fzeros(f)
2-element Array{Real,1}:
 1
 2
f(x) = exp(-3x) - 1/2
plot(f, 0, 5)			# zero between 0 and 1
fzero(f, [0, 1])
0.23104906018664842

Okay, start your engines

Use these cells or add some more to answer the questions on the exam.