Matrix Hub matrix operation Library C language

Posted by wiztek2000 on Tue, 28 Dec 2021 00:56:30 +0100

Matrix_hub

Matrix operation Library - C language

##The lib of Matrix operation for C language. (matrix operation library – C language)

Author: Amoiensis

Email: Amoiensis@outlook.com

Data:2020.02.12

More information:

https://github.com/Amoiensis/Matrix_hub

Source code download:
release: https://github.com/Amoiensis/Matrix_hub/releases/
Download: https://github.com/Amoiensis/Matrix_hub/releases/download/v1.42/Matrix_Hub_v1.42.zip

Specific application examples:

Optimization algorithm: https://github.com/Amoiensis/Optimization-Algorithm

Specific:

Folder_--_lib_.lib file_+_.h file

Folder_--_code_.c file_+_.h file

CONTENT

####(operation function)

operationOPERATIONfunc_NAME
Generating matrixgenerationMatrix_gen
Copy matrixcopyMatrix_copy
multiplicationmultiplyM_mul
Addition and subtraction methodadd/subM_add_sub
Matrix displayprintM_print
Identity matrix (generation)identity_matrix(gen)M_I
Matrix basic transformationmatrix_element_teransfM_E_trans
Basic transformation matrixElement_trans2MatrixEtrans_2_Matrix
Inverse of basic transformation matrixinv_Element_trans2MatrixEtrans_2_Inverse
Upper triangulationUpper_triangular_transformationM_Uptri_
Upper triangulation (for inversion)Upper_triangular_transformation_for_InverseM_Uptri_4inv
Lower triangulationLower_triangular_transformationM_Lowtri_
Lower triangulation (for inversion)Lower_triangular_transformation_for_InverseM_Lowtri_4inv
Inverse of diagonal matrixMatrix_Inv_for_Dia_matrixM_Dia_Inv
DiagonalizationDiagonalizationM_Diatri_
InversionMatrix_InverseM_Inverse
Matrix row (column) exchangeSwap_LineM_Swap
TransposeTransposeM_T
Cut partial matrixCut_out_part_of_MatrixM_Cut
Free memoryfree_mempry_of_MatrixM_free
tracetraceM_tr
determinantDeterminantM_det
fillFullM_full
normNormM_norm
Absolute value of matrixAbsolute ValueM_abs
Matrix number multiplicationNumber MultiplicationM_numul
Fill matrix (using matrix)Full with matrixM_matFull
Generate (all) zero matrixGeneration Zeros MatrixM_Zeros
Generate (all) one matrixGeneration Ones MatrixM_Ones
Find the corresponding value position of the matrix (column first)Find position with the value in MatrixM_find
Sum of matrix by column / sum of vector elementsMatrix column sum / Vector element sumM_sum
Matrix by column minimum row position / vector minimum element positionMatrix minimum row position / Vector minimum element positionM_min
Maximum row position of matrix by column / maximum element position of vectorMatrix maximum row position / Vector maximum element positionM_max
The value of the specified row position for each column of the matrixThe value of the specified row position
of each column of the matrix
M_minax_val
Comparison between each position of the matrix and the given value (return to the matrix, value 0 / 1)Compare each position of the matrix with the given value
(return the matrix, the value is 0/1)
M_logic_equal
Logical operation of corresponding position of two matricesLogical operation of corresponding positions of two matricesM_logic
Matrix corresponding element multiplication / DivisionMultiply / divide corresponding elements of matrixM_pmuldiv
Matrix batch assignment (using matrix transfer)Matrix batch assignment (using matrix transfer)M_setval
Matrix to matrix, multiply each rowMatrix Number Multiplication (using matrix transfer)M_numul_m
helpHelp Filehelp

[update description]

[Matrix Hub v1.42] 2021.08.06

  1. New maximum eigenvalue function for solving matrix: M_eigen_max(), you can use help("M_eigen_max") to view the specific usage;
  2. New matrix absolute value function M_abs(), you can use help("M_abs") to view the specific usage;
  3. Perfect various norm operations of vectors and matrices M_norm(): new methods such as 1 norm (1), 2 norm (2), infinite norm (INF) and F norm (FRO) are added to correct the calculation error of matrix two norm. You can use help("M_norm") to view the specific use;

