Browse code

2.15.1: Added MAGELLANs sources and functionality from MAGELLAN

ramon diaz-uriarte (at Phelsuma) authored on 02/07/2019 14:55:40
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,71 @@
1
+/*
2
+	All functions needed for Linear Algrebra
3
+	This is especially used for Least Square Estimates
4
+*/
5
+
6
+
7
+#ifndef __LINEAR_ALGEBRA__
8
+#define __LINEAR_ALGEBRA__
9
+
10
+struct matrix {
11
+	int r; 
12
+	int c;
13
+	double **val;
14
+};
15
+
16
+/*
17
+	Memory functions
18
+*/
19
+
20
+struct matrix MemMat( int m, int n );
21
+void IdentMat(struct matrix *M);
22
+void FreeMat( struct matrix *M );
23
+
24
+/*
25
+	Output a matrix
26
+*/
27
+void PrintMat( struct matrix *M, char *name );
28
+
29
+/*
30
+	Basic matrix operators
31
+	when opt_free is set to 1, it also free the entry matrix
32
+*/
33
+
34
+// :: WHAT ABOUT MEMORY HERE?:: WOULD IT BE BETTER TO MAKE ALL THESE FUNCTIONS VOID AND PASS THE MATRIX AS REFERENCE?:: //
35
+
36
+struct matrix MatrixProduct(struct matrix *M_left, struct matrix *M_right, char opt_free);
37
+void MatrixProductRef(struct matrix *M_left, struct matrix *M_right, struct matrix *Prod, char opt_free);
38
+
39
+struct matrix MatrixSum(struct matrix *M1, struct matrix *M2, char opt_free);
40
+void MatrixSumRef(struct matrix *M1, struct matrix *M2, struct matrix *Sum, char opt_free);
41
+
42
+struct matrix MatrixDiff(struct matrix *M1, struct matrix *M2, char opt_free);
43
+void MatrixDiffRef(struct matrix *M1, struct matrix *M2, struct matrix *Diff, char opt_free);
44
+
45
+
46
+struct matrix MatrixTranspose( struct matrix *M, char opt_free );
47
+struct matrix Invert_MatrixDiag(struct matrix *D, char opt_free );
48
+struct matrix MatrixHadarmardProduct(struct matrix *M1, struct matrix *M2, char opt_free);
49
+void MatrixHadarmardProductRef(struct matrix *M1, struct matrix *M2, struct matrix *HadarmardProduct, char opt_free);
50
+struct matrix scaleMatrix(struct matrix *M1, float scale, char opt_free);
51
+void scaleMatrixRef(struct matrix *M1, 	struct matrix *M2, float scale, char opt_free);
52
+void inverseMatrix(struct matrix *M1, struct matrix *inverseM);
53
+
54
+/*
55
+	From a vector, create a Diag Matrix
56
+*/
57
+struct matrix CreateMatrixDiag( struct matrix *Vector, char opt_free );
58
+
59
+/*
60
+	From a Matrix, create a Diag Matrix
61
+ */
62
+struct matrix CreateMatrixDiagMatrix( struct matrix *M1, char opt_free );
63
+
64
+/*
65
+	Return a vector [n,1] from a matrix X [m,n] and a vector Y[m,1]
66
+	m i the number of observation
67
+	n is the number of parameter to estimate
68
+*/
69
+struct matrix LeastSquare( struct matrix *X, struct matrix *Y );
70
+
71
+#endif