edu.mines.jtk.la
Class TridiagonalFMatrix

java.lang.Object
  extended by edu.mines.jtk.la.TridiagonalFMatrix

public class TridiagonalFMatrix
extends java.lang.Object

A tridiagonal matrix is a square matrix specified by three diagonals. All elements except for those on the diagonal, lower sub-diagonal, and upper super-diagonal of the matrix are equal to zero. The diagonals are represented by three arrays a, b, and c of matrix elements. Here is an example of a tridiagonal system of n = 4 equations:


  |b[0]    c[0]     0       0  | |u[0]|     |r[0]|
  |a[1]    b[1]    c[1]     0  | |u[1]|  =  |r[1]|
  | 0      a[2]    b[2]    c[2]| |u[2]|     |r[2]|
  | 0       0      a[3]    b[3]| |u[3]|     |r[3]|
 
The values a[0] and c[n-1] are ignored.

Version:
2006.12.12
Author:
Dave Hale, Colorado School of Mines

Constructor Summary
TridiagonalFMatrix(int n)
          Constructs a tridiagonal matrix with the specified number of rows.
TridiagonalFMatrix(int n, float[] a, float[] b, float[] c)
          Constructs a new tridiagonal matrix with specified elements.
 
Method Summary
 float[] a()
          Returns the array a of lower sub-diagonal elements.
 float[] b()
          Returns the array b of diagonal elements.
 float[] c()
          Returns the array c of upper sub-diagonal elements.
 int n()
          Returns the number of rows and columns in this matrix.
 void solve(float[] r, float[] u)
          Solves this tridiagonal system for specified right-hand-side.
 float[] times(float[] x)
          Multiplies this matrix by the specified column vector.
 void times(float[] x, float[] y)
          Multiplies this matrix by the specified column vector.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TridiagonalFMatrix

public TridiagonalFMatrix(int n)
Constructs a tridiagonal matrix with the specified number of rows. All matrix elements are initially zero.

Parameters:
n - the number of rows (and columns) in the matrix.

TridiagonalFMatrix

public TridiagonalFMatrix(int n,
                          float[] a,
                          float[] b,
                          float[] c)
Constructs a new tridiagonal matrix with specified elements. The arrays a, b, and c are passed by reference, not by copy.

Parameters:
n - the number of rows (and columns) in the matrix.
a - array of lower sub-diagonal elements; a[0] is ignored.
b - array of diagonal elements.
c - array of upper super-diagonal elements; c[n-1] is ignored.
Method Detail

n

public int n()
Returns the number of rows and columns in this matrix.

Returns:
the number of rows and columns.

a

public float[] a()
Returns the array a of lower sub-diagonal elements.

Returns:
the array a; by reference, not by copy.

b

public float[] b()
Returns the array b of diagonal elements.

Returns:
the array b; by reference, not by copy.

c

public float[] c()
Returns the array c of upper sub-diagonal elements.

Returns:
the array c; by reference, not by copy.

solve

public void solve(float[] r,
                  float[] u)
Solves this tridiagonal system for specified right-hand-side. Uses Gaussian elimination without pivoting, and assumes that this matrix is non-singular.

Parameters:
r - input array containing the right-hand-side column vector.
u - output array containing the left-hand-side vector of unknowns.

times

public float[] times(float[] x)
Multiplies this matrix by the specified column vector.

Parameters:
x - input array containing the column vector.
Returns:
array containing the matrix-vector product.

times

public void times(float[] x,
                  float[] y)
Multiplies this matrix by the specified column vector.

Parameters:
x - input array containing the column vector.
y - output array containing the matrix-vector product.