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.
- 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.
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.
To compile the program, use the following command in your terminal:
g++ -o matriz_reader main.cppThis will compile main.cpp and generate an executable named matriz_reader.
To run the program, simply type the following command in the terminal:
./matriz_readerAfter 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
Given the example input above, the program output will be:
The entered matrix is:
1 2 3
4 5 6
7 8 9
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.
- 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.
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.
To compile the program, use the following command in your terminal:
g++ -o matriz_inversa main.cpp -I /path/to/eigenThis 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.
To run the program, simply type the following command in the terminal:
./matriz_inversaAfter 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
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).
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.
- 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.
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.
To compile the program, use the following command in your terminal:
g++ -o matriz_producto main.cpp -I /path/to/eigenEnsure you replace /path/to/eigen with the actual path to the Eigen library on your system.
To run the program, type the following command in the terminal:
./matriz_productoYou 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
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.