HOME

PDF

my Julia programming cheat sheet

Nasser M. Abbasi

September 8, 2023   Compiled on September 8, 2023 at 10:40am

Contents

 1 installing 0.5
 2 installing 0.3
 3 installing 0.2
 4 getting help on functions
 5 How to show plot using Julia studio?
 6 How to find the version number of Julia?
 7 How to upgrade Julia?

1 installing 0.5

see http://julialang.org/downloads/platform.html

I did, on Linux mint, per above:

sudo apt-add-repository ppa:staticfloat/julianightlies 
sudo apt-add-repository ppa:staticfloat/julia-deps 
sudo apt-get update 
sudo apt-get install julia
 

and now

~>julia 
               _ 
   _       _ _(_)_     |  A fresh approach to technical computing 
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org 
   _ _   _| |_  __ _   |  Type "?help" for help. 
  | | | | | | |/ _` |  | 
  | | |_| | | | (_| |  |  Version 0.5.0-dev+1491 (2015-11-27 16:54 UTC) 
 _/ |\__'_|_|_|\__'_|  |  Commit 41fb1ba (54 days old master) 
|__/                   |  x86_64-linux-gnu 
 
julia>
 

2 installing 0.3

Same steps as below for 0.2, from git. After installing I did

>./julia 
               _ 
   _       _ _(_)_     |  A fresh approach to technical computing 
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org 
   _ _   _| |_  __ _   |  Type "help()" to list help topics 
  | | | | | | |/ _` |  | 
  | | |_| | | | (_| |  |  Version 0.3.0-prerelease+4002 (2014-07-01 19:11 UTC) 
 _/ |\__'_|_|_|\__'_|  |  Commit 7e74621 (0 days old master) 
|__/                   |  i686-linux-gnu 
 
julia> Pkg.add("Winston") 
INFO: Initializing package repository /home/me/.julia/v0.3 
INFO: Cloning METADATA from git://github.com/JuliaLang/METADATA.jl 
 using WinstonINFO: Cloning cache of BinDeps from git://github.com/JuliaLang/BinDeps.jl.git 
INFO: Cloning cache of Cairo from git://github.com/JuliaLang/Cairo.jl.git 
INFO: Cloning cache of Color from git://github.com/JuliaLang/Color.jl.git 
INFO: Cloning cache of IniFile from git://github.com/JuliaLang/IniFile.jl.git 
INFO: Cloning cache of Tk from git://github.com/JuliaLang/Tk.jl.git 
INFO: Cloning cache of URIParser from git://github.com/Keno/URIParser.jl.git 
INFO: Cloning cache of Winston from git://github.com/nolta/Winston.jl.git 
INFO: Installing BinDeps v0.2.14 
INFO: Installing Cairo v0.2.13 
INFO: Installing Color v0.2.10 
INFO: Installing IniFile v0.2.2 
INFO: Installing Tk v0.2.13 
INFO: Installing URIParser v0.0.2 
INFO: Installing Winston v0.11.0 
INFO: Building Cairo 
INFO: Building Tk 
INFO: Package database updated 
 
julia>  using Winston 
julia> x = -2pi:0.1:2pi; 
julia> plot(x, sin(x.^2)./x)
 

Here is screen shot

pict

3 installing 0.2

get the source using git

>git clone git://github.com/JuliaLang/julia.git 
Cloning into 'julia'... 
remote: Reusing existing pack: 82408, done. 
remote: Counting objects: 7, done. 
remote: Compressing objects: 100% (7/7), done. 
remote: Total 82415 (delta 2), reused 4 (delta 0) 
Receiving objects: 100% (82415/82415), 27.75 MiB | 4.92 MiB/s, done. 
Resolving deltas: 100% (61567/61567), done. 
Checking out files: 100% (567/567), done. 
>lsd 
drwxrwxrwx 1 me me       0 Jan  7 17:55 ./ 
drwxrwxrwx 1 me me   40960 Jan  6 02:41 ../ 
drwxrwxrwx 1 me me       0 Jan  7 17:56 julia/ 
 
>cd julia/ 
>lsd 
drwxrwxrwx 1 me me     0 Jan  7 17:56 ./ 
drwxrwxrwx 1 me me     0 Jan  7 17:55 ../ 
drwxrwxrwx 1 me me 24576 Jan  7 17:56 base/ 
drwxrwxrwx 1 me me     0 Jan  7 17:56 contrib/ 
drwxrwxrwx 1 me me  8192 Jan  7 17:56 deps/ 
drwxrwxrwx 1 me me     0 Jan  7 17:56 doc/ 
drwxrwxrwx 1 me me     0 Jan  7 17:56 etc/ 
drwxrwxrwx 1 me me     0 Jan  7 17:56 examples/ 
drwxrwxrwx 1 me me     0 Jan  7 17:56 .git/ 
drwxrwxrwx 1 me me 12288 Jan  7 17:56 src/ 
drwxrwxrwx 1 me me 12288 Jan  7 17:56 test/ 
drwxrwxrwx 1 me me     0 Jan  7 17:56 ui/ 
>
 

compile

>make 
Cloning into 'deps/Rmath'... 
remote: Reusing existing pack: 332, done. 
remote: Total 332 (delta 0), reused 0 (delta 0) 
Receiving objects: 100% (332/332), 247.59 KiB, done. 
Resolving deltas: 100% (217/217), done. 
Submodule path 'deps/Rmath': checked out '004e056e4562a8e8459b3d283f7de2f655f99a8b' 
Cloning into 'deps/libuv'... 
remote: Counting objects: 18022, done. 
remote: Compressing objects: 100% (7331/7331), done. 
remote: Total 18022 (delta 10650), reused 18000 (delta 10629) 
Receiving objects: 100% (18022/18022), 10.53 MiB | 3.42 MiB/s, done. 
Resolving deltas: 100% (10650/10650), done. 
Submodule path 'deps/libuv': checked out '5bf16a9b86b2b059b20703d52c1dbba5979b6f5c' 
Cloning into 'deps/openlibm'... 
.... 
/usr/bin/ld: cannot find -lncurses 
collect2: error: ld returned 1 exit status 
*** Please ensure that the ncurses-devel package is installed on your OS, and try again. *** 
make[2]: *** [/home/me/data/julia/usr/bin/julia-readline] Error 1 
make[1]: *** [julia-release] Error 2 
make: *** [release] Error 2 
>
 

so I installed ncurses

>sudo apt-get install ncurses-dev 
[sudo] password for me: 
Reading package lists... Done 
Building dependency tree 
Reading state information... Done 
Note, selecting 'libncurses5-dev' instead of 'ncurses-dev' 
The following extra packages will be installed: 
  libtinfo-dev 
Suggested packages: 
  ncurses-doc 
The following NEW packages will be installed: 
  libncurses5-dev libtinfo-dev 
0 upgraded, 2 newly installed, 0 to remove and 5 not upgraded. 
Need to get 306 kB of archives. 
After this operation, 1,146 kB of additional disk space will be used. 
Do you want to continue [Y/n]? y 
Get:1 http://archive.ubuntu.com/ubuntu/ raring/main libtinfo-dev i386 5.9-10ubuntu4 [93.1 kB] 
Get:2 http://archive.ubuntu.com/ubuntu/ raring/main libncurses5-dev i386 5.9-10ubuntu4 [213 kB] 
Fetched 306 kB in 0s (389 kB/s) 
Selecting previously unselected package libtinfo-dev:i386. 
(Reading database ... 229715 files and directories currently installed.) 
Unpacking libtinfo-dev:i386 (from .../libtinfo-dev_5.9-10ubuntu4_i386.deb) ... 
Selecting previously unselected package libncurses5-dev. 
Unpacking libncurses5-dev (from .../libncurses5-dev_5.9-10ubuntu4_i386.deb) ... 
Setting up libtinfo-dev:i386 (5.9-10ubuntu4) ... 
Setting up libncurses5-dev (5.9-10ubuntu4) ...
 

use g++ -print-search-dirs to find which libraries are searched by g++

>locate libncurses 
/lib/i386-linux-gnu/libncurses.so.5 
/lib/i386-linux-gnu/libncurses.so.5.9 
/lib/i386-linux-gnu/libncursesw.so.5 
/lib/i386-linux-gnu/libncursesw.so.5.9 
/usr/lib/vlc/plugins/gui/libncurses_plugin.so 
/usr/share/doc/libncurses5 
/usr/share/doc/libncursesw5 
/var/lib/dpkg/info/libncurses5:i386.list 
/var/lib/dpkg/info/libncurses5:i386.md5sums 
/var/lib/dpkg/info/libncurses5:i386.postinst 
/var/lib/dpkg/info/libncurses5:i386.postrm 
/var/lib/dpkg/info/libncurses5:i386.shlibs 
/var/lib/dpkg/info/libncurses5:i386.symbols 
/var/lib/dpkg/info/libncursesw5:i386.list 
/var/lib/dpkg/info/libncursesw5:i386.md5sums 
/var/lib/dpkg/info/libncursesw5:i386.postinst 
/var/lib/dpkg/info/libncursesw5:i386.postrm 
/var/lib/dpkg/info/libncursesw5:i386.shlibs 
/var/lib/dpkg/info/libncursesw5:i386.symbols
 

Ok, now try the build of Julia again, just type make again where it was left

>make 
    LINK usr/bin/julia-readline 
    CC ui/repl-basic.o 
    LINK usr/bin/julia-basic 
linalg.jl 
OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance. 
Warning: replacing module Base
 

it worked ! lets try it

>lsd 
drwxr-xr-x 13 me me  4096 Jan  7 20:40 ./ 
drwxr-xr-x  4 me me  4096 Jan  7 19:15 ../ 
drwxr-xr-x  5 me me  4096 Jan  7 20:40 base/ 
drwxr-xr-x  6 me me  4096 Jan  7 19:15 contrib/ 
drwxr-xr-x 20 me me  4096 Jan  7 20:25 deps/ 
drwxr-xr-x  9 me me  4096 Jan  7 19:15 doc/ 
drwxr-xr-x  2 me me  4096 Jan  7 19:15 etc/ 
drwxr-xr-x  2 me me  4096 Jan  7 19:15 examples/ 
drwxr-xr-x  9 me me  4096 Jan  7 20:40 .git/ 
lrwxrwxrwx  1 me me    42 Jan  7 20:40 julia -> /home/me/data/julia/usr/bin/julia-readline* 
drwxr-xr-x  4 me me  4096 Jan  7 20:27 src/ 
drwxr-xr-x  4 me me  4096 Jan  7 19:15 test/ 
drwxr-xr-x  2 me me  4096 Jan  7 20:40 ui/ 
drwxr-xr-x  8 me me  4096 Jan  7 19:16 usr/ 
>which julia 
>./julia 
OpenBLAS : Your OS does not support AVX instructions. OpenBLAS is using Nehalem kernels as a fallback, which may give poorer performance. 
               _ 
   _       _ _(_)_     |  A fresh approach to technical computing 
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org 
   _ _   _| |_  __ _   |  Type "help()" to list help topics 
  | | | | | | |/ _` |  | 
  | | |_| | | | (_| |  |  Version 0.3.0-prerelease+860 (2014-01-07 22:41 UTC) 
 _/ |\__'_|_|_|\__'_|  |  Commit 0258864 (0 days old master) 
|__/                   |  i686-linux-gnu 
 
julia>
 

Let see if it will plot something

To update packages

julia> Pkg.update() 
INFO: Initializing package repository /home/me/.julia 
INFO: Cloning METADATA from git://github.com/JuliaLang/METADATA.jl 
INFO: Updating METADATA... 
INFO: Computing changes... 
INFO: No packages to install, update or remove 
 
 
julia> Pkg.add("PyPlot") 
INFO: Cloning cache of Color from git://github.com/JuliaLang/Color.jl.git 
INFO: Cloning cache of PyCall from git://github.com/stevengj/PyCall.jl.git 
INFO: Cloning cache of PyPlot from git://github.com/stevengj/PyPlot.jl.git 
INFO: Installing Color v0.2.6 
INFO: Installing PyCall v0.3.1 
INFO: Installing PyPlot v1.1.0 
INFO: REQUIRE updated 
 
 
using PyPlot 
ERROR: PyError (PyImport_ImportModule) <type 'exceptions.ImportError'> 
ImportError('No module named matplotlib',) 
 
 in pyerr_check at /home/me/.julia/PyCall/src/exception.jl:58 
 in pyimport at /home/me/.julia/PyCall/src/PyCall.jl:85 
 in reload_path at loading.jl:146 
 in _require at loading.jl:59 
 in require at loading.jl:43 
while loading /home/me/.julia/PyPlot/src/PyPlot.jl, in expression starting on line 32
 

Ok, so the above is no good. Try this now

julia> Pkg.add("Winston") 
INFO: Cloning cache of BinDeps from git://github.com/JuliaLang/BinDeps.jl.git 
INFO: Cloning cache of Cairo from git://github.com/JuliaLang/Cairo.jl.git 
INFO: Cloning cache of IniFile from git://github.com/JuliaLang/IniFile.jl.git 
INFO: Cloning cache of Tk from git://github.com/JuliaLang/Tk.jl.git 
INFO: Cloning cache of URIParser from git://github.com/loladiro/URIParser.jl.git 
INFO: Cloning cache of Winston from git://github.com/nolta/Winston.jl.git 
INFO: Installing BinDeps v0.2.12 
INFO: Installing Cairo v0.2.12 
INFO: Installing IniFile v0.2.2 
INFO: Installing Tk v0.2.10 
INFO: Installing URIParser v0.0.1 
INFO: Installing Winston v0.7.2 
INFO: Building Cairo 
INFO: Building Tk 
INFO: REQUIRE updated 
 
julia> using Winston 
julia> x = -2pi:0.1:2pi; 
julia> plot(x, sin(x.^2)./x)
 

it worked!

pict

4 getting help on functions

use the methods command

julia> methods(plot) 
# 8 methods for generic function "plot": 
plot(p::FramedPlot,x::(Array{T<:Real,1},Array{S<:Real,1}),args...) at /home/me/.julia/Winston/src/plot_interfaces.jl:22 
plot(p::FramedPlot,f::Function,a::Real,b::Real,args...) at /home/me/.julia/Winston/src/plot_interfaces.jl:26 
plot(p::FramedPlot,fs::Array{Function,1},a::Real,b::Real,args...) at /home/me/.julia/Winston/src/plot_interfaces.jl:36 
plot(p::FramedPlot,fs::(Function,Function),a::Real,b::Real,args...) at /home/me/.julia/Winston/src/plot_interfaces.jl:57 
plot(p::FramedPlot,args...) at /home/me/.julia/Winston/src/plot.jl:107 
plot(fs::Array{Function,2},a::Real,b::Real,args...) at /home/me/.julia/Winston/src/plot_interfaces.jl:68 
plot(f::Contourc) at /home/me/.julia/Winston/src/plot_interfaces.jl:317 
plot(args...) at /home/me/.julia/Winston/src/plot.jl:168
 

There is also help, but does not work for all functions like the above

 
julia> help(open) 
Base.open(file_name[, read, write, create, truncate, append]) -> IOStream 
 
julia> ?help 
 
 Welcome to Julia. The full manual is available at 
 
    http://docs.julialang.org 
 
 To get help, try help(function), help("@macro"), or help("variable"). 
 To search all help text, try apropos("string"). To see available functions, 
 try help(category), for one of the following categories: 
 
  "Getting Around" 
  "All Objects" 
  "Types" 
  "Generic Functions" 
  "Syntax" 
  "Iteration" 
  "General Collections" 
  "Iterable Collections" 
  "Indexable Collections" 
  "Associative Collections" 
  "Set-Like Collections" 
  "Dequeues" 
  "Strings" 
  "I/O" 
  "Network I/O" 
  "Text I/O" 
  "Multimedia I/O" 
  "Memory-mapped I/O" 
  "Mathematical Operators" 
  "Mathematical Functions" 
  "Data Formats" 
  "Numbers" 
  "BigFloats" 
  "Random Numbers" 
  "Arrays" 
  "Combinatorics" 
  "Statistics" 
  "Signal Processing" 
  "Numerical Integration" 
  "Parallel Computing" 
  "Distributed Arrays" 
  "System" 
  "C Interface" 
  "Errors" 
  "Tasks" 
  "Events" 
  "Reflection" 
  "Internals" 
  "Collections and Data Structures" 
  "Constants" 
  "Filesystem" 
  "Graphics" 
  "Linear Algebra" 
  "BLAS Functions" 
  "Package Manager Functions" 
  "Profiling" 
  "Sorting and Related Functions" 
  "Sparse Matrices" 
  "Unit and Functional Testing"
 

5 How to show plot using Julia studio?

Need to use display, like this

using Winston 
x=-2pi:0.1:2pi 
display(plot(x,sin(x.^2)./x))
 

On Linux, from terminal, there is not need to use display, but on windows I found that it is needed, else the plot do not show up.

6 How to find the version number of Julia?

julia> VERSION 
v"0.2.0" 
 
julia>
 

To get more information:

julia> versioninfo(true) 
Julia Version 0.2.0 
Commit 05c6461 (2013-11-16 23:44 UTC) 
Platform Info: 
  System: Windows (x86_64-w64-mingw32) 
  WORD_SIZE: 64 
           Microsoft Windows [Version 6.1.7601] 
  uname: MINGW32_NT-6.1 1.0.12(0.46/3/2) 2011-07-20 17:52 i686 unknown 
Memory: 15.925960540771484 GB (8968.46484375 MB free) 
Uptime: 272274.5636161 sec 
Load Avg:  0.0  0.0  0.0
 

7 How to upgrade Julia?

First time you install Julia:

cd .... to where you want Julia folder to be 
git clone git://github.com/JuliaLang/julia.git 
cd julia 
make 
.... go take a long nap....
 

Now, to upgrade Julia anytime after the above, do

git pull && make
 

see updating-an-existing-source-tree