Skip to content

Commit 8abb3a3

Browse files
committed
Complex Matrix Operations Java
0 parents  commit 8abb3a3

8 files changed

+916
-0
lines changed

ENTRADAS MATRICES COMPLEJAS.txt

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
3
2+
3
3+
3
4+
2
5+
3
6+
5
7+
2
8+
1
9+
-4
10+
2
11+
5
12+
4
13+
6
14+
4
15+
3
16+
4
17+
3
18+
3
19+
2
20+
5
21+
6
22+
5
23+
1
24+
2
25+
-3
26+
2
27+
6
28+
3
29+
1
30+
4
31+
2
32+
3
33+
2
34+
4
35+
2
36+
6
37+
4
38+
3
39+
2
40+
1
41+
-3
42+
1
43+
4
44+
1
45+
2
46+
1
47+
5
48+
1
49+
3
50+
1
51+
1
52+
1
53+
-6
54+
1
55+
2
56+
1
57+
2
58+
1
59+
5
60+
1
61+
2
62+
1
63+
5
64+
1
65+
-2
66+
1
67+
5
68+
1
69+
1
70+
1
71+
3
72+
1
73+
4
74+
1

Jesus_Huerta_Proy1.pdf

466 KB
Binary file not shown.

MatricesComplejas.java

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
//BENEMERITA UNIVERSIDAD AUTONOMA DE PUEBLA
2+
//FACULTAD DE CIENCIAS DE LA COMPUTACION
3+
//PROGRAMACION II - JESUS HUERTA AGUILAR
4+
5+
// --------------------> Principal
6+
7+
package com.mycompany.matricescomplejas;
8+
9+
import java.util.Scanner;
10+
11+
public class MatricesComplejas{
12+
public static void main(String[] args){
13+
TMatrizCompleja A,B,C;
14+
int n,m;
15+
long numreal,numimag,denreal,denimag;
16+
TComplejo ayuda = new TComplejo();
17+
18+
Scanner sc = new Scanner(System.in);
19+
TOpMatricesComplejas op = new TOpMatricesComplejas();
20+
21+
System.out.println("\n / / / / / CALCULADORA DE MATRICES COMPLEJAS / / / / /\n");
22+
System.out.println("INGRESA EL TAMAÑO DE LAS MATRICES A Y B:");
23+
System.out.print(" | FILAS: ");
24+
n = sc.nextInt();
25+
System.out.print(" | COLUMNAS: ");
26+
m = sc.nextInt();
27+
28+
A = new TMatrizCompleja(n,m);
29+
B = new TMatrizCompleja(n,m);
30+
C = new TMatrizCompleja(n,m);
31+
32+
//ENTRADA DE DATOS MATRIZ A
33+
System.out.println("\nIngresa los componentes complejos de la matriz A");
34+
for(int i=0;i<n;i++){
35+
for(int j=0;j<n;j++){
36+
System.out.printf("//// MATRIZ[%d][%d]\n",(i+1),(j+1));
37+
System.out.println("---REAL: ");
38+
System.out.printf(" | NUMERADOR:");
39+
numreal = sc.nextInt();
40+
System.out.printf(" | DENOMINADOR:");
41+
denreal = sc.nextInt();
42+
System.out.println("---IMAGINARIO: ");
43+
System.out.printf(" | NUMERADOR:");
44+
numimag = sc.nextInt();
45+
System.out.printf(" | DENOMINADOR:");
46+
denimag= sc.nextInt();
47+
48+
ayuda.setNumReal(numreal);
49+
ayuda.setDenReal(denreal);
50+
ayuda.setNumImag(numimag);
51+
ayuda.setDenImag(denimag);
52+
A.setComponente(i,j,ayuda);
53+
System.out.println();
54+
}
55+
System.out.println("----------\n");
56+
}
57+
58+
//ENTRADA DE DATOS MATRIZ B
59+
System.out.println("\nIngresa los componentes complejos de la matriz B");
60+
for(int i=0;i<n;i++){
61+
for(int j=0;j<n;j++){
62+
System.out.printf("//// MATRIZ[%d][%d]\n",(i+1),(j+1));
63+
System.out.println("---REAL: ");
64+
System.out.printf(" | NUMERADOR:");
65+
numreal = sc.nextInt();
66+
System.out.printf(" | DENOMINADOR:");
67+
denreal = sc.nextInt();
68+
System.out.println("---IMAGINARIO: ");
69+
System.out.printf(" | NUMERADOR:");
70+
numimag = sc.nextInt();
71+
System.out.printf(" | DENOMINADOR:");
72+
denimag= sc.nextInt();
73+
74+
ayuda.setNumReal(numreal);
75+
ayuda.setDenReal(denreal);
76+
ayuda.setNumImag(numimag);
77+
ayuda.setDenImag(denimag);
78+
B.setComponente(i,j,ayuda);
79+
System.out.println();
80+
}
81+
System.out.print("----------\n\n");
82+
}
83+
84+
//SALIDA SUMA MATRIZ A B
85+
C = op.sumaMatricesComplejas(A,B);
86+
System.out.println("\nSUMA DE MATRICES: ");
87+
System.out.println(C.toString());
88+
89+
//SALIDA RESTA MATRIZ A B
90+
C = op.restaMatricesComplejas(A,B);
91+
System.out.println("\nRESTA DE MATRICES: ");
92+
System.out.println(C.toString());
93+
94+
//SALIDA MULTIPLICACION MATRIZ A B
95+
C = op.multiplicaMatricesComplejas(A,B);
96+
System.out.println("\nMULTIPLICACION DE MATRICES: ");
97+
System.out.println(C.toString());
98+
99+
//SALIDA MULTIPLICACION MATRIZ A*Inv(B)
100+
B = op.inversaMatrizCompleja(B);
101+
C = op.multiplicaMatricesComplejas(A,B);
102+
System.out.println("\nMULTIPLICACION DE MATRICES A*INV(B): ");
103+
System.out.println(C.toString());
104+
105+
}//FIN MAIN
106+
}//FIN CALSE PRINCIPAL

