## Introduction

This article presents a library developed in Microsoft VC#.NET, which contains methods used in linear algebra. Methods for inversion of matrices, finding determinant and solving linear systems are presented here. The advantages of using an object oriented language for computational problems is also discussed here.

## Background

I was developing a mathematical library for computational methods for fluid flow, where I needed a linear algebra module for solving the formulations made by finite volume methods. Due to the relative simplicity of the Gaussian elimination scheme, I decided to use it and I could achieve reasonable speed in solving large sparse systems. The time taken is proportional to the square of the unknowns.

## Using the code

As described above, the matrix is represented by a two dimensional `double`

array. The following code snippet gives an example of how to use the library. Consider a simple system of linear equations:

2a + b + 3c = 26
a + 10b + c = 48
7a + 2b + c = 28

The following code snippet is used to solve the simple system. The unique solution is obtained as `a=2`

, `b=4`

and `c=6`

. The methods in the library are efficient for systems of size 300. I usually use them for systems of size 75-100 in my application:

using System;
namespace LinearAlgebra
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
double[,] DATA = {{2,1,3},{1,10,1},{7,2,1}};
Matrix COF = new Matrix(DATA);
Matrix CON = new Matrix(3,1);
CON[0,0]=26;CON[1,0]=48;CON[2,0]=28;
Console.WriteLine ("Determinent of COF matrix = " +
COF.Det().ToString() );
Matrix Sol = COF.Inverse()*CON;
Sol.Display();
Console.Read();
}
}
}

## Example – Steady state heat conduction

As described above, the library is used to solve a steady state heat conduction problem. The problem set up is shown below:

A uniform mesh of size 10*5 is adopted. The linear system of equation is developed using the steady state heat conduction with convection at all boundaries. The convective heat transfer coefficient is taken as 10 W/m² K and thermal conductivity is taken as 4 W/m K. The equation system is solved and the results are written to a text file. The temperature distribution is then plotted using the MATLAB software. Given below is the comparison of results obtained using this library and the FEMLAB software.

The temperature distribution in the bottom edge of the slab is also compared.

The minor difference in the temperatures is due to the sparse grid adopted in the program.

## Conclusion

There are many advantages that I have observed in using an object oriented language like C# for computational problems. For example, the nodal points in a mesh can be defined as objects with coordinates and topology as properties. The type of the nodes, for example, whether the node is internal or a boundary node, the type of boundary conditions etc. can also be added as properties. In pipe network simulation programs, the different components can be derived from, say, a `Branch`

class, which simplifies the code to a large extent.