Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Getting started with Julia Programming Language
  • Table Of Contents Toc
Getting started with Julia Programming Language

Getting started with Julia Programming Language

By : Ivo Balbaert
4.1 (17)
close
close
Getting started with Julia Programming Language

Getting started with Julia Programming Language

4.1 (17)
By: Ivo Balbaert

Overview of this book

This book is for you if you are a data scientist or working on any technical or scientific computation projects. The book assumes you have a basic working knowledge of high-level dynamic languages such as MATLAB, R, Python, or Ruby.
Table of Contents (14 chapters)
close
close
12
A. List of Macros and Packages
13
Index

Recursive functions

Functions can be nested, as demonstrated in the following example:

function a(x)
    z = x * 2
    function b(z)
        z += 1
    end
    b(z)
end

d = 5
a(d) #=> 11

A function can also be recursive, that is, it can call itself. To show some examples, we need to be able to test a condition in code. The simplest way to do this in Julia is to use the ternary operator ? of the form expr ? b : c (ternary because it takes three arguments). Julia also has a normal if construct (refer to the Conditional evaluation section of Chapter 4, Control Flow). expr is a condition and if it is true, then b is evaluated and the value is returned, else c is evaluated. This is used in the following recursive definition to calculate the sum of all the integers up to and including a certain number:

sum(n) =  n > 1 ? sum(n-1) + n : n

The recursion ends because there is a base case: when n is 1, this value is returned. Or here is the famous function to calculate the nth Fibonacci number...

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Getting started with Julia Programming Language
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon