MTH229 with Julia
Preface
Introduction
MTH229 at the College of Staten Island is a course to introduce a programming language to reinforce concepts of a first-semester calculus course from numerical and graphical points of view.
Some sections use the Julia programming language. For Julia
, the computer-lab “projects” are on WeBWorK and there should be sufficient background material therein to work through the details. In the notes here can be found additional detail for those seeking it. For a more thorough introduction, visit Calculus with Julia.
Installation details for Julia
are at the end of this page, but most students will use a departmental web server to access Julia
. In a pinch, there are online instances (resource-constrained) that can be used:
- Colab. Google’s
colab
service allows the free user more computing power than doesbinder
but does require more setup. This is working as of March 2025:
Go to google colab:
https://colab.research.google.com/
Click on “Runtime” menu and then “Change Runtime Type”
Select Julia as the “Runtime Type” then save
Copy and paste then run this set of commands
using Pkg
Pkg.add("Plots")
Pkg.add("MTH229")
using MTH229
using Plots
This may take 2-3 minutes to load. The plotly()
backend doesn’t work out of the box. Use gr()
to recover if that command is issued.
- Binder. Binder is a free service for small images though it can be very tempermental. Binder has an inactivity time out of a few minutes. Two images are available, the one without
SymPy
loads much faster and would typically suffice, though has no symbolic capabilities.
These notes are broken into different sections, where most all sections have some self-grading questions at the end that allow you to test your knowledge of that material. The code should be copy-and-pasteable into a Julia
session. The code output is similar to what would be shown if evaluated in an IJulia
cell, our recommended interface while learning Julia
, though some may like the Pluto
interface as well.
The notes mostly follow topics of a standard first-semester calculus course after some background material is presented for learning Julia
within a mathematical framework.
Each topic has a lab project. At CSI, sufficient time is allotted to complete these projects during the lab class. These projects are available as IJulia
notebooks or Pluto
notebooks. (There are also Pluto
notebooks with 5-10 minutes of commentary.) Find links for these near the top of each page of notes.
For example, blank notebooks for test taking, etc. are found by following these links:
Lab notebook
A laboratory notebook is a useful tool for keeping notes. One specific for this class is available for printing out: LabNotebook
Questions and Answers
Question and answers are now presented and completed through WeBWorK
. The provided .ipynb
notebooks only contain modest background details and a few examples.
There are a few idiosyncrasies in the WeBWorK
pages to be aware of:
The code examples may be typeset in
WeBWorK
as though they appear in a terminal. A terminal displays the output of each command immediately after execution. In a notebook, when a cell is executed, all the commands are computed and only the last value is shown. (The use of@show
orprint(...)
can be used to display intermediate values in a cell.)Copy and paste from a
WeBWorK
page into a notebook will usually be unsuccessful, as numbers in the font used to display computer markup do not copy as ASCII numbers into a cell. The numbers can be hand edited though.While
Julia
is very happy to express its output using scientific notation,WeBWorK
is not happy to receive the exact output for an answer. Either replacee
withE
(as in1.23e4
would be1.23E4
) or use decimals.For most questions with a numeric answer it is best to copy all 16 digits of output. Several digits are expected to match a correct answer. For numeric questions where an estimate is made, say from a graph, this is significantly relaxed.
If the answer is to be a function, the automatic grader is expecting just the rule of the function (an expression), as in for
f(x) = sin(x)
just entersin(x)
.
Basic ideas
Julia
makes an excellent choice as a computer supplement for this material as its syntax is very similar to standard mathematical syntax. The ability to define mathematical functions using the familiar f(x) = ...
notation makes getting started really easy. Further, the fact that functions are first-class objects means that it is possible to create higher-order Julia
functions that mirror the standard operations of calculus. The following pattern is used throughout:
action(function_object, args...)
For example, the notes use:
plot(f, a, b)
to plotf
over[a,b]
;plot!(g)
to add a curve (usingPlots
)find_zero(f, (a, b))
orfzero(f, a, b)
to find a zero between the bracketing interval[a,b]
(fromRoots
)find_zero(f, a)
(orfzero(f, a)
) to find a zero near an initial starting pointa
(fromRoots
)lim(f, c)
to numerically investigate the limit off
atx=c
.limit(f(x), x=>c)
to find the limit off
atc
(fromSymPy
)f'
to return a function that computes the derivative off
(Added in theMTH229
package based on thederivative
function from theForwardDiff
package)diff(f(x),x)
to find a symbolic derivative off
(fromSymPy
)find_zeros(f, (a, b))
(orfzeros(f, a,b)
) to find all the real zeros of a functionf
in[a,b]
(fromRoots
)sign_chart(f, a, b)
to find and classify zeros of a function over[a,b]
quadgk(f, a, b)
to find the numeric integral off
over(a,b)
(from theQuadGK
package)integrate(f(x), x)
to find the symbolic integral off
(from theSymPy
package)integrate(f(x), (x, a, b))
to find the definite integral over[a,b]
symbolically (from theSymPy
package).
With just this basic set of actions, akin to buttons on the calculator, a rich variety of problems can be addressed.
Installing Julia
on a personal laptop or computer.
Installing Julia
is not terribly difficult, but does involve a few additional steps. Use juliaup
to manage a Julia
installation
On Windows from the command line run
winget install julia -s msstore
On Mac or Linux, from the command line run
curl -fsSL https://install.julialang.org | sh
These two command install juliaup
, which you then run from the command line to install Julia
.
Details on additional packages to install for MTH229 are listed at https://github.com/mth229/MTH229.jl/.
This table covers pros and cons for the approaches mentioned above:
Using server Colab Binder Local Installation
Setup ease ✓ ~ ✓ ×
Speed ✓ ✓ × ✓
Persistence of work × ✓ × ✓
Free ✓ ✓ ✓ ✓
Use at home ✓ ✓ ✓ ✓