Julia cheatsheet#
Ways to work in Julia#
REPL (Read-Eval-Print Loop)#
This is the default way to start and run Julia.
Press
]
to enter package management mode; press backspace to leave it.Press Ctrl-C to interrupt execution.
Press Ctrl-D to exit.
Press
?
to enter help mode.Press Up/Down arrows to walk through the command history.
There are other interactive utilities described [in the manual]](https://docs.julialang.org/en/v1/stdlib/InteractiveUtils/).
Jupyter notebook#
Install the IJulia
package, then import it and run IJulia.notebook()
at the REPL to launch a session in a web browser.
You can put multiple lines in a code cell. Press Shift-Enter to execute the cell.
Click the Stop button (square icon) to interrupt execution.
Use
include Pkg
and thenPkg.add
, etc. for package management.
Pluto notebook#
Unlike a Jupyter notebook, a Pluto notebook is reactive in the sense that a change anywhere affects all of the code cells immediately. To use it, install and import the \texttt{Pluto} package, then use \texttt{Pluto.run()} to launch it in a web browser.
Visual Studio Code#
Install the Julia extension and run the REPL in a pane. This option is most like an IDE such as PyCharm or Spyder and has many features to assist with coding.
Basics#
Item/Reference |
Example |
---|---|
Help on a function |
|
|
|
|
|
Comment |
starts with |
|
|
Other defined symbols |
|
Symbols using LaTeX nomenclature |
|
Input and output#
Example |
Package |
|
---|---|---|
|
||
|
||
Scientific notation |
|
|
Complex numbers |
|
|
Constants |
|
|
|
||
Show result |
|
|
Print to screen |
|
|
|
||
|
||
|
Operators#
Example |
|
---|---|
Arithmetic |
|
prefix with dot, or |
|
|
|
Comparison |
|
Logical AND / OR / NOT |
|
|
Errors#
Message/Symptom |
Possible cause |
---|---|
|
Accessed a nonexistent array element |
|
Probably used the wrong number/type of function arguments |
Illegal type conversion, maybe by assigning to an array |
|
“Cannot juxtapose string literal” |
Invalid string construction |
Unexpected array changes |
Use |
Wrong norm |
Used |
Iteration#
Example |
|
---|---|
|
|
|
|
|
|
|
Vectors, matrices, arrays#
Example |
Package |
|
---|---|---|
All ones, all zeros |
|
|
Random elements |
|
|
|
||
Get dimensions |
|
|
|
LinearAlgebra |
|
|
LinearAlgebra |
|
|
||
|
||
|
||
|
||
|
||
Make a copy |
|
Linear algebra#
Example |
Package |
|
---|---|---|
|
||
|
LinearAlgebra |
|
Outer product |
|
|
|
||
|
||
|
LinearAlgebra |
|
|
LinearAlgebra |
|
|
LinearAlgebra |
|
|
LinearAlgebra |
|
|
LinearAlgebra |
|
|
LinearAlgebra |
Major problem types#
Example |
Package |
|
---|---|---|
|
||
|
SparseArrays, IterativeSolvers, Arpack |
|
|
||
|
||
Rootfinding |
|
|
Integration |
|
|
|
||
|
Graphics#
Example |
Package |
|
---|---|---|
|
||
|
||
|
GraphRecipes |
|
|
||
Modify existing plot |
|
|
|
||
Log scales |
|
|
Colors and images |
|