Scientific Computing in Julia
Learn numerical methods in Julia: floating-point error, linear algebra, root finding, interpolation, quadrature, ODEs, optimization and Monte Carlo. Use Base Julia and the LinearAlgebra and Random standard libraries, then assemble and validate a heat-equation simulation with explicit assumptions.
11 projects, 275 hands-on levels, run in your browser.
Syllabus
- Foundations: code through scientific computing: Never written code before? Start here. You will learn the basics of Julia, functions, variables, types, decisions, loops, and arrays, with simple numerical examples. By the end you are ready for Project 1.
- Julia for Scientific Computing: The tools you reach for in every numerical program. Define functions, work with vectors and the broadcasting that makes Julia feel like math, control flow, and the numeric types that scientific code lives on. By the end you can express a formula, sweep it over an array, and reduce the result, fluently.
- Floating Point and Error: Explore Float64 spacing, rounding and cancellation, then compare ordinary, compensated and pairwise sums and finite series. Learn when algebraic rewrites improve a calculation and how to distinguish truncation error, roundoff and conditioning; none of these methods promises exact arithmetic at every scale.
- Linear Algebra: Build real vector and matrix operations, solve systems by substitution and an introductory no-pivot elimination, then compare with the LinearAlgebra standard library. Interpret residuals and conditioning together, keeping array shapes and nonmutation contracts explicit.
- Root Finding: Solve f(x)=0 with brackets, Newton, secant and fixed-point iterations, and evaluate polynomials with Horner's rule. Learn the assumptions behind convergence and report unusable updates or exhausted budgets. Grid scans detect sampled zeros and sign changes; they do not guarantee finding every root.
- Interpolation and Fitting: Data comes as samples; science needs the values in between and the trend underneath. Interpolate with straight lines and Lagrange polynomials to pass exactly through points, then fit a least-squares line that captures the trend through noise. These are the tools that turn a table of measurements into a usable function.
- Numerical Integration: Approximate signed integrals with rectangle, trapezoidal, Simpson and Gaussian rules, then apply them to averages, arc length, areas and work. Compare methods against analytic anchors while accounting for smoothness, panel count, rounding and the limits of estimated-error stopping rules.
- Differential Equations: Build Euler and Runge-Kutta solvers for scalar and coupled ODEs, then model growth, cooling, population interaction, falling velocity and capacitor charge. Compare finite-time solutions with analytic anchors and distinguish stability, truncation error and physical-model assumptions.
- Optimization: Use unimodal interval searches, gradient descent and Newton stationarity steps, then fit a line by minimizing squared error. Learning rates, initial points, smoothness and curvature affect success; an arbitrary callable function is not guaranteed to have a minimum these methods can find.
- Monte Carlo Methods: Build seeded sampling experiments for integrals, distributions, random walks and absorbing boundaries. Distinguish sampled outcomes from theoretical expectations and keep one advancing random stream per experiment. Reproducibility assumes a matching runtime/RNG and draw order; high dimension can still increase variance and cost.
- Capstone: The Heat Equation: Assemble a uniform-grid one-dimensional heat simulator with physical diffusivity, spacing and time step, fixed or insulated boundaries, source rates and independent state histories. Validate weighted heat budgets, steady fields and stability, and distinguish the finite numerical model from a general-purpose physical solver.
Key concepts
- Back substitution: Solving an upper-triangular system by working from the last equation upward: the bottom unknown is immediate, and each earlier one follows by substituting the…
- Bisection method: A root finder for a continuous real function on an interval with opposite endpoint signs, with exact endpoint roots handled separately. Repeated halving shrink…
- Box-Muller transform: Transform independent uniform draws into a standard normal sample using sqrt(-2log(u1)) cos(2pi u2). Require u1>0 before taking log; if the generator can re…
- Broadcasting: Applying a function elementwise over compatible array shapes, using dots such as xs .^ 2 or f.(xs). Nested dotted operations normally fuse without intermediate…
- Catastrophic cancellation: Subtracting nearly equal approximations can magnify their existing errors relative to the small true difference. Factoring a^2-b^2 as (a-b)*(a+b), or using exp…
- CFL condition: The Courant-Friedrichs-Lewy condition relates a numerical domain of dependence to the physical one for propagation problems. The separate explicit diffusion st…
- Coefficient of determination (R-squared): For nonconstant observed y, R-squared=1-SSE/SST compares residual sum of squares with variation around the mean. A perfect fit gives one and the mean predictor…
- Condition number: A measure of sensitivity to input perturbations in a chosen norm. For a nonsingular matrix, cond(A) estimates worst-case relative error amplification in solvin…
- Diffusion: Redistribution down concentration or temperature gradients in the stated model. Zero-flux boundaries conserve the appropriate integral; this mirror-node heat d…
- Discrete Laplacian: On a uniform one-dimensional grid, (u[i-1]-2u[i]+u[i+1])/dx^2 approximates the second spatial derivative. Several introductory helpers return only the unscaled…
- Dot product: For real vectors of equal length, the sum of matching component products. A vector dotted with itself is its squared Euclidean length, so a square root is need…
- Eigenvalue: A scalar lambda for which A v=lambda v for a nonzero vector v. The vector is preserved up to scalar multiplication; negative real lambda reverses its direction…
- Euler's method: Forward Euler advances y by h*f(t,y). It has first-order global truncation error over a fixed duration for sufficiently smooth, stable problems in the asymptot…
- Finite difference: Approximating a derivative by a difference of nearby function values, like (f(x+h) - f(x-h))/(2h) for the first derivative. The basic tool for turning differen…
- Fixed-point iteration: Iteration x_next=g(x). A contraction mapping of a closed interval into itself gives convergence to its unique fixed point in that interval. A numerical derivat…
- Floating point: A finite representation of numbers with limited precision, such as binary Float64. Many decimal values cannot be represented exactly, and arithmetic rounds whe…
- Gaussian elimination: Row elimination reduces a square linear system to triangular form, followed by back substitution. Pivoting selects suitable rows and improves robustness. Julia…
- Gaussian quadrature: Quadrature with chosen nodes and weights giving high polynomial degree of exactness. Two-point Gauss-Legendre integrates polynomials of degree at most three ex…
- Golden-section search: A derivative-free interval reduction for a unimodal one-dimensional objective. Two probes placed using the golden ratio select which portion can be discarded.…
- Gradient: The vector of partial derivatives, giving the direction of steepest increase in the Euclidean norm. At a differentiable unconstrained interior minimum it is ze…
- Gradient descent: An iterative minimizer that steps against the gradient (the direction of steepest increase), scaled by a learning rate: x -> x - lr*grad. The workhorse of m…
- Heat equation: The partial differential equation u_t = alpha*u_xx that governs how heat (or any diffusing quantity) spreads over time. Solved numerically by discretizing spac…
- Horner's rule: Polynomial evaluation by nested multiplication, with coefficients in descending-power order: acc=acc*x+c. It avoids forming every power independently and can c…
- Interpolation: Constructing a function that passes exactly through a set of sample points, then evaluating it between them. Linear interpolation connects samples with straigh…
- Kahan summation: Compensated summation carries a correction for low-order information lost in previous additions. It improves many sums compared with a simple left-to-right loo…
- Lagrange interpolation: For n distinct x nodes, the unique interpolating polynomial has degree at most n-1. Its basis polynomial for one node is one there and zero at the other nodes.…
- Law of large numbers: For independent identically distributed samples with a finite expectation, the sample mean converges to that expectation in the appropriate probabilistic sense…
- Learning rate: The step-size factor in gradient descent. Too small and convergence crawls; too large and the iteration overshoots and diverges. Choosing it well is the centra…
- Least squares: Fitting a model to noisy data by minimizing the sum of squared residuals rather than passing through every point. For a straight line this yields closed-form s…
- Linear regression: For nonconstant x data, ordinary least-squares fitting with an intercept gives a line y=m*x+b minimizing squared residuals. In exact arithmetic it passes throu…
- Linear system: A set of linear equations written Ax = b, asking which vector x the matrix A maps to b. Solving it is the central problem of computational linear algebra, appe…
- Machine epsilon: For Float64, eps(Float64)=2^-52 is the gap from 1.0 to the next larger representable value. Under round-to-nearest, adding a positive amount smaller than half…
- Matrix: A two-dimensional array, written rows-first as [1.0 2.0; 3.0 4.0] . Indexed A[i,j] , sized by size(A,1) and size(A,2) , and central to linear algebra: matrix-v…
- Monte Carlo method: Estimate a quantity from random samples. For independent identically distributed finite-variance observations, the standard error of the sample mean scales as…
- Multiple dispatch: Julia selects a method using the types of all positional arguments. Generic numerical methods can specialize for concrete calls, but dispatch itself is not a t…
- Newton's method: The root update x_next=x-f(x)/f'(x). With sufficient smoothness, a simple root, a suitable nearby start and exact arithmetic, convergence is locally quadra…
- Norm: A measure of a vector's length. The Euclidean (2-) norm is the square root of the sum of squared components; the infinity norm is the largest absolute comp…
- Numerical integration: Approximating a definite integral from sampled function values. Integrals are signed accumulations, not always positive geometric areas. Quadrature error depen…
- Numerical stability: How a numerical method propagates perturbations. For the scalar decay test equation, amplification magnitude below one means strict decay, while equality is a…
- Optimization: Finding the input that minimizes (or maximizes) a function. Methods include derivative-free line searches, gradient descent, and Newton's method; it powers…
- Ordinary differential equation (ODE): An equation relating a quantity to its rate of change, dy/dt = f(t, y), describing motion, decay, growth, and oscillation. Solved numerically by marching the s…
- Random walk: A path made from random increments. For independent symmetric unit steps from zero, mean position is zero and expected squared displacement after n steps is n,…
- RK4: Classical fourth-order Runge-Kutta combines four stage slopes per step, with weights 1,2,2,1. Its fourth-order global accuracy requires suitable smoothness and…
- Root finding: Solving f(x) = 0 for a function f. The core scientific-computing task behind equilibria, intersections, and inverse problems, attacked with bracketing methods…
- Runge-Kutta methods: A family of ODE solvers that sample the slope at several points within a step and combine them for higher accuracy. The classic fourth-order member, RK4, is th…
- Secant method: A root iteration using the slope through the last two sampled points in place of a supplied derivative. It can converge superlinearly near a simple root under…
- Simpson's rule: Composite Simpson quadrature uses weights 1,4,2,...,4,1 over an even number of equal intervals. It integrates polynomials through degree three exactly in exact…
- Stiffness: A numerical problem in which stability forces explicit time steps much smaller than accuracy alone would suggest, often because fast-decaying and slow componen…
- Trapezoidal rule: Integrate straight lines joining adjacent samples, giving endpoint half weights on a uniform grid. It is exact for linear integrands in exact arithmetic and ha…
- Type stability: A function's return type is determined by its input types rather than their values. This can help Julia infer and specialize code. Type stability alone doe…
- Vector: An ordinary Julia Vector is a one-dimensional array with one-based indexing: v[1] is its first entry and v[end] its last. Matrix-vector operations treat it as…