[Matrix Hub v1.4] 2021.02.02

  1. Add a help() function. You can enter the name of each function to view the specific use method; For example, help ("help"), help ("Matrix_gen"), help ("README"), help ("Update"), etc;

  2. The new function "M_numul_m()" is used for matrix number multiplication. The matrix operates on the matrix, and each row corresponds to number multiplication;

  3. Replace the original M_ In the matfull() function, the leftmost and uppermost sides are row_up and column_ The left value is set from "0" to "1 (HEAD)";

  4. Correct the miswriting of "Matrix" in the original code and correct it to "Matrix";

Demo (Matrix_hub)

code:

/*
%% IMFORMATION
%% MATRIX_HUB
% Author: Xiping Yu
% Email:Amoiensis@outlook.com
% Github: https://github.com/Amoiensis/Matrix_hub
% Data: 2020.02.24 
% Case: Matrix Operation 
% Dtailed: the code_file of Matrix_hub
*/ 

#include <stdio.h>
#include <stdlib.h>
#include "matrix.h"


int main(int argc, char *argv[]) {
	system("color 0F");
// Matrix
	//	Mat_1
	
	...
	
//	Operation
	// multiplication 
	Matirx*  mat_3 = M_mul(mat_2,mat_1);
	M_print(mat_3);	
	// Addition and subtraction method
	Matirx*  mat_diff = M_add_sub(1,mat_21,1,mat_21b);
	M_print(mat_diff);	
	// Elementary transformation 
	Etrans_struct _Etrans_;
	_Etrans_.minuend_line = 2;
	_Etrans_.subtractor_line = 1;
	_Etrans_.scale = 2;
	_Etrans_.next_E_trans = NULL;
	_Etrans_.forward_E_trans = NULL;
	M_E_trans(mat_2,&_Etrans_,_ROW_);
	M_print(mat_2);
	// Identity matrix 
	M_print(M_I(5));
	// Elementary transformation to matrix 
	Matirx* mat_4 = Etrans_2_Matrix(&_Etrans_,5,_ROW_);
	M_print(mat_4);
	Matirx* mat_5 = Etrans_2_Inverse(&_Etrans_,5,_ROW_);
	M_print(mat_5);
	// Upper triangular transformation
	Uptri_struct* _Uptri_ =  M_Uptri_(mat_21);
	M_print(_Uptri_->trans_matrix );
	M_print(_Uptri_->Uptri_matrix);
	// Lower triangular transformation
	Lowtri_struct* _Lowtri_ =  M_Lowtri_(mat_21);
	M_print(_Lowtri_->Lowtri_matrix);
	M_print(_Lowtri_->trans_matrix);
	// Diagonalization
	Dia_struct* _Dia_ = M_Diatri_(mat_21);
	M_print(_Dia_->trans_leftmatrix);
	M_print(_Dia_->Diatri_matrix);
	M_print(_Dia_->trans_rightmatrix);
	// Matrix inversion 
	Matirx* _mat_inv = M_Inverse(mat_21);
	M_print(_mat_inv );
	// Row column exchange
	M_Swap(_mat_inv,1,2,_ROW_);
	M_print(_mat_inv); 
	// Cutting part
	Matirx* _mat_cut = M_Cut(_mat_inv,_END_,_END_,2,3);
	M_print(_mat_cut);
	// Transpose
	Matirx* _mat_T = M_T(_mat_inv);
	M_print(_mat_T);
	// trace
	MATRIX_TYPE _tr_mat = M_tr(_mat_inv);
	printf("Tr(Matrix_%x) = %.4lf\n",_mat_inv,_tr_mat);
	// determinant
	MATRIX_TYPE _det_mat = M_det(_mat_inv);
	printf("Det(Matrix_%x) = %.4lf\n",mat_21,_det_mat);
	// fill
	Matirx* mat_full = M_full(mat_2,1,1,1,1,0);
	M_print(mat_full);
// Application
	// Solving linear equations
		// mat_A*x = mat_b
	printf("#Solver:mat_A*x = mat_b\n");
	Matirx* _mat_result = M_mul(M_Inverse(mat_A10),mat_b10);
	M_print(_mat_result);
	
//  Others
	M_free(_mat_T);

// Help function
	help("help"); 
	help("Update"); 

	system("pause"); 
	return 0;
}

ATTENTION

Please feel free to contact with me for any questions, thank you!

Don't spread the files without permission!

All documents are for learning and communication only!

Do not spread without permission!

Topics: C