Practical Julia: A Hands-On Introduction for Scientific Minds
9781718502765, 9781718502772
earn to use Julia as a tool for research, and solve problems of genuine interest—like modeling the course of a pandemic—
126
57
31MB
English
Pages 578
Year 2024
Report DMCA / Copyright
DOWNLOAD EPUB FILE
Table of contents :
Cover Page
Title Page
Copyright Page
Dedication Page
About the Author
About the Technical Reviewer
BRIEF CONTENTS
CONTENTS IN DETAIL
ACKNOWLEDGMENTS
INTRODUCTION
Why Is Julia Popular with Scientists?
What Will This Book Do for You?
How to Use This Book
Book Overview
PART I: LEARNING JULIA
1 GETTING STARTED
Installation Guide
Hardware Requirements
Prerequisites
Julia Versions
Installation
Privacy Note
The Julia Coding Environment
The Julia REPL
Text Editors
Jupyter Notebooks
Pluto: A Better Notebook
Integrated Development Environments
Recommendations
2 LANGUAGE BASICS
The Syntax: Data Types, Expressions, and Blocks
Types of Numbers
Operations and Expressions
Logic
Looping: while Blocks
if Blocks
Arrays
Ranges
Arrays: Beyond the First Dimension
Tuples
Membership
Strings and Characters
Characters
Strings
More Looping: for Blocks
Functions
Composing Functions
Creating Anonymous Functions
Broadcasting
Scope
Scoping Rules for Functions
Scoping Rules for Loops
Modification of Scoping Rules in Interactive Contexts
Mutability
Functions That Mutate Their Arguments
Strings Are Immutable
Comments in Code
Congratulations
3 MODULES AND PACKAGES
Modules
Understanding Namespaces
Using Installed Modules
Selective Importing and Renaming
Creating Modules
Documenting Functions with Docstrings
The Package System
How to Add and Remove Packages
The Load Path
The Nature of a Package
The Benefits of Packages
How to Create Packages
Julia and Git
The Relationship Between Package Versions and Git Commits
Version Updating and Pinning
How to Find Public Packages
Conclusion
4 THE PLOTTING SYSTEM
Plots
The Backend System
Modes of Interaction with Plots
2D Plots
Plotting from Vectors
Plotting Functions
Plotting Vectors of Vectors or Functions
Displaying and Mutating
Creating Parametric Plots
Making Polar Plots
Making Scatterplots
Optional and Keyword Arguments
Basic Plot Settings
Font Attributes
The Frame Styles
Working with Plot Settings
Aspect Ratio and Title Font Size
Labels and Legend Positioning
LaTeX Titles and Label Positioning by Data
Regression Lines
Saving Plots
Detail Insets
3D Plots
Surface Plots
Heatmaps
Contour Plots
3D Parametric Plots
Vector Plots
3D Scatterplots
Useful Backends
UnicodePlots
PyPlot
PlotlyJS
PGFPlots and PGFPlotsX
HDF5
Gaston
Layouts
Making Simple Rectangular Layouts
Using grid()
Creating Complex Layouts Using @layout
Conclusion
5 COLLECTIONS
Controlling Loop Execution
The break Statement
The continue Statement
Comprehensions and Generators
More Ways to Join Strings
Nonstandard String Literals
Raw Strings
Semantic Version Strings
Byte Array Literals
String Searching and Replacing
String Interpolation
Additional Collection Types
Dictionaries
Sets
Structs
Named Tuples
Initializing Arrays with Functions
The repeat() Function
The fill() Function
Mutability with the fill() and repeat() Functions
The zeros() and ones() Functions
The reshape() Function
Array Manipulations Useful in Numerical Algorithms
General Concatenation
Logical Indexing
Adjoints and Transposes
Matrix Multiplication
Enumeration and Zipping
The enumerate() Function
The pairs() Function
The zip() Function
Conclusion
6 FUNCTIONS, METAPROGRAMMING, AND ERRORS
Functions and Their Arguments
Concise Syntax for Keyword Arguments
The Splat and Slurp Operators
Destructuring
Operators Are Functions Too
The Mapping, Filtering, and Reduction Operators
do Blocks
Symbols and Metaprogramming
Expression Objects
Expression Object Interpolation
Macros
How to Create Macros
Useful Macros
Error Handling
Types of Errors
The Call Stack
try...catch Blocks
Using throw()
The finally Clause
Conclusion
7 DIAGRAMS AND ANIMATIONS
Diagramming with Luxor
The Graphs Package
The Adjacency Matrix
Factor Trees
Animations with Javis
Closures
Epicycle Animation
Animations with Reel
Interactive Visualizations in Pluto
Conclusion
8 THE TYPE SYSTEM
Types in Practice
“Big” and Irrational Types
Type Promotion
Collections
The Type Hierarchy
Type Assertions and Declarations
Functions and Methods: Multiple Dispatch
Creating Multiple Methods
Extending Built-in Functions with New Methods
Understanding Union Types and the