# 1.17: 1.17- Frequently-needed Numerical Procedures

- Page ID
- 8096

Many years ago I gradually became aware that there were certain mathematical Equations and procedures that I found myself using over and over again. I therefore set aside some time to write short computer programs for dealing with each of them, so that whenever in the future I needed, for example, to evaluate a determinant, I had a program already written to do it. I show here a partial list of the programs I have for instant use by myself whenever needed. I would suggest that the reader might consider compiling for him- or herself a similar collection of small programs. I have found over the years that they have saved me an immense amount of time and effort. Most programs are very short and required only a few minutes to write (although this depends, of course, on how much programming experience one has), though a few required a bit more effort. Some programs are so short – consisting of a few lines only - that they might be thought to be too trivial to be worth writing. These include, for example, programs for solving a quadratic Equation or for solving two simultaneous linear Equations. Yet I have perhaps used these particularly simple ones more than any others, and they have been of use out of all proportion to the almost negligible effort required to write them. Here, then, is a partial list, and I do suggest that the reader will be repaid enormously over the years if he takes a short time to write similar programs. Of course many or even most of them are readily available in prepackaged programs. But there are enormous advantages in writing your own programs. Quite apart from the extra programming practice that they provide, you know exactly what your own programs do, you can tailor them exactly to your own requirements, you know their strengths and their weaknesses or limitations, and you don’t have to struggle for hours over an instruction manual trying to understand how to use them, only to find in the end that they don’t do exactly what you want.

Solve quadratic Equation

Solve cubic Equation

Solve quintic Equation

Solve \(f(x) = 0\) by Newton-Raphson

Solve \(f(x , y) = 0 \ , \ g(x , y) = 0\) by Newton-Raphson

Tabulate \(y = f(x)\)

Tabulate \(y = f(x , a)\)

Fit least-squares straight line to data

Fit least-squares cubic Equation to data

Solve two simultaneous linear Equations

Solve three simultaneous linear Equations

Solve four simultaneous linear Equations

Solve \(N (>4)\) simultaneous linear Equations in two, three or four unknowns by least squares

Multiply column vector by square matrix

Invert matrix

Diagonalize matrix

Find eigenvectors and eigenvalues of matrix

Test matrix for orthogonality

Evaluate determinant

Convert between rectangular and polar coordinates

Convert between rectangular and spherical coordinates

Convert between direction cosines and Euler angles

Fit a conic section to five points

Numerical integration by Simpson’s rule

Gaussian quadrature

Given any three elements of a plane triangle, calculate the remaining elements

Given any three elements of a spherical triangle, calculate the remaining elements

In addition to these common procedures, there are many others that I have written and have readily to hand that are of more specialized use tailored to my own particular interests, such as

Solve Kepler’s Equation

Convert between wavelength and wavenumber

Calculate \(LS\)-coupling line strengths

Convert between relativity factors such as \(\gamma = 1/\sqrt{1-\beta^2}\)

Likewise, you will be able to think of many formulas special to your own interests that you use over and over again, and it would be worth your while to write short little programs for them.