Over a million developers have joined DZone.

Matrix operations: Gaussian elimination, Upper triangulization and Back-substitution example in C


A simple example of matrix operations (Gaussian elimination, Upper triangulization and Back-substitution) which can be used for solving systems of linear equations, or matrix inversion.

/** Gaussian elimination / Upper triangulization / Back-substitution example by Adrian Boeing


void PrintMatrix(double **mat, int m, int n) {
    for (int j=0;j0;p--) { //pivot backwards through all the rows
        for (int r=p-1;r>=0;r--) { //for each row above the pivot
            float multiple = mat[r][p]; //how many multiples of the pivot row do we need (to subtract)?
            for (int c=p-1;c

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}