Article

# Library for linear algebra methods in C#.NET and its application to computational heat transfer

By , 25 May 2005
 Rate this:

## 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
{
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();
}
}
}```

## 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.

A list of licenses authors might use can be found here

No Biography provided

 First Prev Next
 algebra keyreversal 23-Apr-06 11:27
 int RabinNeslo 7-Mar-06 5:08
 Re: int RajkumarJ 28-Mar-06 19:58
 Singular matrix and inversion Grossmogul 15-Feb-06 3:25
 C++ code for nonlinear equations Prasad Indi 30-Jan-06 0:25
 Documentation gmosbo01 29-Nov-05 10:05
 Do you have any documentation to go along with the matrix class and its inversion subroutines. What is the maximum matrix size that the code can handle.   Gary
 Better Herbert Sauro 27-Jun-05 16:40
 Terrible Herbert Sauro 25-May-05 6:48
 Re: Terrible VijayaSekhar Gullapalli 26-May-05 3:58
 Source? stano 13-May-05 0:27
 Last Visit: 31-Dec-99 18:00     Last Update: 8-Mar-14 6:01 Refresh 1