This is the basic C++ program of C++ armadillo library which shows how to generate random matrix of some particular size. Basic rules of matrix arithmetic operations are applicable to this. Random matrix is generated by inbuilt function named randu which takes two parametres i.e. number of rows and columns.
mat A = randu<mat>(4,4); //random matrix of size 4x4 (generared by this syntax)
mat B = randu<mat>(4,4);
cout << "A::\n"<< A << endl;
cout << "B::\n"<< B << endl;
cout << "Addition of A and B(A+B)::" << endl;
cout << A+B << endl; //Addition
cout << "Subtraction of A and B(A-B)::" << endl; //Basic arithmetic operations
cout << A-B << endl; //Subtraction
cout << "Multiplication of A and B(A*B)::" << endl;
cout << A*B << endl; //Multiplication
cout << "Division of A and B(A/B)::" << endl;
cout << A/B << endl; //Division
return 0;
}
Comments