Practical Julia: A Hands-On Introduction for Scientific Minds

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

earn to use Julia as a tool for research, and solve problems of genuine interest—like modeling the course of a pandemic—in this practical, hands-on introduction to the language. The Julia programming language is acclaimed in scientific circles for its unparalleled ease, interactivity, and speed. Practical Julia is a comprehensive introduction to the language, making it accessible even if you’re new to programming. Julia is a fairly new programming language. It emerged into the public sphere in 2012 after two and a half years of research by four computer scientists at MIT. Julia’s creators explained why they needed to create a new language: they were “greedy.” There were already languages that were fast, such as C and Fortran. They were well suited to writing programs that ran on giant supercomputers to simulate the weather or design airplanes. But their syntax was not the friendliest; programs in these languages demanded a certain amount of ceremony. And they didn’t provide an interactive experience; one could not improvise and explore at the terminal, but had to submit to an edit-compile-run discipline. Dive in with a thorough guide to Julia’s syntax, data types, and best practices, then transition to craft solutions for challenges in physics, statistics, biology, mathematics, scientific machine learning, and more. Whether you’re solving computational problems, visualizing data, writing simulations, or developing specialized tools, Practical Julia will show you how. As you work through the book, you’ll • Use comprehensions and generators, higher-level functions, array initialization and manipulation, and perform operations on Unicode text • Create new syntax and generate code with metaprogramming and macros, and control the error system to manipulate program execution • Visualize everything from mathematical constructs and experimental designs to algorithm flowcharts • Elevate performance using Julia’s unique type system with multiple dispatch • Delve into scientific packages tailored for diverse fields like fluid dynamics, agent-based modeling, and image processing Whether your interest is in scientific research, statistics, mathematics, or just the fun of programming with Julia, Practical Julia will have you writing high-performance code that can do real work in no time.

Author(s): Lee Phillips
Publisher: No Starch Press, Inc.
Year: 2024

Language: English
Pages: 578

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 <: Operator
User-Defined Types
Creating Abstract Types
Creating Composite Types
Using Composite Types
Defining structs with Base.@kwdef
Performance Tips
Vanquish Type Instability
Avoid Changing the Types of Variables
Type Aliases
Parametric Types
Plot Recipes
The Plotting Pipeline
The Series Recipe
The Plot Recipe
Type Recipes
User Recipes
The @userplot Macro
Conclusion
PART II: APPLICATIONS
9 PHYSICS
Bringing Physical Units into the Computer with Unitful
Using Unitful Types
Stripping and Converting Units
Typesetting Units
Plotting with Units
Making Plots for Publication
Error Propagation with Measurements
Fluid Dynamics with Oceananigans
The Physical System
The Grid
The Boundary Conditions
The Diffusivities
The Equation of State
The Model and Initial Conditions
The Simulation
The Results
Solving Differential Equations with DifferentialEquations
Defining the Physics Problem and Its Differential Equation
Setting Up the Problem
Solving the Equation System
Examining the Solutions
Defining Time-Dependent Parameters
Parametric Instability
Combining DifferentialEquations with Measurements
Conclusion
10 STATISTICS
Probability
Random Numbers in Julia
The Monty Hall Problem
Counting
Factorials
Binomial Coefficients
Modeling a Pandemic
Common Statistics Functions
Distributions
The Normal Distribution
Probability Density Functions
Dealing with Data
Missing Values
CSV Files
Dataframes
Multivariate Data
Other Packages
JuliaDB for Out of Core Datasets
RCall for Interacting with R
P-hacking
Conclusion
11 BIOLOGY
The Julia Biology Ecosystem
Simulating Evolution with Agent-Based Modeling
Overview of the Simulation Problem
The Predator and Prey Agents
Constants Defining Model Behavior
Utility Functions
Model Initialization
Functions to Extract Information from the Model
Stepping Through the Simulation
Running the Simulation
Visualizing System Behavior
Analyzing the Results
Conclusion
12 MATHEMATICS
Symbolic Mathematics
Numerical-Symbolic Modeling with Symbolics
Math Manipulation with SymPy and Pluto
Linear Algebra
Views
Linear Algebra Examples
The LinearAlgebra Package
Specialized Matrix Types
Equation Solving and factorize()
Conclusion
13 SCIENTIFIC MACHINE LEARNING
Automatic Differentiation in a Physics Problem
Differentiating with ForwardDiff
Calculating Forces from Potentials
Probabilistic Programming
Testing for Fairness of a Coin
Inferring Model Parameters from Series Observations
Conclusion
14 SIGNAL AND IMAGE PROCESSING
Signals in Time
Exploring a Sound Sample
Analyzing Frequencies
Filtering
Image Processing
Loading and Converting Images
Counting Cells Using an Area Fraction
Counting Cells by Recognizing Features
Applying Advanced Array Concepts
Conclusion
15 PARALLEL PROCESSING
Concurrency Paradigms
Multithreading
Easy Multithreading with Folds
Manual Multithreading with @threads
Spawning and Synchronizing Tasks
Multiprocessing
Easy Multiprocessing with pmap
Networking with Machine Files
Going Manual with @spawnat
Multiprocessing Threads with @distributed
Summary of Concurrency in Julia
Conclusion
INDEX