# Getting started with Julia {{< include ../_common_code.qmd >}} ```{julia} #| echo: false #| results: "hidden" using CalculusWithJulia nothing ``` 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). ## Running Julia through the web There are a few services for running `Julia` through the web. Mentioned here is [Binder](https://mybinder.org), which provides a web-based interface to `Julia` built around `Jupyter`. `Jupyter` is a wildly succesful platform for interacting with different open-source software programs. [lauch binder](https://mybinder.org/v2/gh/CalculusWithJulia/CwJScratchPad.git/master) 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. ## Installing Julia locally Installing `Julia` locally is not more difficult than installing other software. Binaries of `Julia` are provided at [julialang.org](http://julialang.org/downloads/). 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). ## 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.) ```{julia} #| eval: false _ _ _ _(_)_ | Documentation: https://docs.julialang.org (_) | (_) (_) | _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help. | | | | | | |/ _` | | | | |_| | | | (_| | | Version 1.7.0 (2021-11-30) _/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release |__/ | julia> 2 + 2 4 ``` 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: ```{julia} 2 + 2 ``` 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](https://www.julia-vscode.org/) might be preferred for experienced programmers). In [Julia interfaces](./julia_interfaces.html), we describe two different notebook interfaces that are available through add-on packages. ## 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](./calculus_with_julia.html) 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: ```{julia} using Plots ``` With that in hand, to make a graph of a function over a range, we follow this pattern: ```{julia} plot(sin, 0, 2pi) ```