These programs are supplied for students of MAT342. Others may use them as they see fit. Note that most of them are based on material from several different textbooks—see the individual programs for more information.

Instructions

Clicking on the links below will load the corresponding Octave program into your browser's window; use the back button to return to this page.

To download a program to your computer, hold the Shift key down while clicking on the link. To run the programs (names do not end with ".m") you must make them executable after downloading them. This is done by typing

chmod u+x <program name>

after downloading the program. This need be done only once for each downloaded program. The program can then be run with

./<program name>

Demos

Visualizing Taylor polynomials

This octave program does essentially the same thing as the sequence of MatLab commands given on page 20 of "Numerical Mathematics and Computing" 5th edition, by Cheney and Kincaid, Brooks/Cole, 2004.

Base Conversion

This function accepts a decimal number and and returns the string representation of the number in the specified base. This function only converts to bases between (inclusive) base-2 and base-36. It uses the convention that hexadecimal numbers use of using alphabetic letters to represent values larger than 9.

Round to n decimal places

This function will round a supplied number to a specified number of decimal places.

Estimate π with a Monte Carlo Method

Procedure to estimate π as outlined in the University of Nebraska-Lincoln Physical Chemistry lab's Basics of Monte Carlo Simulations.

Loss of significance

This program demonstrates the lost of precision that occurs when two numbers very close to each other are subtracted. This example uses x and sin(x) for a small value of x.

Solve f(x)=0 with fsolve

Demonstrates the use of the Octave function "fsolve" to solve nonlinear equations in the form f(x) = 0 where x is a vector of one or more unknown values.

Root Finding Algorithms

These functions implement a range of root finding algorithms: bisection, Newton's, secant, fixed point, and Steffensen's. The programs good_newton and bad_newton illustrate that while Newton's method normally has a quadratic rate of convergence when finding a root of f(x), the rate of convergence is only linear if the derivative f'(x) = 0.

Divided Differences

This function computes the divided differences that can be used to construct an interpolating polynomial for the given set of data.

Richardson's Extrapolation

This function implements Richardson's Extrapolation to determine an approximation of f'(x) at a particular value of x. Based on an algorithm on page 185 in "Numerical Mathematics and Computing" 5th Edition, by Cheney and Kincaid, Brooks-Cole, 2004.

Romberg Integration

Based on an algorithm on pages 223 and 224 in "Numerical Mathematics and Computing" 5th Edition, by Cheney and Kincaid, Brooks-Cole, 2004.

Adaptive Simpson's Rule

This function uses an adaptive Simpson's rule to approximate the value of the integral. Notice that this is not very efficient; it is recursive and recomputes many function values that have already been computed. The code in this function is meant to be clear and explain the ideas behind adaptive schemes rather than to be an efficient implementation of one. The program verify_adaptSimp demonstrates that the error is usually within the specified tolerance, but may not be.

Gaussian Quadrature

Estimates integral using Gaussian quadrature. Needs grule.m to compute nodes and weights from Legendre Polynomials.

Gaussian Elimination

Performs Gaussian elimination with partial pivoting on a rectangular matrix.

Backward Solve

Performs a backward solve on the system Ax=b where A has already been reduced by Gaussian elimination.

Tridiagonal Solver

Solves Ax=b where A is a tridiagonal matrix stored in three vectors.

Euler's method for ODEs

This program demonstrates the use of Euler's Method to solve the initial value problem x'(t) = tsin(t), x(0)=1.

Taylor series for ODEs

This program demonstrates the use of Taylor Series to solve the initial value problem x'(t) = tsin(t), x(0)=1.

2nd Order Runge-Kutta (Burden-Faires)

This function implements a 2nd order Runge-Kutta algorithm to solve the initial value problem

dy/dt = f(t,y),      y(t0) = y0.

This particular version is based on the algorithm presented in "Numerical Analysis", 6th Edition, by Burden and Faires, Brooks-Cole, 1997.

2nd Order Runge-Kutta (Cheney-Kincaid)

This function implements a 2nd order Runge-Kutta algorithm to solve the initial value problem

dy/dt = f(t,y),      y(t0) = y0.

This particular version is based on pages 459-461 in "Numerical Mathematics and Computing" 5th Edition, by Cheney and Kincaid, Brooks-Cole, 2004.

4th Order Runge-Kutta for systems of equations

This function implements 4th order Runge-Kutta to solve

dy/dt = f(t,y),      y(t(1)) = y0.

at the t values stored in the t array (so the interval of solution is given by first and last entries in the array for t: [t(1), t(N)]). Notice that it works equally well for scalar functions f(t,y) (in the case of a single 1st order ODE) or for vector functions f(t,y) (in the case of multiple 1st order ODEs).

Runge-Kutta-Fehlberg

This function implements 4th-5th order Runge-Kutta-Fehlberg Method to solve the initial value problem

dy/dt = f(t,y),      y(a) = y0.

on the interval [a,b]. Based on pseudocode presented in "Numerical Analysis", 6th Edition, by Burden and Faires, Brooks-Cole, 1997.

Shooting Method

This function implements the shooting method to solve second-order boundary value problems. It assumes that the second order equation has been converted to a first order system of two equations and uses the built-in Octave function lsode() to solve the initial value problems. The secant method is used to refine the initial values of y' used for the initial value problems.

Finite Difference Method

Compute finite difference solution to the boundary value problem

x'' = u(t) + v(t)x + w(t)x'
x(t(1)) = a,    x(t(n)) = b

on the interval [t(1), t(n)].

Forward Time, Centered Space (FTCS) scheme applied to the Heat Equation

Use the FTCS scheme to solve the heat equation in a thin rod.

Crank Nicolson applied to the Heat Equation

Use Crank-Nicolson scheme to solve the heat equation in a thin rod. Needs the tridiagonal solver.

Finite Difference Solution of Wave Equation

Solves the one-dimensional wave equation.

Finite Difference Solution of Elliptic Helmholtz Problem

Solves the two-dimensional Helmholtz equation on the unit square.

Fibonacci Search

Demonstrates the use of the Fibonacci Search to find the minimum of the unimodal function |sin x| on the interval [2,4].

Golden Section Search

Demonstrates the use of the Golden Section Search to find the minimum of the unimodal function |sin x| on the interval [2,4].

Simulated Annealing in One Dimension

Demonstrates the use of Simulated Annealing to find the minimum of the function x e-x sin 55x on the interval [0,5]. Needs the simulated annealing solver.