-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextended-ReadEigen.c
executable file
·93 lines (73 loc) · 1.9 KB
/
extended-ReadEigen.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
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <pthread.h>
#define MAXTR 100
#define EPS 10e-28
void read_eigen (double **v, double *d, int n)
{
int i, j, k;
FILE *InPut;
InPut = fopen("./EigenOut.txt", "r");
for ( i = 0; i < n; i++){
fscanf(InPut, "%lf", &d[i]);
}
for ( i = 0; i < n; i++)
for (j = 0; j < n; j++){
fscanf(InPut, "%lf", &v[i][j]);
}
}
void extend (double **mat, double **v, double *d, int n)
{
int i, j, k;
double **aux;
aux = (double **) malloc (n*sizeof(double *));
for (j = 0; j < n; j++)
aux[j] = (double *) malloc (n*sizeof(double));
for ( i = 0; i < n; i++)
if(d[i] < 0.000003) d[i] = d[i-1];
for ( i = 0; i < n; i++)
for (j = 0; j < n; j++)
mat[i][j] = 0.0;
for ( i = 0; i < n; i++)
for (j = 0; j < n; j++)
aux[i][j] = d[i]*v[j][i];
for ( i = 0; i < n; i++)
for (j = 0; j < n; j++)
for (k = 0; k < n; k++)
mat[i][j] += v[i][k]*aux[k][j];
// free(aux);
}
void print_mat(double **Mat, char *outfile, int Ne, int tr)
{
int i, j;
FILE *OutPut;
OutPut = fopen (outfile, "w");
for (i = 0; i < Ne; i++){
for ( j = 0; j < tr-1; j++){
fprintf(OutPut, "%lf\t", Mat[i][j]);
}
fprintf(OutPut, "%lf\n", Mat[i][j]);
}
}
void bend (double **mat_ext, int tr)
{
int j;
double **v, *d;
v = (double **) malloc (tr*sizeof(double *));
for (j = 0; j < tr; j++)
v[j] = (double *) malloc (tr*sizeof(double));
d = (double *) malloc (tr*sizeof(double));
read_eigen (v, d, tr);
extend (mat_ext, v, d, tr);
}
main (){
int i, j, k, l, Ne, tr;
double **Covar;
scanf("%d", &tr);
Covar = (double **) malloc (tr*sizeof(double));
for ( j = 0; j < tr; j++)
Covar[j] = (double *) malloc (tr*sizeof(double));
bend(Covar, tr);
print_mat(Covar, "Cov_Ext.T.csv", tr, tr);
}