Julia 1.0 Programming
eBook - ePub

Julia 1.0 Programming

Dynamic and high-performance programming to build fast scientific applications, 2nd Edition

Ivo Balbaert

Buch teilen
  1. 196 Seiten
  2. English
  3. ePUB (handyfreundlich)
  4. Über iOS und Android verfügbar
eBook - ePub

Julia 1.0 Programming

Dynamic and high-performance programming to build fast scientific applications, 2nd Edition

Ivo Balbaert

Angaben zum Buch
Buchvorschau
Inhaltsverzeichnis
Quellenangaben

Über dieses Buch

Enter the exciting world of Julia, a high-performance language for technical computing

Key Features

  • Leverage Julia's high speed and efficiency for your applications
  • Work with Julia in a multi-core, distributed, and networked environment
  • Apply Julia to tackle problems concurrently and in a distributed environment

Book Description

The release of Julia 1.0 is now ready to change the technical world by combining the high productivity and ease of use of Python and R with the lightning-fast speed of C++. Julia 1.0 programming gives you a head start in tackling your numerical and data problems. You will begin by learning how to set up a running Julia platform, before exploring its various built-in types. With the help of practical examples, this book walks you through two important collection types: arrays and matrices. In addition to this, you will be taken through how type conversions and promotions work.

In the course of the book, you will be introduced to the homo-iconicity and metaprogramming concepts in Julia. You will understand how Julia provides different ways to interact with an operating system, as well as other languages, and then you'll discover what macros are. Once you have grasped the basics, you'll study what makes Julia suitable for numerical and scientific computing, and learn about the features provided by Julia. By the end of this book, you will also have learned how to run external programs.

This book covers all you need to know about Julia in order to leverage its high speed and efficiency for your applications.

What you will learn

  • Set up your Julia environment to achieve high productivity
  • Create your own types to extend the built-in type system
  • Visualize your data in Julia with plotting packages
  • Explore the use of built-in macros for testing and debugging, among other uses
  • Apply Julia to tackle problems concurrently
  • Integrate Julia with other languages such as C, Python, and MATLAB

Who this book is for

Julia 1.0 Programming is for you if you are a statistician or data scientist who wants a crash course in the Julia programming language while building big data applications. A basic knowledge of mathematics is needed to understand the various methods that are used or created during the course of the book to exploit the capabilities that Julia is designed with.

Häufig gestellte Fragen

Wie kann ich mein Abo kündigen?
Gehe einfach zum Kontobereich in den Einstellungen und klicke auf „Abo kündigen“ – ganz einfach. Nachdem du gekündigt hast, bleibt deine Mitgliedschaft für den verbleibenden Abozeitraum, den du bereits bezahlt hast, aktiv. Mehr Informationen hier.
(Wie) Kann ich Bücher herunterladen?
Derzeit stehen all unsere auf Mobilgeräte reagierenden ePub-Bücher zum Download über die App zur Verfügung. Die meisten unserer PDFs stehen ebenfalls zum Download bereit; wir arbeiten daran, auch die übrigen PDFs zum Download anzubieten, bei denen dies aktuell noch nicht möglich ist. Weitere Informationen hier.
Welcher Unterschied besteht bei den Preisen zwischen den Aboplänen?
Mit beiden Aboplänen erhältst du vollen Zugang zur Bibliothek und allen Funktionen von Perlego. Die einzigen Unterschiede bestehen im Preis und dem Abozeitraum: Mit dem Jahresabo sparst du auf 12 Monate gerechnet im Vergleich zum Monatsabo rund 30 %.
Was ist Perlego?
Wir sind ein Online-Abodienst für Lehrbücher, bei dem du für weniger als den Preis eines einzelnen Buches pro Monat Zugang zu einer ganzen Online-Bibliothek erhältst. Mit über 1 Million Büchern zu über 1.000 verschiedenen Themen haben wir bestimmt alles, was du brauchst! Weitere Informationen hier.
Unterstützt Perlego Text-zu-Sprache?
Achte auf das Symbol zum Vorlesen in deinem nächsten Buch, um zu sehen, ob du es dir auch anhören kannst. Bei diesem Tool wird dir Text laut vorgelesen, wobei der Text beim Vorlesen auch grafisch hervorgehoben wird. Du kannst das Vorlesen jederzeit anhalten, beschleunigen und verlangsamen. Weitere Informationen hier.
Ist Julia 1.0 Programming als Online-PDF/ePub verfügbar?
Ja, du hast Zugang zu Julia 1.0 Programming von Ivo Balbaert im PDF- und/oder ePub-Format sowie zu anderen beliebten Büchern aus Computer Science & Programming Languages. Aus unserem Katalog stehen dir über 1 Million Bücher zur Verfügung.

Information

Jahr
2018
ISBN
9781788990059

