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)
operation | OPERATION | func_NAME |
---|---|---|
Generating matrix | generation | Matrix_gen |
Copy matrix | copy | Matrix_copy |
multiplication | multiply | M_mul |
Addition and subtraction method | add/sub | M_add_sub |
Matrix display | M_print | |
Identity matrix (generation) | identity_matrix(gen) | M_I |
Matrix basic transformation | matrix_element_teransf | M_E_trans |
Basic transformation matrix | Element_trans2Matrix | Etrans_2_Matrix |
Inverse of basic transformation matrix | inv_Element_trans2Matrix | Etrans_2_Inverse |
Upper triangulation | Upper_triangular_transformation | M_Uptri_ |
Upper triangulation (for inversion) | Upper_triangular_transformation_for_Inverse | M_Uptri_4inv |
Lower triangulation | Lower_triangular_transformation | M_Lowtri_ |
Lower triangulation (for inversion) | Lower_triangular_transformation_for_Inverse | M_Lowtri_4inv |
Inverse of diagonal matrix | Matrix_Inv_for_Dia_matrix | M_Dia_Inv |
Diagonalization | Diagonalization | M_Diatri_ |
Inversion | Matrix_Inverse | M_Inverse |
Matrix row (column) exchange | Swap_Line | M_Swap |
Transpose | Transpose | M_T |
Cut partial matrix | Cut_out_part_of_Matrix | M_Cut |
Free memory | free_mempry_of_Matrix | M_free |
trace | trace | M_tr |
determinant | Determinant | M_det |
fill | Full | M_full |
norm | Norm | M_norm |
Absolute value of matrix | Absolute Value | M_abs |
Matrix number multiplication | Number Multiplication | M_numul |
Fill matrix (using matrix) | Full with matrix | M_matFull |
Generate (all) zero matrix | Generation Zeros Matrix | M_Zeros |
Generate (all) one matrix | Generation Ones Matrix | M_Ones |
Find the corresponding value position of the matrix (column first) | Find position with the value in Matrix | M_find |
Sum of matrix by column / sum of vector elements | Matrix column sum / Vector element sum | M_sum |
Matrix by column minimum row position / vector minimum element position | Matrix minimum row position / Vector minimum element position | M_min |
Maximum row position of matrix by column / maximum element position of vector | Matrix maximum row position / Vector maximum element position | M_max |
The value of the specified row position for each column of the matrix | The 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 matrices | Logical operation of corresponding positions of two matrices | M_logic |
Matrix corresponding element multiplication / Division | Multiply / divide corresponding elements of matrix | M_pmuldiv |
Matrix batch assignment (using matrix transfer) | Matrix batch assignment (using matrix transfer) | M_setval |
Matrix to matrix, multiply each row | Matrix Number Multiplication (using matrix transfer) | M_numul_m |
help | Help File | help |
[update description]
[Matrix Hub v1.42] 2021.08.06
- New maximum eigenvalue function for solving matrix: M_eigen_max(), you can use help("M_eigen_max") to view the specific usage;
- New matrix absolute value function M_abs(), you can use help("M_abs") to view the specific usage;
- 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
-
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;
-
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;
-
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)";
-
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!