Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
najela committed Jan 12, 2014
1 parent 20839ce commit 1720656
Show file tree
Hide file tree
Showing 13 changed files with 1,494 additions and 3 deletions.
340 changes: 340 additions & 0 deletions COPYING

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********** matrix.h ***********/
A basic matrix header file for C programming
/********** matrix.h ***********/
A basic matirx header file for C programming

Author: Acho Arnold
Email: [email protected]
Expand All @@ -21,4 +21,4 @@ https://sourceforge.net/projects/matrix-header/
matrix.h is free software, released under the GNU GPL. Please see the
COPYING file for more information. If you do modify this program,
please tell me about it! Perhaps you've made a good improvement that
I can learn from :)
I can learn from :)
1 change: 1 addition & 0 deletions doc
Submodule doc added at 54d866
58 changes: 58 additions & 0 deletions examples/LU_decomposition.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2013- Acho Arnold
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* A sample program to perfom LU decompostion of a matrix using the
* LU_decompose function */

#include "matrix.h"

int main()
{
Matrix *upper_triangular_matrix, *lower_triangular_matrix;
upper_triangular_matrix = matrix_alloc(3,3);
lower_triangular_matrix = matrix_callalloc(3);
int j,k;

/*Fillin the upper triangular with random numbers less that 3 */
for(j = 0; j<3; j++)
{
for(k = 0; k < 3; k++)
{
upper_triangular_matrix->matrix_entry[j][k] = rand()%6;
}
}

/* Printing the oridginal matrix is */
printf("\tThe oridginal matrix is \n");
matrix_print(upper_triangular_matrix);

/* Carrying out row reduction of the matrix */
LU_decompose( upper_triangular_matrix, lower_triangular_matrix);

/*Printing the row reduced matrix */
printf("\n\tThe upper triangular matrix after LU decomposition is \n");
matrix_print(upper_triangular_matrix);

printf("\n\tThe lower triangular matrix after LU decomposition is \n");
matrix_print(lower_triangular_matrix);

/* Freeing th alocated matrix spaces */
matrix_free(upper_triangular_matrix);
matrix_free(lower_triangular_matrix);

return 0;
}
59 changes: 59 additions & 0 deletions examples/gaus_ellimination.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2013- Acho Arnold
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* A sample program to perfom gauss elimination using the row_reduction
* function */

#include "matrix.h"

int main()
{
Matrix *matrix;
matrix = matrix_alloc(2,3);
Matrix *result;
int i,j,k;

/*Fillin the matrices with random numbers less that 3 */
for(i = 0; i < 1; i++)
{
for(j = 0; j<2; j++)
{
for(k = 0; k < 3; k++)
{
matrix->matrix_entry[j][k] = rand()%3;
}
}
}

/* Printing the oridginal matrix is */
printf("Oridginal matrix is \n");
matrix_print(matrix);

/* Carrying out row reduction of the matrix */
matrix_row_reduce(matrix, matrix->row_size);

/*Printing the row reduced matrix */
printf("\n\tMatrix after row reduction is \n");
matrix_print(matrix);
printf("\n\tColumn matrix of unknowns is\n");
matrix_print_part(matrix, matrix->row_size);

/* Freeing th alocated matrix spaces */
matrix_free(matrix);

return 0;
}
59 changes: 59 additions & 0 deletions examples/matrix_add_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (C) 2013- Acho Arnold
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* A sample program to perfom the addition of two matrices
*/
#include "matrix.h"

int main()
{
Matrix *matrix1 = matrix_alloc(2,2);
Matrix *matrix2 = matrix_alloc(2,2);
Matrix *result = matrix_alloc(2,2);
int j,k;


for(j = 0; j<2; j++)
{
for(k = 0; k < 2; k++)
{
matrix1->matrix_entry[j][k] = rand()%3;
}
}
printf("\n\tMatrix1 is:\n");
matrix_print(matrix1);

for(j = 0; j<2; j++)
{
for(k = 0; k < 2; k++)
{
matrix2->matrix_entry[j][k] = rand()%3;
}
}
printf("\n\tMatrix2 is:\n");
matrix_print(matrix2);

matrix_add(result, matrix1, matrix2);

printf("\n\tThe result matrix of the addition is:\n");
matrix_print(result);

/* Freeing th alocated matrix spaces */
matrix_free(matrix1);
matrix_free(matrix2);
matrix_free(result);
}
48 changes: 48 additions & 0 deletions examples/matrix_inverse.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright (C) 2013 - Acho Arnold
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* A sample program to look for the matrix inverse using the matrix_row_reduce
* function */

#include "matrix.h"

int main()
{
Matrix * matrix = matrix_alloc(3,3);
int j,k;

for(j = 0; j<3; j++)
{
for(k = 0; k < 3; k++)
{
matrix->matrix_entry[j][k] = rand()%3;
}
}

printf("\tThe oridginal matrix is \n");
matrix_print(matrix);

matrix_invert(matrix);

printf("\n\tThe inverse matrix is \n");
matrix_print(matrix);

/* Freeing th alocated matrix spaces */
matrix_free(matrix);

return 0;
}
60 changes: 60 additions & 0 deletions examples/matrix_multiply_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2013- Acho Arnold
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* A sample program to perfom the multiplication of two matrices */

#include "matrix.h"

int main()
{
Matrix *matrix[2];
matrix[0] = matrix_alloc(2,2);
matrix[1] = matrix_alloc(2,2);
Matrix *result;
int i,j,k;

/*Fillin the matrices */
for(i = 0; i < 2; i++)
{
for(j = 0; j<2; j++)
{
for(k = 0; k <2; k++)
{
matrix[i]->matrix_entry[j][k] = rand()%3;
}
}
}

result = matrix_multiply( matrix[0], matrix[1]);

/*Printing the operation just carried out */
printf("\n\tMultiplying\n");
matrix_print(matrix[0]);
printf("\n\twith\n");
matrix_print(matrix[1]);

/*Printing the result matrix of the multiplication */
printf("\n\tGives\n");
matrix_print(result);

/* Freeing th alocated matrix spaces */
for( i =0; i< 2; i++)
{
matrix_free(matrix[i]);
}
matrix_free(result);
}
53 changes: 53 additions & 0 deletions examples/matrix_pow_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (C) 2013- Acho Arnold
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/* A sample program text the "matrix_pow" function*/

#include "matrix.h"

int main()
{
Matrix *matrix;
matrix = matrix_alloc(2,2);
Matrix *result;
int j,k;

/*Fillin the matrices */
for(j = 0; j<2; j++)
{
for(k = 0; k <2; k++)
{
matrix->matrix_entry[j][k] = rand()%3;
}
}

printf("\n\tMatrix A =\n");
matrix_print(matrix);

result = matrix_pow( matrix, 4);

/*Printing the operation just carried out */
printf("\n\tMatrix A raised to the power 4 (ie A^4) =\n");
matrix_print(result);

/* Freeing th alocated matrix spaces */

matrix_free(matrix);
matrix_free(result);

return 0;
}
Loading

0 comments on commit 1720656

Please sign in to comment.