Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
J
julia4ever
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Thomas Boy
julia4ever
Commits
1b716e33
Commit
1b716e33
authored
6 years ago
by
br86redu
Browse files
Options
Downloads
Patches
Plain Diff
add cheatsheet
parent
d9b79d52
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
FirstSteps.jl
+155
-0
155 additions, 0 deletions
FirstSteps.jl
with
155 additions
and
0 deletions
FirstSteps.jl
0 → 100644
+
155
−
0
View file @
1b716e33
"""
Setting a working directory with abc
"""
cd
(
"/home/Wherever/You/Want"
)
# Linux
cd
(
"C:
\\
Users
\\
Nickname
\\
Just
\\
put
\\
it
\\
there"
)
# Windows
"""
Show the working directory
"""
pwd
()
"""
Save your files with a .jl to make atom recognize that its Julia
and make the colour formatting appear
"""
"""
Documentation
Any string appearing at the top-level right before an object
is interpreted as documentation (Markdown)
"""
# This is a comment :)
"""
type ? in the REPL to switch to the help menu
type ; in the REPL to switch to the shell
type ] in the REPL to switch to the package management
]st # status of the packages
]update
]add "
Plots
"
or you can do it like this
"""
import
Pkg
Pkg
.
add
(
"StatsBase"
)
# add the package
using
StatsBase
# load the package
Pkg
.
add
(
"Distributions"
)
# add the package
using
Distributions
# load the package
"""
The define operator is =
To use the unicode math symbols (e.g. Greek) type
\a
lpha and press Tab
You cannot redefine a built-in constant or function
"""
pi
a
,
b
,
c
=
1
,
2
,
3
x
=
3
z
=
x
+
a
z1
=
2
x
^
2
-
3
x
+
1
z2
=
2
^
2
x
x
+=
1
d
=
rand
()
# choose a random number between 0 and 1
# randn(10) 10 random numbers- normal distributed
### "===" compare the number and the type of a variable
"""
Define an array
"""
a
=
[
x
,
y
,
z
]
#Array
b
=
rand
(
1
:
10
,
6
)
b
=
rand
(
2
,
2
)
#2×2 Array{Float64,2}
a
=
Array
{
Float64
,
1
}
# Array{T,N} N-dimensional dense array with elements of type T.
# N can be Any, Float64, Int64, String
# T can be 1 - Vector, 2 - Matrix, 3 - Array
c
=
Vector
{
Float64
}(
undef
,
6
)
# create a vector with random numbers (undefined, row, column)
c
=
fill!
(
c
,
3
)
d
=
fill
(
rand
(
1
:
10
),
(
5
,
5
))
g
=
[
1
:
10
;]
#create a vector
g
[
9
]
=
-
9
# change number at pos. 9
g
[
3
:
5
]
=
fill!
(
g
[
3
:
5
],
-
8
)
print
(
g
)
length
(
g
)
size
(
b
)
println
(
"text"
^
2
)
"""
Arithmetic Operators
(+) (-) (/) (*) (^) (%) (\)
For every binary operation there is a "
dot
"-operation that
automatically performs element-by-element on arrays
"""
x
=
3
-
x
#mathematical inverse
+
x
y
%
x
# remainder
x
+=
3
# is like x = x + 3
+
(
1
,
2
,
3
)
*
(
1
,
2
,
3
,
4
)
a
=
[
1
,
2
,
3
]
b
=
a
.+
1
c
=
a
.^
2
"""
build-in mathematical functions
"""
Random
.
seed!
(
123
)
# Setting the seed; using Random, Distributions
d
=
Normal
()
#Normal distribution std=1
x
=
rand
(
d
,
2
)
g
=
[
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
]
sum
(
g
)
mean
(
g
)
# in the Pkg StatsBase
maximum
(
g
)
extrema
(
g
)
"""
- Numeric comparison
- (==) (!=) (<=) ...
"""
x
=
3
x
<
5
?
"yes"
:
"no"
x
=
7
x
<
5
?
"yes"
:
"no"
# Boolean operators
x
>
5
&&
"Cool!"
x
<
5
&&
"Cool!"
x
>
5
||
"Cool!"
x
<
5
||
"Cool!"
# Loop and if-else statments
for
i
in
1
:
length
(
g
)
println
(
"Hallo World (
$
i)"
^
2
)
end
name
=
"Brinkley"
if
name
==
"Jeeves"
println
(
"Very Good Jeeves"
)
elseif
name
==
"Brinkley"
println
(
"Thank you, Brinkley"
)
println
(
"and shut the door behind you"
)
else
println
(
"Fine, just ignore me"
)
end
"""
functions in julia
"""
# one-line function
myfunc
(
value
)
=
20
*
value
myfunc
(
20
)
# more complicated functions
function
First
(
x
,
y
)
x
+
y
end
First
(
3
,
4
)
function
Sec
(
x
,
y
)
return
x
*
y
x
+
y
end
Sec
(
3
,
4
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment