# math/misc

You can browse the scripts available in this addon using Trac.

## Installation

`load 'math/misc/name_of_script'`

## Scripts

 amoeba 1.0.0 Nelder-Mead multi-dimensional minimization, aka the amoeba method bigpi 1.0.0 Calculate several digits of pi brent 1.0.0 Brent's method in J contfrac 1.0.0 Continued fraction utilities det 1.0.0 Definitions for determinants fermat 1.0.0 Fermat factorization gamesolver 1.0.0 Find optimal mixed strategies for 2-person games gcd 1.0.0 Calculate GCD integer 1.0.0 Various integer definitions integrat 1.0.0 Various methods for numeric integration jacobi 1.0.0 Jacobi's method for eigenvalues and vectors legendre 1.0.0 Legendre symbol and quadratic residues linear 1.0.0 Solve linear equations makemat 1.0.0 Make various matrices matfacto 1.0.0 Matrix factorization mathutil 1.0.0 Math utilities matutil 1.0.0 Matrix utilities mean 1.0.0 Various means numbers 1.0.0 Various number definitions pollard 1.0.0 Pollard factorizations poly 1.0.0 Polynomial functions primutil 1.0.0 Primes - prime testing programs quatern 1.0.0 Definitions for quaternions rsa 1.0.0 RSA encryption simplex 1.0.0 Simplex method simplexnr 1.0.0 Simplex method spline 1.0.0 Spline utilities svd 1.0.0 Singular value decomposition

### amoeba

Nelder-Mead multi-dimensional minimization, aka the amoeba method

Henry H. Rich, October 2009

### bigpi

Calculate several digits of pi

from Borwein

 bigpi v Calculate pi to different levels of of precision

### brent

Brent's method in J

(from J. Patrick Harrington)

 brent a Adverb to solve f(x) = y0 by Brent's method.

### contfrac

Continued fraction utilities

 contfrac v create continued fraction contfracx v expand continued fraction

### det

Definitions for determinants

 det v Determinants of a matrix by recursive expansion of minors detm v Determinants of square matrix by Gauss elimination

### fermat

Fermat factorization

 fermatfactor v Find factor of n near square root of n using Fermat's method

### gamesolver

Find optimal mixed strategies for 2-person games

Henry H. Rich (HenryHRich@nc.rr.com), April 2005

 solvegame v Find optimal mixed strategies for 2-person games

### gcd

Calculate GCD

 gcd v Greatest common denominator

### integer

Various integer definitions

 inta v Augmented integers inte v Extended integers ints v Symmetric integers intm v Minus integers intn v Normal integers intr v Reflexive integers jint v Complex integers jints c symmetric ints

### integrat

Various methods for numeric integration

 integrate c Numeric integration by Aitken extrapolation on Gauss integrals simpson c Numeric integration by Simpson's method adapt c Numeric integration by adaptive quadrature

### jacobi

Jacobi's method for eigenvalues and vectors

 jacobi v Calculate eigenvalues and vectors using Jacobi's method

### linear

Solve linear equations

 gauss_elimination v Gauss elimination (partial pivoting) gauss_jordan v Gauss-Jordan elimination (full pivoting) gauss_seidel v Solves Ax=B for matrix A, vector B jacobi_iteration v Solves Ax=B for matrix A, vector B

### makemat

Make various matrices

 bandmat v Band matrix in position x from diagonal y cidmat v Counter identity matrix of size y diagmat v Diagonal matrix with y on diagonal hilbertmat v Hilbert matrix of size y ltmat v Lower triangular matrix (of 1's) of size y utmat v Upper triangular matrix (of 1's) of size y

### matfacto

Matrix factorization

 choleski v Choleski decomposition of matrix y lud v LU decomposition of matrix y qrd v QR decomposition of matrix y

### mathutil

