LogLevel(1001)
69 Getting started with Julia
Julia is a freely available, open-source programming language aimed at technical computing.
As it is open source, indeed with a liberal MIT license, it can be installed for free on many types of computers (though not phones or tablets).
69.1 Running Julia through the web
There are a few services for running Julia
through the web. Mentioned here is Binder, which provides a web-based interface to Julia
built around Jupyter
. Jupyter
is a wildly successful platform for interacting with different open-source software programs.
Clicking the launch link above will open a web page which provides a blank notebook, save for a package used by these notes. However, Binder
is nowhere near as reliable as a local installation.
69.2 Installing Julia locally
Installing Julia
locally is not more difficult than installing other software.
Binaries of Julia
are provided at julialang.org. Julia has an official released version and a developmental version. Unless there is a compelling reason, the latest released version should be downloaded and installed for use.
For Windows users, there is a juliaup
program for managing the installation of Julia.
The base Julia
provides a command-line interface, or REPL (read-evaluate-parse).
69.3 Basic interactive usage
Once installed, Julia
can be started by clicking on an icon or typing julia
at the command line. Either will open a command line interface for a user to interact with a Julia
process. The basic workflow is easy: commands are typed then sent to a Julia
process when the “return” key is pressed for a complete expression. Then the output is displayed.
A command is typed following the prompt. An example might be 2 + 2
. To send the command to the Julia
interpreter the “return” key is pressed. A complete expression or expressions will then be parsed and evaluated (executed). If the expression is not complete, julia
’s prompt will still accept input to complete the expression. Type 2 +
to see. (The expression 2 +
is not complete, as the infix operator +
expects two arguments, one on its left and one on its right.)
__(_)_ | Documentation: https://docs.julialang.org
_ _ | (_) (_) |
(_) | |_ __ _ | Type "?" for help, "]?" for Pkg help.
_ _ _| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.7.0 (2021-11-30)
/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
_|__/ |
> 2 + 2
julia4
Above, julia>
is the prompt. These notes will not include the prompt, so that copying-and-pasting can be more easily used. Input and output cells display similarly, though with differences in coloring. For example:
2 + 2
4
While many prefer a command line for interacting with Julia
, when learning a notebook interfaces is suggested. (An IDE like Julia for Visual Studio Code might be preferred for experienced programmers). In Julia interfaces, we describe two different notebook interfaces that are available through add-on packages.
69.4 Add-on packages
Julia
is well on its way towards 10,000 external add-on packages that enhance the offerings of base Julia
. We refer to one, CalculusWithJulia
, that is designed to accompany these notes. Installation notes are available.
In Julia
graphics are provided only by add-on packages – there is no built-in graphing. This is the case under Pluto
or Jupyter
or the command line.
In these notes, we use the Plots
package and its default backend. The Plots
package provides a common interface to several different backends; this choice is easily changed. The gr
backend is used in these notes, though for interactive use the Plotly
backend has advantages; for more complicated graphics, pyplot
has some advantages; for publication PGFPlotsX
has advantages.
The package, if installed, is loaded as any other package:
using Plots
With that in hand, to make a graph of a function over a range, we follow this pattern:
plot(sin, 0, 2pi)