## Mathematical Minimum (for Aspiring Physicists)

### Numerical Solution for 2nd Order Differential Equations

In general, a 2nd order differential equation involves the independent variable x, the dependent variable y, its 1st derivative dy/dx, and the 2nd derivative d(dy/dx)/dx. Numerical solution requires only simple programming whenever we can isolate the 2nd derivative in the form:

d(dy/dx)/dx=f(y',y,x),

where y'=dy/dx=z.

Thus, we can rewrite the original equation as:

dz/dx=f(z,y,x).

In the form of difference equation:

z(n+1)=z(n)+f[z(n),y(n),x(n)]dx

y(n+1)=y(n)+z(n)dx

Input parameters include the step size dx, the number of steps max, and and the initial conditions x(0), y(0), z(0).

Numerical integration is carried out by iteration as shown below (in Basic, also see actual example for a cosmological model):

input max

input dx

input x0

input y0

input z0

n=0

zn=z0

yn=y0

xn=x0

#from the actual expression of the function at x0

fn=f0

MainLoop:

znn=zn+fn*dx

ynn=yn+zn*dx

xnn=xn+dx

n=n+1

if (n-max)=0 then goto Ende

zn=znn

yn=ynn

xn=xnn

#from the actual expression of the function

fn=fnn

print xnn;:print ", ";:print ynn

refresh

goto MainLoop

Ende:

The numerical solution for 1st order differential equation follows the same idea only simpler (see a Basic Program for the Logistic Equation). Other "home-made" programs such as Base Conversion (between decimal, hexadecimal, and binary), Unit Conversion (fps to SI, SI to fps), Mathematical Functions, and Loan Payment (all in Basic) are available (just clicking the link) to show the subtlety of computer programming.
.