developing common algebra for c++ langugae
The numcpp is legacy code for developing c++ class for linear algebra library.
- 2023.2.1. inital version
- 2023.2.10. get, set function
- 2023.2.12. clear function
- 2023.2.13. add, substract, product, vec_dot, vec_cross function
Graduated Inha Univ in 2012
Get M.S. degree at KAIST in 2014
Get Ph.D. degree at KAIST in 2019
Working at Hyundai Motor Company from 2019 as a GNC engineer
to practice basic algebra function to develope basis math function set for matrix calculation
#tool chain If you are using windows OS, any following option is available, cygwin, mingW, or any gcc compiler (minGW, Cygwin), msys or MS visual studio compiler (VS comunity)
If you are using linux, (Ubuntu or CentOS) just use gcc compiler of the latest version.
cmf::matrix a;
double arr[9] = {1, 2, 3, 4, 5,6,7,8,9};
a.set(arr, 3,3 );
a.print_mat();
// swap element
a.set(3.9, 2,2);
a.print_mat();
cmf::matrix a,b,c;
double arr[9] = {1, 2, 3, 4, 5,6,7,8,9};
double arr2[9] = {2, 4,2, 5,3,6,3,2,5};
a.set(arr, 3,3 );
b.set(arr2,3,3);
add(c,a,b); // c = a+b
a.print_mat();
b.print_mat();
c.print_mat();
substrct(c,a,b); // c = a-b
c.print_mat();
cmf::matrix a,b,c;
double arr[6] = {1, 2, 4, 5,6,9};
double arr2[6] = {2, 4,6,3,2,5};
a.set(arr, 2,3 );
b.set(arr2,3,2);
printf("a matrix \n");
a.print_mat();
printf("b matrix \n");
b.print_mat();
matprod(c,a,b); // c = ab
printf("c = ab \n");
c.print_mat();
matprod(c,b,a); // c = ba
printf("c = ba \n");
c.print_mat();
return 1;
cmf::matrix a,b;
double arr[6] = {1, 2, 4, 5,6,9};
double arr2[6] = {2, 4,6,3,2,5};
a.set(arr, 6,1 );
b.set(arr2,6,1);
double c = 0.0;
printf("%f\n",c);
c = vdot(a,b); // c = ab
printf("a dot b = %f\n",c);
c = vdot(b,a); // c = ba
printf("b dot a = %f\n",c);
cmf::matrix A, B, C;
double arr[6] = {1, 2, 4, 5, 6, 4};
double arr2[4] = {2, 4,2,5};
double arr3[9] = {1,2,4, 5,6,1, 2,4,2};
A.set(arr, 3,2 );
B.set(arr2,2,2);
C.set(arr3,3,3);
printf("A matrix \n");
A.print_mat();
printf("B matrix \n");
B.print_mat();
printf("C matrix \n");
C.print_mat();
printf("Determinant A : %f \n",Det(A));
printf("Determinant B : %f \n",Det(B));
printf("Determinant C : %f \n",Det(C));
``` c++
matrix a,b,c;
```
``` c++
matrix a,b,c;
```
``` c++
```
// matrix product
cmf::matrix a,b,c;
double arr[4] = {1, 2, 4, 5};
double arr2[4] = {2, 4,2,5};
a.set(arr, 2,2 );
b.set(arr2,2,2);
printf("a matrix \n");
a.print_mat();
printf("b matrix \n");
b.print_mat();
c = a*b;
printf("c = ab \n");
c.print_mat();
c = b * a;
printf("c = ba \n");
c.print_mat();
// double * matrix
c = 3 * a ;
print ("c = 3.0 * a \n");
c.print_mat();
// matrix * double
c = a * 3;
print ("c = a * 3.0 \n");
c.print_mat();
cmf::matrix a,b,c;
double arr[6] = {1, 2, 4, 5, 6, 4};
double arr2[4] = {2, 4,2,5};
a.set(arr, 3,2 );
b.set(arr2,2,2);
printf("a matrix \n");
a.print_mat();
printf("b matrix \n");
b.print_mat();
printf("Determinant A : %f \n",Det(a));
printf("Determinant B : %f \n",Det(b));
cmf::matrix a,b,c;
double arr[4] = {1, 2, 4, 5};
double arr2[4] = {2, 4,2,5};
a.set(arr, 2,2 );
b.set(arr2,2,2);
printf("a matrix \n");
a.print_mat();
printf("b matrix \n");
b.print_mat();
c = a;
printf("c = a");
c.print_mat();
c = a +1 ;
printf("c = a+1");
c.print_mat();
c = 101 + a ;
printf("c = 101+a");
c.print_mat();
cmf::matrix a,b,c;
double arr[4] = {1, 2, 4, 5};
double arr2[4] = {2, 4,2,5};
a.set(arr, 2,2 );
b.set(arr2,2,2);
printf("a matrix \n");
a.print_mat();
printf("b matrix \n");
b.print_mat();
c = a ;
printf("c =a \n");
c.print_mat();
printf("c == a\n");
if(c==a)
{
printf("Same as\n");
}else
{
printf("Not Same\n");
}
printf("c == b\n");
if(c==b)
{
printf("Same as\n");
}else
{
printf("Not Same\n");
}
printf("c != b\n");
if(c!=b)
{
printf("Not same\n");
}else
{
printf("Same as\n");
}
use following excutible for simple calcuation. and Test.
- setting matrix
- empty matrix and one matrix
- matrix add
- matrix substract
- matrix multiply
- cross product
- dot product
- LU decomposition
- matrix inversion
dd
let's say matrix A in mxn and B in mxn are given as follows, respectively
A= [a_ij] i in m, j in n
B= [b_ij] i in m, j in n
A+B = [a_ij + b_ij]
mat A, B , C;
A = B + C ;
let's say matrix A in lxm and B in mxn are given as follows, respectively
A= [a_ij] i in l, j in m
B= [b_jk] i in m, j in n
then
A*B = [ Sum (a_ij * b_jk) from j=1 to m ], i in l, k in n
Thus
let's say matrix A and B are 3x1 with three components as follows, respectively
A = [a1, a2, a3] B = [b1, b2, b3]
Then the output should be
C = AxB = [a2b3 - a3b2 , -a1b3+a3b1, a1b2-a2b1]
mat A, B , C;
A = B + C ;
no | type | variable name | description |
---|---|---|---|
1 | double * | elm | matrix element data array |
2 | int | nrow | number of rows |
3 | int | ncol | number of columns |
no | type | variable name | description |
---|---|---|---|
1 | matrix & | dst_mat | output reference |
2 | matrix & | A | A matrix |
3 | matrix & | B | B matrix |
dst_mat = A+ B
no | type | variable name | description |
---|---|---|---|
1 | matrix & | dst_mat | output reference |
2 | matrix & | A | A matrix |
3 | matrix & | B | B matrix |
dst_mat = A- B
no | type | variable name | description |
---|---|---|---|
0 | double | vector_dot | output |
1 | matrix & | A | 1 x m vector A |
2 | matrix & | B | 1 x m vector B |
o = A dot B
no | type | variable name | description |
---|---|---|---|
1 | matrix & | dst_mat | output reference |
2 | matrix & | A | A matrix |
3 | matrix & | B | B matrix |
mathmatical representative
dst_mat = A x B