Book Image

Julia 1.0 Programming Complete Reference Guide

By : Ivo Balbaert, Adrian Salceanu
Book Image

Julia 1.0 Programming Complete Reference Guide

By: Ivo Balbaert, Adrian Salceanu

Overview of this book

Julia offers the high productivity and ease of use of Python and R with the lightning-fast speed of C++. There’s never been a better time to learn this language, thanks to its large-scale adoption across a wide range of domains, including fintech, biotech and artificial intelligence (AI). You will begin by learning how to set up a running Julia platform, before exploring its various built-in types. This Learning Path walks you through two important collection types: arrays and matrices. You’ll be taken through how type conversions and promotions work, and in further chapters you'll study how Julia interacts with operating systems and other languages. You’ll also learn about the use of macros, what makes Julia suitable for numerical and scientific computing, and how to run external programs. Once you have grasped the basics, this Learning Path goes on to how to analyze the Iris dataset using DataFrames. While building a web scraper and a web app, you’ll explore the use of functions, methods, and multiple dispatches. In the final chapters, you'll delve into machine learning, where you'll build a book recommender system. By the end of this Learning Path, you’ll be well versed with Julia and have the skills you need to leverage its high speed and efficiency for your applications. This Learning Path includes content from the following Packt products: • Julia 1.0 Programming - Second Edition by Ivo Balbaert • Julia Programming Projects by Adrian Salceanu
Table of Contents (18 chapters)

Installing and working with IJulia

IJulia (https://github.com/JuliaLang/IJulia.jl) is a combination of the Jupyter Notebook interactive environment (http://jupyter.org/) with a Julia language backend. It allows you to work with a powerful graphical notebook (which combines code, formatted text, math, and multimedia in a single document) with a regular REPL. Detailed instructions for installation can be found at the GitHub page for IJulia (https://github.com/JuliaLang/IJulia.jl) and in the Julia at MIT notes (https://github.com/stevengj/julia-mit/blob/master/README.md). Add the IJulia package in the REPL package mode with add IJulia.

Then, whenever you want to use it, start up a Julia REPL and type the following commands:

using IJulia 
notebook()

If you want to run it from the command line, type:

jupyter notebook 

The IJulia dashboard should look as follows:

The IJulia dashboard

You should see the Jupyter logo in the upper-left corner of the browser window. Julia code is entered in the input cells (the input can be multiline) and then executed with Shift + Enter

Here is a small example (ijulia-example.jl):

The output should be something as follows:

An IJulia session example

In the first input cell, the value of b is calculated from a:

a = 5 
b = 2a^2 + 30a + 9 

In the second input cell, we use PyPlot. Install this package with add PyPlot in the REPL package mode, and by issuing using PyPlot in the REPL.

The range(0,stop=5,length=101) command defines an array of 100 equally spaced values between 0 and 5; y is defined as a function of x and is then shown graphically with the plot command, as follows:

using PyPlot 
x = range(0,stop=5,length=101)
y = cos.(2x .+ 5) plot(x, y, linewidth=2.0, linestyle="--") title("a nice cosinus") xlabel("x axis") ylabel("y axis")

Save a notebook in file format (with the .ipynb extension) by downloading it from the menu.