README.md

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Complex Matrix Operations in Java
2+
3+
## Project Overview
4+
5+
This repository contains a Java project for performing operations on complex matrices. The project is structured into several classes, each responsible for different aspects of handling and manipulating complex numbers and matrices. The main functionalities include creating complex matrices, performing arithmetic operations, and handling complex number arithmetic.
6+
7+
## Features
8+
9+
- **Complex Number Operations**: Basic operations on complex numbers such as addition, subtraction, multiplication, and division.
10+
- **Complex Matrix Operations**: Creation and manipulation of matrices with complex numbers including matrix addition, subtraction, multiplication, and scalar operations.
11+
- **Utility Methods**: Helper methods to facilitate complex number and matrix operations.
12+
- **Input Handling**: Reading complex matrices from input files and processing them.
13+
14+
## Project Structure
15+
16+
```plaintext
17+
src/
18+
├── TComplejo.java
19+
├── TOperaComplejos.java
20+
├── TMatrizCompleja.java
21+
├── TOpMatricesComplejas.java
22+
└── MatricesComplejas.java
23+
```
24+
25+
### TComplejo.java
26+
27+
This class defines the structure and basic operations for complex numbers. It includes methods for addition, subtraction, multiplication, and division of complex numbers.
28+
29+
#### Key Methods
30+
```java
31+
public class TComplejo {
32+
private double real;
33+
private double imag;
34+
35+
public TComplejo(double real, double imag) {
36+
this.real = real;
37+
this.imag = imag;
38+
}
39+
40+
public TComplejo add(TComplejo c) {
41+
return new TComplejo(this.real + c.real, this.imag + c.imag);
42+
}
43+
44+
public TComplejo subtract(TComplejo c) {
45+
return new TComplejo(this.real - c.real, this.imag - c.imag);
46+
}
47+
48+
// Other operations...
49+
}
50+
```
51+
52+
### TOperaComplejos.java
53+
54+
This class provides additional operations for complex numbers, possibly including utility functions that extend the basic arithmetic operations provided in `TComplejo.java`.
55+
56+
### TMatrizCompleja.java
57+
58+
This class represents a matrix with complex numbers. It includes methods to perform matrix-specific operations such as addition, subtraction, and multiplication.
59+
60+
#### Key Methods
61+
```java
62+
public class TMatrizCompleja {
63+
private TComplejo[][] data;
64+
65+
public TMatrizCompleja(int rows, int cols) {
66+
data = new TComplejo[rows][cols];
67+
}
68+
69+
public TMatrizCompleja add(TMatrizCompleja m) {
70+
// Implementation for matrix addition
71+
}
72+
73+
public TMatrizCompleja multiply(TMatrizCompleja m) {
74+
// Implementation for matrix multiplication
75+
}
76+
77+
// Other matrix operations...
78+
}
79+
```
80+
81+
### TOpMatricesComplejas.java
82+
83+
This class likely provides additional operations for complex matrices, complementing the basic operations defined in `TMatrizCompleja.java`.
84+
85+
### MatricesComplejas.java
86+
87+
This is the main class that coordinates the complex matrix operations, possibly including reading inputs, initializing matrices, and invoking operations.
88+
89+
#### Example Usage
90+
```java
91+
public class MatricesComplejas {
92+
public static void main(String[] args) {
93+
// Initialize matrices and perform operations
94+
TMatrizCompleja matrix1 = new TMatrizCompleja(3, 3);
95+
TMatrizCompleja matrix2 = new TMatrizCompleja(3, 3);
96+
97+
TMatrizCompleja result = matrix1.add(matrix2);
98+
// Output the result...
99+
}
100+
}
101+
```
102+
103+
## How to Use
104+
105+
1. **Clone the repository**
106+
```bash
107+
git clone https://github.com/yourusername/ComplexMatrixOperations.git
108+
```
109+
2. **Navigate to the project directory**:
110+
```bash
111+
cd ComplexMatrixOperations
112+
```
113+
3. **Compile the Java files**:
114+
```bash
115+
javac src/*.java
116+
```
117+
4. **Run the main class**:
118+
```bash
119+
java src/MatricesComplejas
120+
```
121+
122+
## Input File Format (example)
123+
124+
The input file `ENTRADAS MATRICES COMPLEJAS.txt` contain the matrices to be processed. Each matrix is represented by its elements, where each complex number is specified in the format (real, imaginary).
125+
126+
```plaintext
127+
3
128+
3
129+
3
130+
2
131+
3
132+
5
133+
2
134+
1
135+
-4
136+
2
137+
5
138+
4
139+
6
140+
...
141+
```

0 commit comments

Comments
 (0)