Julia Tutorial - 1: Context and basics

Context

A super fan of Matlab, I’ve used it (mainly the Optimization toolbox) a lot during my PhD study. Later on, after I started my professional job in INRIA and GE, I used mainly C++/C/C#/Python but rarely Matlab. Though Matlab is great, it is, however, too expensive for personal users. That’s why I use often open-source tools such like Numpy, Scipy, Eigen and Maxima in some math-related development works.

I heard the name of Julia in 2017. I felt astonished to learn that this new language combines the interactivity and computational power of Python/Matlab with the speed of C. It is until winter of 2020 that I have time to learn intensively this powerful and promising language. So I would like to share my learning notes here. Stay hungry!

Alt Text

Numbers

For Number type of Julia, this table in figure below presents the common basic types:
Alt Text

I have made a “Knowldge graph” of all data types in Julia and their relations. Below is a chart of all types (nodes) that are related to Numbertype:
Alt Text

My exercise code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#     one '#' symbole for a one-line comment, equal to // in C/C++

#= '#=' + '=#' pair for multi-line comment
similar to '/*'+'*/' pair in C/C++
=#

## as in java, println(xxx) is equivalent to print(xxx + '\n')


######## day 1: Numbers
a = 1
println("a: ", a, ",", typeof(a)) ## Int64 if running on 64-bit CPU, Int32 for 32-bit CPU

aa = UInt8(1) # method to convert to a specific type
println(a == aa)
println(sizeof(a), ", " ,sizeof(aa))

b = 3.2
println("b: ", b, ",", typeof(b))
println(sizeof(b))

c = 1e18
println("c: ", c, ",", typeof(c))

d = 0x3f
println("d: ", d, ",", typeof(d))

e = 0b10
println("e: ", e, ",", typeof(e))

f = 0o057
println("f: ", f, ",", typeof(f))


g = 'x'
println("g: ", g, ",", typeof(g))
println("g-1: ", g-1, ",", typeof(g-1))
println(g == UInt8('x'))
g= convert( UInt8, g) # convert function for converting types
println(g == UInt8('x'))

h = 2 + 3im
println("h: ", h, ", ", typeof(h))


i = 0.5f
println("i: ", i, ", ", typeof(i))

j = Inf - Inf
println("j: ", j, ", ", typeof(j))

k = Inf * 0
println("k: ", k, ", ", typeof(k))

l = 2/0
println("l: ", l, ", ", typeof(l))


m = 6//9

println("m: ", m, ", ", typeof(m))

n = bitstring(65535)
println("n: ", n, ", ", typeof(n))

Below is the output that I got:
Alt Text

Official Website:
https://julialang.org/

Cheat sheet:
https://juliadocs.github.io/Julia-Cheat-Sheet/
https://juliadocs.github.io/Julia-Cheat-Sheet/zh-cn/