Math utilities

 det v Determinant of matrix y mp v Matrix product of x and y powermod a x (n powermod) y computes n|x^y randomint v Random integer in range 0, <: 10^y randomintd v Random integer with y digits timesmod a x (n timesmod) y computes n|x*y

### matutil

Matrix utilities

 diag v Diagonal of matrix invsut v Invert square upper-triangular matrix minors v minors of matrix band v b band M - zero all but x bands of matrix y cond v Condition number of matrix pivot v Pivot at row, column coldrop v Drop cols from M coltake v Take cols from M rowdrop v Drop rows from M rowtake v Take rows from M rowswap v Swap rows i and j rowscale v Multiply row i by n rowshear v Multiply row j by n and add to row i

### mean

Various means

 arithmean v Arithmetic mean of y geomean v Geometric mean of y harmean v Harmonic mean of y commonmean v Common mean of y

### numbers

Various number definitions

 bell v Number of ways of partitioning y things into subsets bernoulli v Bernoulli numbers from 0 to y catalan v Catalan numbers cycles v Table of Stirling cycle numbers (S1) cycle v Number of ways of partitioning n items into k cycles eulers v Table of Eulerian numbers euler v Number of permutations of size n with k ascents fermat v Fermat numbers fibonacci v first y+1 Fibonacci numbers lucas v first y+1 Lucas numbers fibbinet v Calculates nth Fibonacci number using Binet formula subsets v Table of Stirling subset numbers (S2) subset v Number of ways of partitioning n items into k sets tangent v tangent numbers from 0 to y

### pollard

Pollard factorizations

 pollardrho v Pollard rho factorization pollardpm1 v Pollard p-1 factorizaton

### poly

Polynomial functions

 chebyshev_tp v Evaluate Chebyshev T polynomial of order n at x chebyshev_up v Evaluate Chebyshev U polynomial of order n at x chebyshev_tpc v Returns coefficients of Chebyshev T polynomial of order n chebyshev_upc v Returns coefficients of Chebyshev U polynomial of order n legendre_pc v Returns coefficients of legendre polynomial of order n

### primutil

Primes - prime testing programs

 prevprime v Previous prime number to y nextprime v Next prime number after y primeq v Test for prime primesto v Primes up to y carmichaelq v Test composite for Carmichael number inversep v Inverse mod p mersenneq v Test if prime p generates a mersenne prime primepowersto v Generate prime powers up to y smallprimefactors v Get small primefactors from number

### quatern

Definitions for quaternions

real quaternions:

• - stored as real arrays with last dimension of length 4
 qncon v Conjugate qnmul v Multiplication qnrec v Reciprocal qndivl v Division (left quotient) qndivr v Division (right quotient) qndivml v Division (using matrix divide, left quotient) qndivmr v Division (using matrix divide, right quotient) qnpolar v Convert to/from polar form

### rsa

RSA encryption

method:

• P & Q are primes
E is exponent, relatively prime to (P-1)*(Q-1)
D is the inverse of E mod (P-1)*(Q-1)

here:

• the public key is: PQ,E (i.e. a pair of numbers)
the private key is: D

then:

• msg (PQ powermod) E encodes msg
msg (PQ powermod) D decodes msg

### simplex

Simplex method

"Numerical Recipes in C"

example description thanks to Henry H. Rich

 simplex v Simplex method

### simplexnr

Simplex method

This implementation follows Numerical Recipes in C, 2/e,
section 10.8, except that we let the user specify the type of
each constraint rather than expecting the order <: >: =
and we use a similar but refined way of handling degenerate pivots

Henry H. Rich (HenryHRich@nc.rr.com), June 2001

 simplexnr v Run simplex method

### spline

Spline utilities

 cubicspline v Calculate cubic spline interspline v Interpolate spline freespline v Calculate spline aprxspline v Approximate by spline

### svd

Singular value decomposition

for real matrices only

 svd v Singular value decomposition of matrix y

Addons/math/misc (last edited 2012-10-17 21:13:27 by DevonMcCormick)