Skip to content
This repository was archived by the owner on Jan 10, 2025. It is now read-only.
/ Matrices Public archive

A small performance test done in cpp to check.

License

DanoGlez/Matrices

Repository files navigation

👾 | Matrix Test


📁 | Read Folder

This C++ program allows the user to input a matrix in a format similar to MATLAB, where rows are separated by semicolons (;) and elements within each row are separated by spaces. It then prints the entered matrix to the console.

Features

  • Flexible Input: Users can input matrices of any size as long as they follow the correct format.
  • MATLAB-Like Format: Matrices must be entered on a single line, using ; to separate rows.

Requirements

To compile and run this program, you will need:

  • A C++ compiler that supports C++11 or later (such as g++).
  • Access to a terminal or command line.

Compilation

To compile the program, use the following command in your terminal:

g++ -o matriz_reader main.cpp

This will compile main.cpp and generate an executable named matriz_reader.

Execution

To run the program, simply type the following command in the terminal:

./matriz_reader

After running the command, you will be prompted to enter a matrix. Here is an example of how to input the matrix:

Enter the matrix (format '1 2 3; 4 5 6; 7 8 9'): 1 2 3; 4 5 6; 7 8 9

Expected Output

Given the example input above, the program output will be:

The entered matrix is:
1 2 3
4 5 6
7 8 9

📁 | Inverse Folder

This C++ program allows the user to input a matrix in a format similar to MATLAB, where rows are separated by semicolons (;) and elements within each row are separated by spaces. If the user wishes, the program calculates and displays the inverse of the matrix.

Features

  • Flexible Input: Users can input matrices of any size as long as they follow the correct format.
  • MATLAB-Like Format: Matrices must be entered on a single line, using ; to separate rows.
  • Inverse Calculation: Calculates and displays the inverse of the entered matrix if it is invertible.

Requirements

To compile and run this program, you will need:

  • A C++ compiler that supports C++11 or later (such as g++).
  • Access to a terminal or command line.
  • The Eigen library for matrix operations.

Compilation

To compile the program, use the following command in your terminal:

g++ -o matriz_inversa main.cpp -I /path/to/eigen

This will compile main.cpp and generate an executable named matriz_inversa. Ensure you replace /path/to/eigen with the actual path to the Eigen library on your system.

Execution

To run the program, simply type the following command in the terminal:

./matriz_inversa

After running the command, you will be prompted to enter a matrix. Here is an example of how to input the matrix:

Enter the matrix (format '1 2 3; 4 5 6; 7 8 9'): 1 2 3; 4 5 6; 7 8 9

Expected Output

For the above input, if the matrix is invertible, the program will display something similar to:

The entered matrix is:
1.00000000000000e+000 2.00000000000000e+000 3.00000000000000e+000
4.00000000000000e+000 5.00000000000000e+000 6.00000000000000e+000
7.00000000000000e+000 8.00000000000000e+000 9.00000000000000e+000

Do you want to display the inverse of the matrix? (y/n): y
The inverse of the matrix is:
-3.00000000000000e+001 6.00000000000000e+001 -3.00000000000000e+001
6.00000000000000e+001 -1.20000000000000e+002 6.00000000000000e+001
-3.00000000000000e+001 6.00000000000000e+001 -3.00000000000000e+001

If the matrix is not invertible, it will display an error:

The matrix is not invertible (determinant is zero).

📁 | Product Folder

This C++ program allows the user to input two matrices in a MATLAB-like format, where rows are separated by semicolons (;) and elements within each row are separated by spaces. If the user wishes, it calculates and displays the product of the two matrices.

Features

  • Flexible Input: Users can input matrices of any size as long as they follow the correct format and are compatible for multiplication.
  • MATLAB-Like Format: Matrices must be entered on a single line, using ; to separate rows.
  • Matrix Product: Calculates the product of two entered matrices if their dimensions are compatible.

Requirements

To compile and run this program, you will need:

  • A C++ compiler that supports C++11 or later (such as g++).
  • Access to a terminal or command line.
  • The Eigen library for matrix operations.

Compilation

To compile the program, use the following command in your terminal:

g++ -o matriz_producto main.cpp -I /path/to/eigen

Ensure you replace /path/to/eigen with the actual path to the Eigen library on your system.

Execution

To run the program, type the following command in the terminal:

./matriz_producto

You will then be prompted to enter two matrices. Here is an example:

Enter the first matrix (format '1 2 3; 4 5 6; 7 8 9'): 1 2 3; 4 5 6; 7 8 9
Enter the second matrix (format '1 2 3; 4 5 6; 7 8 9'): 9 8 7; 6 5 4; 3 2 1

Expected Output

For the above input, if the dimensions are compatible, the program will display:

The product of the matrices is:
 3.00000000000000e+001 2.40000000000000e+001 1.80000000000000e+001
 8.40000000000000e+001 6.90000000000000e+001 5.40000000000000e+001
 1.38000000000000e+002 1.14000000000000e+002 9.00000000000000e+001

If the dimensions are incompatible, it will display an error:

Error: the dimensions of the matrices are not compatible for multiplication.

About

A small performance test done in cpp to check.

Resources

License

Stars

Watchers

Forks

Languages