Saturday, September 20, 2008

The LinearEquations Class

The LinearEquations class encapsulates
  1. data structures to store the representation of a set of linear equations and
  2. methods to solve the linear equations.




The elements of the matrix and the vectors are stored in zero-based arrays but the elements at index zero (row zero and column zero for the matrix) are completely ignored by the solution routine.
This is convenient because the formulation routine will produce an equation for every node, the nodal equations are linearly dependent and one of them must be ignored for the set to become linearly independent. We chose to ignore the equation at index zero which is the equation of the ground node.
Also, the coefficients at column zero are the coefficients of the ground voltage which is known to be zero, so we can safely remove the column zero from the matrix and the unknown at index zero from the solution vector.

Internally, the LinearEquations class uses the same two-dimensional array to store the coefficients matrix before the LU factorization and both the L and U matrices after the factorization. Before the factorization, the two-dimensional array is accessible through the property Coefficients and after the factorization it cannot be accessed.
Also, the same array is used to store the RHS vector before the solution and the solution vector after the solution process. Before solving, the array is accessible through the property Rhs, and after the solution it is accessible through the property Solution.

The values of the properties CurrentMatrixState and CurrentVectorContent determine the state of the LinearEquations object.



In state 1, using the Solution property causes an ApplicationException to be thrown.
In state 2, using the Coefficients property or the Solution property causes an ApplicationException to be thrown.
In state 3, using the Coefficients property or the Rhs property causes an ApplicationException to be thrown.

Click here to download the LinearEquationSolver project which includes the LinearEquations class. The project was created and built using the express edition of Visual Studio 2008.
Please note that the class Program was written just to test the other classes, and that it is not intended for reuse. It does not perform any checking on the format of the input file.

No comments: