_
_ _ _(_)_ | Documentation: <https://docs.julialang.org>
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.4.2 (2020-05-23)
_/ |\\__'_|_|_|\\__'_| |
|__/ |
julia>|
I have been using the Julia REPL as my day-to-day calculator on the command line for more than a year now. I am surprised that I haven’t seen more posts talking about how powerful and extensible the language is for simple numerical calculations and scripting.
I have tried a dozen of alternatives to Julia before, such as MATLAB/Octave, Python, R, Mathematica, and, very briefly, the more old-school bc and dc calculators, but nothing feels more natural to me than Julia.
Of course, Julia can do simple numerical calculations on numbers, just like any other languages. For example, floating point division,
variables, imaginary numbers,
In [2]
x = ans + 2im
and mathematical functions ().
However, who works with plain numbers these days?
Oftentimes, I need to work with lists of objectsIn Julia’s lingo, it is Array
s, but I would prefer to call it lists. For example, vectors, or lists of numbers, and matrices, which can either be viewed as a list of vectors, or a 2D list of numbers, and sometimes even lists of matrices, lists of higher dimensions, and lists of other objects such as strings or dates.
Julia is a Domain Specific Language (DSL) designed for performing numerical calculations on lists (Of course, it’s much more than this). Many people might have been told that Julia is a performant language, but it is really the syntax of Julia that shines.
Here, I will briefly talk about how I use Julia as calculator on lists. Don’t treat it as a tutorial on how to program, or how to write efficient programs, in Julia. However, hopefully I could show you how to use Julia with syntactically meaningful code. Such skill can be transferred to other languages such as Python or MATLAB, though it might take some work.
The source code is available as a Jupyter notebook on GitHub, though Jupyter’s capability is too limiting for the code examples to work. I would still suggest you work through the examples in a Julia REPL session run from the command line instead.
If you found any mistakes or have any suggestions, comments, etc., please let me know.
I originally came to Julia because its MATLAB-like syntax. For example, you could define a matrix just with the exactly the same syntax as MATLABIt’s not exactly the same, but very close,
or alternatively,
and you could do matrix multiplication like this,
which calculates the matrix product There would be much more noises in the syntax if you try to do the same thing in numpy.
If you already know about MATLAB from either academic or work experiences, you shouldn’t have any trouble picking up Julia. Many of the MATLAB syntax should just work out of the box. For example, you can write a for loop with the traditional MATLAB syntax.
However, Julia is not a MATLAB clone nor compatible with MATLAB, you can find traces of almost every language mentioned above, plus some more, especially Lisp. It might help to think of Julia as an open source, lightweight, extensible MATLAB that looks more like an actual programming language, but keep in mind that it is capable of multiple programming paradigms.