## 1 - Introduction

### Simple Calculations and Variables

Julia can be used as a "pocket calculator". All the usual arithmetic operators and standard mathematical functions are available. Exponentiation is denoted by ^. Mathematical constants such as e or pi are known. The imaginary unit $\sqrt{-1}$ is denoted by im.
Boolean operators &&, ||, and ! work as usual with true and false as logical constants. Boolean comparisons through ==, <, <=, etc.
Comparisons chaining is supported. The end-of-line comment sign is #; inline comments with #= ... =#.

In :
(1 + 2*3 + 3^4 + 4^5) / 10  # no integer division

Out:
111.2

In :
sqrt(-1)

DomainError
while loading In, in expression starting on line 1

in sqrt at math.jl:131
In :
22 < pi^e < e^pi < 24       # chained comparison

Out:
true


Variable names consist of lower and upper case letters, digits, and underscore or (but start with a letter). UTF8 characters are allowed. Julia is case sensitive. A semicolon at the end suppresses printing on the console. When multiplying a variable with a number, the * sign can be left out.

In :
γ = 0.57721_56649_01532_86;  # Euler-Masceroni constant
2γ

Out:
1.1544313298030657


Strings are written with ", character literals with '. The string function will change an object into its string representation. Strings are concatenated with * and duplicated with ^. String interpolation is done with the

In :
"The result of e*pi is " * string(e*pi)

Out:
"The result of e*pi is 8.539734222673566"

In :
println("The result of pi*e is \$(pi*e).")

The result of pi*e is 8.539734222673566.



Rational numbers are represented as m//n and printed in their normalized, i.e. cancelled, form.
They are a subtype of floating point numbers and float(m//n) will convert them to floats.

In :
r = 1//3+ 1//6 + 1//12 + 1//15

Out:
13//20

In :
1//3 - 1/3

Out:
0.0


BigFloat and BigInt examples

In :
factorial(20)

Out:
2432902008176640000


Simple, one-line functions can be defined in a very intuitive way, e.g., f(x) = sin(x) + cos(x).

In :
p(x) = 1 + 2x^2 + 3x^3;  # a polynomial

p(1), p(1.0), p(1im)     # returns a tupel

Out:
(6,6.0,-1 - 3im)


The type hierarchy of numerical types looks like this:

Number
Real
FloatingPoint
BigFloat
Float64 Float32 Float16
Integer
BigInt
Signed
Int128  Int64  Int32  Int16  Int8
--Int--
Unsigned
Uint128 Uint64 Uint32 Uint16 Uint8
Bool
Char
Rational
Complex

### Vectors and matrices

Vectors and matrices are defined in Julia in a very MATLAB-like way.
Array{Float64,1}

In :
v = [1, 2, 3, 4]

Out:
4-element Array{Int64,1}:
1
2
3
4

In :
v, v[2:end]

Out:
(1,[2,3,4])

In :
A = [1.0 2 3 4; 5 6 7 8; 9 10 11 12]

Out:
3x4 Array{Float64,2}:
1.0   2.0   3.0   4.0
5.0   6.0   7.0   8.0
9.0  10.0  11.0  12.0

In :
H12 = [1/(i+j-1) for i in 1:12, j=1:12]
# det(H12)

Out:
12x12 Array{Float64,2}:
1.0        0.5        0.333333   …  0.1        0.0909091  0.0833333
0.5        0.333333   0.25          0.0909091  0.0833333  0.0769231
0.333333   0.25       0.2           0.0833333  0.0769231  0.0714286
0.25       0.2        0.166667      0.0769231  0.0714286  0.0666667
0.2        0.166667   0.142857      0.0714286  0.0666667  0.0625
0.166667   0.142857   0.125      …  0.0666667  0.0625     0.0588235
0.142857   0.125      0.111111      0.0625     0.0588235  0.0555556
0.125      0.111111   0.1           0.0588235  0.0555556  0.0526316
0.111111   0.1        0.0909091     0.0555556  0.0526316  0.05
0.1        0.0909091  0.0833333     0.0526316  0.05       0.047619
0.0909091  0.0833333  0.0769231  …  0.05       0.047619   0.0454545
0.0833333  0.0769231  0.0714286     0.047619   0.0454545  0.0434783

In :
w = A * v

A \ w

Out:
4-element Array{Float64,1}:
1.0
2.0
3.0
4.0