MTH229 with Julia

Author

CSI Math department

Published

June 26, 2024

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:

  • Binder. Binder is a free service for small images; it has an inactivity time out. Two images are available, the one without SymPy loads much faster and would typically suffice, though has no symbolic capabilities.

Run on Binder Run on binder (with SymPy)

Run on Binder w/o SymPy Run on binder (without SymPy)

  • Colab. Google’s colab service allows the free user more computing power than does binder but does require more setup. A means to run Julia through Google’s colab service is shown at https://github.com/mth229/MTH229.jl/.

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:

ipynb (Pluto html)

Questions and Answers

Question and answers are now presented and completed through WeBWorK. The .ipynb notebooks only contain modest background details.

There are a few idiosyncrasies in the WeBWorK pages to be aware of:

  • The code examples are typset 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 or print(...) 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 replace e with E (as in 1.23e4 would be 1.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 enter sin(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 plot f over [a,b]; plot!(g) to add a curve (using Plots)
  • find_zero(f, (a, b)) or fzero(f, a, b) to find a zero between the bracketing interval [a,b] (from Roots)
  • find_zero(f, a) (or fzero(f, a)) to find a zero near an initial starting point a (from Roots)
  • lim(f, c) to numerically investigate the limit of f at x=c.
  • limit(f(x), x=>c) to find the limit of f at c (from SymPy)
  • f' to return a function that computes the derivative of f (Added in the MTH229 package based on the derivative function from the ForwardDiff package)
  • diff(f(x),x) to find a symbolic derivative of f (from SymPy)
  • find_zeros(f, (a, b)) (or fzeros(f, a,b)) to find all the real zeros of a function f in [a,b] (from Roots)
  • sign_chart(f, a, b) to find an classify zeros of a function over [a,b]
  • quadgk(f, a, b) to find the numeric integral of f over (a,b) (from the QuadGK package)
  • integrate(f(x), x) to find the symbolic integral of f (from the SymPy package)
  • integrate(f(x), (x, a, b)) to find the definite integral over [a,b] symbolically (from the SymPy package).

With just this basic set of actions, akin to buttons on the calculator, a rich variety of problems can be addressed.

How to use Julia in MTH 229

Using Julia to complete the projects of MTH 229 can be done in several ways.

Using the juliabox server

CSI students have access to a server that gives access to the jupyter notebooks.

Using binder to run the projects remotely:

Run on Binder Run on binder (with SymPy)

Run on Binder w/o SymPy Run on binder (without SymPy)

These links above allow Julia for MTH229 to be run through the web.

  • binder is a service that runs interactive notebooks through the web. Each notebook is limited in memory and has a 10 minute inactivity timeout. Binder notebooks are not persistent, though they do have a button to save to local storage.

Binder takes about 30ish seconds to load. To save memory and start up time, the setup does not have Plots rather it uses BinderPlots, a stripped down version of Plots. The image without SymPy loads in less time.

Installing Julia on a personal laptop or computer.

Some installation details are at https://github.com/mth229/MTH229.jl/.

Installing Julia is not terribly difficult, but does involve a few additional steps.


This table covers pros and cons for the approaches mentioned above:

                         Using server    Binder       Local Installation
Setup ease                  ✓              ✓                 ×

Speed                       ✓              ×                 ✓

Persistence of work         ×              ×                 ✓

Free                        ✓              ✓                 ✓

Use at home                 ✓              ✓                 ✓