Variables, Types, and Operations

Julia is an optionally typed language, which means that the user can choose to specify the type of arguments passed to a function and the type of variables used inside a function. Julia's type system is the key for its performance; understanding it well is important, and it can pay off to use type annotations, not only for documentation or tooling, but also for execution speed. This chapter discusses the realm of elementary built-in types in Julia, the operations that can be performed on them, as well as the important concepts of types and scope.
The following topics are covered in this chapter:
  • Variables, naming conventions, and comments
  • Types
  • Integers
  • Floating point numbers
  • Elementary mathematical functions and operations
  • Rational and complex numbers
  • Characters
  • Strings
  • Regular expressions
  • Ranges and arrays
  • Dates and times
  • Scope and constants
You will need to follow along by typing in the examples in the REPL, or executing the code snippets in the code files of this chapter.

Variables, naming conventions, and comments

Data is stored in values such as 1, 3.14, and "Julia", and every other value has a type, for example, the type of 3.14 is Float64. Some other examples of elementary values and their data types are 42 of the Int64 type, true and false of the Bool type, and 'X' of the Char type.
Julia, unlike many modern programming languages, differentiates between single characters and strings. Strings can contain any number of characters, and are specified using double quotes—single quotes are only used for a character literal. Variables are the names that are bound to values by assignments, such as x = 42. They have the type of the value they contain (or reference); this type is given by the typeof function. For example, typeof(x) returns Int64.
The type of a variable can change, because putting x = "I am Julia" now results in typeof(x) returning String. In Julia, we don't have to declare a variable (that indicates its type) such as in C or Java, for instance, but a variable must be initialized (that is, bound to a value) so that Julia can deduce its type:
julia> y = 7 7  typeof(y) # Int64 julia> y + z ERROR: UndefVarError: z not defined 
In the preceding example, z was not assigned a value before we used it, so we got an error. By combining variables through operators and functions such as the + operator (as in the preceding example), we get expressions. An expression always results in a new value after computation. Contrary to many other languages, everything in Julia is an expression, so it returns a value. That's why working in a REPL is so great: because you can see the values at each step.
The type of variables determines what you can do with them, that is, the operators with which they can be combined with. In this sense, Julia is a strongly typed language. In the following example, x is still a String value, so it can't be summed with y, which is of type Int64, but if we give x a float value, the sum can be calculated, as shown in the following example:
julia> x + y ERROR: MethodError: no method matching +(::String, ::Int64) julia> x = 3.5; x + y 10.5 
Here, the semicolon (;) ends the first expression and suppresses its output. Names of the variables are case-sensitive. By convention, lowercase is used with multiple words separated by an underscore. They start with a letter and, after that, you can use letters, digits, underscores, and exclamation points. You can also use Unicode characters. Use clear, short, and to-the-point names. Here are some valid variable names: mass, moon_velocity, current_time, pos3, and ω1. However, the last two are not very descriptive, and they should better be replaced with, for example, particle_position and particle_ang_velocity.
A line of code preceded by a hash sign (#) is a comment, as we can see in the following example:
# Calculate the gravitational acceleration grav_acc: gc = 6.67e-11 # gravitational constant in m3/kg s2 mass_earth = 5.98e24 # in kg radius_earth = 6378100 # in m grav_acc = gc * mass_earth / radius_earth^2 # 9.8049 m/s2  
Multiline comments are helpful for writing comments that span across multiple lines or commenting out code. In Julia, all lines between #= and =# are treated as a comment. For printing out values, use the print or println functions, as follows:
julia> print(x) 3.5 
If you want your printed output to be in color, use printstyled("I love Julia!", color=:red), which returns the argument string in the color indicated by the second argument.
The term object (or instance) is frequently used when dealing with variables of more complex types. However, we will see that, when doing actions on objects, Julia uses functional semantics. We write action(object) instead of object.action(), as we do in more object-oriented languages such as Java or C#.
In a REPL, the value of the last expression is automatically displayed each time a statement is evaluated (unless it ends with a ; sign). In a standalone script, Julia will not display anything unless the script specifically instructs it to. This is achieved with a print or println statement. To display any object in the way the REPL does in code, use display(object) or show(object) (show is a basic function that prints a text representation of an object, which is often more specific than print).

Types

Julia's type system is unique. Julia behaves as a dynamically typed language (such as Python, for instance) most of the time. This means that a variable bound to an integer at one point might later be bound to a string. For example, consider the following:
julia> x = 10 10 julia> x = "hello" "hello" 
However, one can, optionally, add type information to a variable. This causes the variable to only accept values that match that specific type. This is done through a type of annotation. For instance, declaring x::String implies that only strings can be bound to x; in general, it looks like var::TypeName. These are used the most often to qualify the arguments a function can take. The extra type information is useful...

Inhaltsverzeichnis