7 * Para direccionar la salida a un archivo, ejecutelo con:
11 * Para compilar en *nix:
13 * gcc -lm -Wall -O3 -o ec_lienal ec_lineal.cpp
16 * gcc -lm -Wall -g3 -o ec_lienal ec_lineal.cpp
22 extern void generar_matriz( Matriz& m ) {
23 for ( Indice i = 0; i < N; i++ )
24 for ( Indice j = 0; j < N; j++ )
25 m[i][j] = Numero( rand() ) * 3.0 / RAND_MAX;
28 extern void generar_vector( Vector& v ) {
29 for ( Indice i = 0; i < N; i++ )
30 v[i] = Numero( rand() ) * 3.0 / RAND_MAX;
33 extern void generar_vector_permutaciones( VectorPermutaciones& v ) {
34 for ( Indice i = 0; i < N; i++ )
38 extern void imprimir_matriz( Matriz& m ) {
39 for ( Indice i = 0; i < N; i++ ) {
40 for ( Indice j = 0; j < N; j++ )
41 printf( "%.02f ", m[i][j] );
46 extern void imprimir_vector( Vector& v ) {
47 for ( Indice i = 0; i < N; i++ )
48 printf( "%.02f ", v[i] );
52 extern void imprimir_matriz_permutada( Matriz& m, VectorPermutaciones& p ) {
53 for ( Indice i = 0; i < N; i++ ) {
54 for ( Indice j = 0; j < N; j++ )
55 printf( "%.02f ", m[p[i]][j] );
60 extern void imprimir_vector_permutado( Vector& v, VectorPermutaciones& p ) {
61 for ( Indice i = 0; i < N; i++ )
62 printf( "%.02f ", v[p[i]] );
66 extern void imprimir_matriz_L( Matriz& m, VectorPermutaciones& p ) {
67 for ( Indice i = 0; i < N; i++ ) {
68 for ( Indice j = 0; j < N; j++ )
74 printf( "%.02f ", m[p[i]][j] );
79 extern void imprimir_matriz_U( Matriz& m, VectorPermutaciones& p ) {
80 for ( Indice i = 0; i < N; i++ ) {
81 for ( Indice j = 0; j < N; j++ )
85 printf( "%.02f ", m[p[i]][j] );
90 extern void sustitucion_directa( Matriz& A, Vector& b, VectorPermutaciones& p ) {
91 for ( Indice i = 1; i < N; i++ ) {
93 for ( Indice j = 0; j < i; j++ )
94 sum += A[p[i]][j] * b[p[j]];
99 extern void sustitucion_inversa( Matriz& A, Vector& b, VectorPermutaciones& p ) {
100 for ( Indice i = N; i > 0; i-- ) {
102 for ( Indice j = i; j < N; j++ )
103 sum += A[p[i-1]][j] * b[p[j]];
104 b[p[i-1]] = ( b[p[i-1]] - sum ) / A[p[i-1]][i-1];