Skip to content

jadecci/numerical_recipes_c

Repository files navigation

<Numerical Recipes in C> Code with Examples

This repository contains code from the book <Numerical Recipes in C> with my comments. The code are contained in a function, which is called in the main function with example inputs. All code can be compiled and run without input parameter.

A set of notes for each chapter/topic is also available on my Github.io blog.

Note that the original code from the book use some tricks with pointers so that indices could start from 1 instead of 0 (Why!). Since I prefer 0-indexing for C/C++, all code in this repository have indicies starting from 0. You are welcome!

Usage

For MacOS player, the code can be compiled by clang util.c file_to_compile.c -o programme. The compiled code can be then run by ./programme.

For Windows player, if gcc is installed, the code can be compiled by gcc util.c file_to_compile.c -o programme. The compiled code can then be run by ./programme.exe.

Content

The code included in this repository, in correspondence to the book's chapters:

Chapter 2 Solution of Linear Algebraic Equations

Notes for this chapter are availablbe at http://jadecci.github.io/notes/C-Chpt2.html

  • Gauss-Jordan Elimination with full pivoting: chpt2_gauss_jordan_full_pivot.c

  • LU Decomposition: chpt2_LU_decomposition.c

  • Cholesky Decomposition: chpt2_cholesky_decomposition.c

  • To add in the future: Singular Value Decomposition, QR Decomposition

Chapter 3 Interpolation and Extrapolation

  • Polynomial

  • Cubic Spline

  • Higher Dimensionality

Chapter 6 Special Functions

  • Gamma, Beta, Factorials, Binomial: chpt6_gamma_bico_beta.c

  • Incomplete Gamma, Error, Chi-Square, Cumulative Poisson

  • Incomplete Beta, Student's, F, Cumulative Binomial

Chapter 7 Random Numbers

  • Uniform Deviates

  • Tranformation: Exponential and Normal Deviates

  • Rejection: Gamma, Poisson, Binomial Deviates

  • Monte Carlo Integration

Chapter 10 Minimisation or Maximisation of Functions

  • Golden Section Search (1D)

  • Parabolic Interpolation and Brent's Method (1D)

  • First Derivatives (1D)

  • Downhill Simplex

  • Direction Set (Powell's)

  • Variable Metric

  • Linear Programming and Simplex Method

Chapter 11 Eigensystems

  • Jacobi Transforms (symmetric matrix)

  • Givens and Householder Reductions

  • Eigenvalues and Eigenvectors of tridiagonal matrix

  • Hermitian

  • Hessenberg Form

  • QR Algorithm for Real Hessenberg Matrices

Chapter 14 Statistical Description of Data

Notes for this chapter are available at http://jadecci.github.io/notes/C-Chpt14.html

  • Moments (mean, variance, skewness, etc.): chpt14_moments.c

  • Distribution comparisons: Student's t-test, F-test, Chi-Square test, Kolmogorov-Smirnov test

  • Linear Correlation

  • Nonparametric/Rank Correlation

  • Comparing 2D Distributions

  • Savitzky-Golay Smoothing Filters

Chapter 15 Modeling of Data

  • Least Squares (MLE)

  • General Linear Least Squares

  • Nonlinear models

About

<Numerical Recipes in C> Codes with Examples

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages