Dev - C++ - gaus jordan 4x4

 
Vista:
sin imagen de perfil

gaus jordan 4x4

Publicado por Kevin (2 intervenciones) el 12/10/2022 04:04:38
hola alguien me podria ayudar con un programa para hacer un gaus jordan 4x4 en "c" (c++ no nos dejan utilizar) con listas se los agradeceria mucho, lo nesecito para un examen dentro de 2 dias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alfil
Val: 4.344
Oro
Ha mantenido su posición en Dev - C++ (en relación al último mes)
Gráfica de Dev - C++

gaus jordan 4x4

Publicado por Alfil (1444 intervenciones) el 12/10/2022 16:38:55
Sólo tienes que pasarlo a C.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <iomanip>
 
using namespace std;
 
void LeerMatriz( float **M, int fil, int col );
void ImprimirFase( float **M, int fil, int col );
void Gauss( float **M, int fil, int col );
void ImprimirResultado( float **M, int fil, int col );
 
int main()
{
    int col, fil;
 
    cout << "# filas de la matriz: ";
    cin >> fil;
    cout << "# columnas de la matriz: ";
    cin >> col;
 
    float** M = new float*[fil];
    for( int i = 0; i < fil; i++ )
        M[i] = new float[col];
 
    LeerMatriz( M, fil, col );
 
    cout << "\nMatriz inicial:";
    ImprimirFase( M, fil, col );
 
    Gauss( M, fil, col );
    ImprimirResultado( M, fil, col );
 
    return 0;
}
 
void LeerMatriz( float **M, int fil, int col )
{
    cout << "\nDatos de la matriz:\n";
    for( int i = 0; i < fil; i++ ){
        cout << "Fila: " << i + 1 << "\n";
        for( int j = 0; j < col; j++ ){
            cout << "Columna " << j + 1 << ": ";
            cin >> M[i][j];
        }
    }
}
 
void ImprimirFase( float **M, int fil, int col )
{
    cout << "\n\n";
    for( int i = 0; i < fil; i++ ){
        for( int j = 0; j < col; j++ ){
            cout << setprecision(2) << fixed << setw(6)
                 << M[i][j] << " ";
        }
        cout << "\n";
    }
}
 
void Gauss( float **M, int fil, int col )
{
    int k = 0;
    float temp;
 
    while( k < col - 1 ){
        for( int i = k; i < fil; i++ ){
            for( int j = col - 1; j >= k; j-- ){
                if( i == k ){
                    temp = 1 / M[k][k];
                    M[i][j] = temp * M[i][j];
                }
                if( i > k ){
                    temp = (-M[i][k]);
                    M[i][j] = ( temp * (M[k][j])) + M[i][j];
                }
            }
        }
        k++;
    }
    cout << "\nFase 1:";
    ImprimirFase( M, fil, col);
 
    for( int i = 0; i < fil - 1; i++ ){
        for( int j = col - 1; j >= col - 2; j-- ){
            temp = (-M[i][col - 2]);
            M[i][j] = (temp * M[fil - 1][j])+ M[i][j];
        }
    }
    cout << "\nFase 2:";
    ImprimirFase( M, fil, col);
 
    k = 0;
    int c = 1;
    while( k < col - 1 ){
        for( int i = k; i < fil - 2; i++ ){
            for( int j = col - 1; j >= k + c; j-- ){
                temp = (-M[i][k + c]);
                M[i][j] = temp * M[i + 1][j] + M[i][j];
            }
        }
        k++;
        c++;
    }
    cout << "\nFase 3:";
    ImprimirFase( M, fil, col );
 
}
 
void ImprimirResultado( float **M, int fil, int col )
{
    cout << "\nImprimir resultado:\n\n";
    for( int i = 0; i < fil; i++ ){
        cout << setprecision(0) << fixed << setw(3)
             << char(120 + i) << " = "
             << setw(3) << setiosflags( ios::right )
             << M[i][col - 1] << endl;
    }
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

gaus jordan 4x4

Publicado por kevin (2 intervenciones) el 16/10/2022 04:31:56
gracias bro voy a intentar pasarlo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar