Xmipp  v3.23.11-Nereus
linearalgebra.h
Go to the documentation of this file.
1 #ifndef _LINEARALGEBRA
2 #define _LINEARALGEBRA
3 
6 /*--------------------------------------------------------------------------*/
7 extern int AllocateMatrix
8  (
9  double **Matrix, /* double output pointer */
10  long Lines, /* width of the matrix */
11  long Columns, /* height of the matrix */
12  int *Status /* error management */
13  );
14 
15 /*--------------------------------------------------------------------------*/
16 extern int AllocateVector
17  (
18  double *(Vector[]), /* double output pointer */
19  long Lines, /* height of the vector */
20  int *Status /* error management */
21  );
22 
23 /*--------------------------------------------------------------------------*/
24 extern int FreeMatrix
25  (
26  double **Matrix /* (double)matrix array */
27  );
28 
29 /*--------------------------------------------------------------------------*/
30 extern int FreeVector
31  (
32  double *(Vector[]) /* (double)vector array */
33  );
34 
35 /*--------------------------------------------------------------------------*/
39 extern int FrobeniusNorm
40  (
41  double *A, /* input matrix */
42  double *Norm, /* resulting scalar norm */
43  long Lines, /* height of the matrix A */
44  long Columns /* width of the matrix A */
45  );
46 
47 /*--------------------------------------------------------------------------*/
48 extern int GetIdentitySquareMatrix
49  (
50  double *A, /* output identity matrix */
51  long Size /* height or width of the square matrix */
52  );
53 
54 /*--------------------------------------------------------------------------*/
55 extern int LinearLeastSquares
56  (
57  double *A, /* matrix */
58  long Lines, /* height the matrix */
59  long Columns, /* width of the matrix */
60  double B[], /* right-hand side vector */
61  double X[], /* resulting vector */
62  double Tolerance, /* admissible relative error */
63  int *Status /* error management */
64  );
65 
66 /*--------------------------------------------------------------------------*/
67 extern int MatrixAdd
68  (
69  double *A, /* left matrix operand */
70  double *B, /* right matrix operand */
71  double *X, /* resulting matrix */
72  long Lines, /* height of the matrices */
73  long Columns /* width of the matrices */
74  );
75 
76 /*--------------------------------------------------------------------------*/
82 extern int MatrixConditionNumber
83  (
84  double *A, /* input matrix */
85  long Lines, /* height of the matrix A */
86  long Columns, /* width of the matrix A */
87  double *ConditionNumber, /* resulting scalar condition number */
88  double Tolerance, /* admissible relative error */
89  long MaxIterations, /* convergence limit */
90  int *Status /* error management */
91  );
92 
93 /*--------------------------------------------------------------------------*/
100  (
101  double *A, /* input matrix */
102  double *B, /* resulting matrix */
103  long Lines, /* height of the matrix A */
104  long Columns, /* width of the matrix A */
105  double Tolerance /* admissible relative error */
106  );
107 
108 /*--------------------------------------------------------------------------*/
116 extern int MatrixMinor
117  (
118  double *A, /* input matrix */
119  double *B, /* smaller output matrix */
120  long Lines, /* height of the matrix A */
121  long Columns, /* width of the matrix A */
122  long i, /* line to delete */
123  long j /* column to delete */
124  );
125 
126 /*--------------------------------------------------------------------------*/
127 extern int MatrixMultiply
128  (
129  double *A, /* left matrix operand */
130  double *B, /* right matrix operand */
131  double *X, /* resulting matrix */
132  long Lines, /* height (left and resulting) */
133  long CommonSize, /* left width and right height */
134  long Columns /* width (right and resulting) */
135  );
136 
137 /*--------------------------------------------------------------------------*/
142 extern int MatrixRank
143  (
144  double *A, /* input square matrix */
145  long Lines, /* height of the matrix A */
146  long Columns, /* width of the matrix A */
147  long *Rank, /* resulting scalar condition number */
148  double Tolerance, /* admissible relative error */
149  long MaxIterations, /* convergence limit */
150  int *Status /* error management */
151  );
152 
153 /*--------------------------------------------------------------------------*/
154 extern int MatrixSubtract
155  (
156  double *A, /* left matrix operand */
157  double *B, /* right matrix operand */
158  double *X, /* resulting matrix */
159  long Lines, /* height of the matrices */
160  long Columns /* width of the matrices */
161  );
162 
163 /*--------------------------------------------------------------------------*/
164 extern int MatrixTimesVector
165  (
166  double *A, /* left matrix operand */
167  double *B, /* right vector operand */
168  double *X, /* resulting vector */
169  long Lines, /* matrix height */
170  long Columns /* matrix width and vector height */
171  );
172 
173 /*--------------------------------------------------------------------------*/
174 extern int MatrixTranspose
175  (
176  double *A, /* input matrix */
177  double *At, /* transposed output matrix */
178  long Lines, /* height input, width output */
179  long Columns /* width input, height output */
180  );
181 
182 /*--------------------------------------------------------------------------*/
189 int multiply_3Matrices(double *A,
190  double *B,
191  double *C,
192  double *X,
193  long Lines,
194  long CommonSizeH,
195  long CommonSizeW,
196  long Columns
197  );
198 
199 int multiply_4Matrices( double *A,
200  double *B,
201  double *C,
202  double *D,
203  double *X,
204  long Lines,
205  long CommonSizeH1,
206  long CommonSizeW1,
207  long CommonSizeW2,
208  long Columns);
209 
210 int multiply_5Matrices( double *A,
211  double *B,
212  double *C,
213  double *D,
214  double *E,
215  double *X,
216  long Lines,
217  long CommonSizeH1,
218  long CommonSizeW1,
219  long CommonSizeW2,
220  long CommonSizeH2,
221  long Columns );
222 
223 /*--------------------------------------------------------------------------*/
233 extern int QRdecomposition
234  (
235  double *Q, /* in-place matrix */
236  double *R, /* output matrix */
237  long Lines, /* height the matrix */
238  long Columns, /* width of the matrix */
239  double Tolerance, /* admissible relative error */
240  int *Status /* error management */
241  );
242 
243 /*--------------------------------------------------------------------------*/
245  (
246  double *U, /* input matrix (in-place processing) */
247  double W[], /* vector of singular values */
248  double *V, /* untransposed orthogonal matrix */
249  long Lines, /* height the matrix */
250  long Columns, /* width of the matrix */
251  double B[], /* input vector */
252  double X[], /* returned solution */
253  int *Status /* error management */
254  );
255 
256 /*--------------------------------------------------------------------------*/
257 #define SVDMAXITER 1000
259  (
260  double *U, /* input matrix (in-place processing) */
261  long Lines, /* height the matrix */
262  long Columns, /* width of the matrix */
263  double W[], /* resulting vector of singular values */
264  double *V, /* untransposed orthogonal matrix */
265  long MaxIterations, /* convergence limit */
266  int *Status /* error management */
267  );
268 
269 /*--------------------------------------------------------------------------*/
270 extern int SquareMatrixDeterminant
271  (
272  double *A, /* input square matrix */
273  long Size, /* height or width of the square matrix */
274  double *Determinant, /* resulting scalar determinant */
275  int *Status /* error management */
276  );
277 
278 /*--------------------------------------------------------------------------*/
279 extern int SquareMatrixInvertGauss
280  (
281  double *Direct, /* input matrix */
282  double *Inverse, /* resulting matrix */
283  long Size, /* height or width of the square matrix */
284  double Tolerance, /* admissible relative error */
285  int *Status /* error management */
286  );
287 
288 /*--------------------------------------------------------------------------*/
295 extern int SquareMatrixSquareRoot
296  (
297  double *A, /* input matrix */
298  double *B, /* output matrix and initial solution */
299  long Size, /* height or width of the square matrix */
300  double Tolerance, /* admissible relative error */
301  long MaxIterations, /* convergence limit */
302  int *Status /* error management */
303  );
304 
305 /*--------------------------------------------------------------------------*/
310 extern int SquareMatrixTrace
311  (
312  double *A, /* input matrix */
313  double *Trace, /* resulting scalar trace */
314  long Size /* height or width of the square matrix */
315  );
316 
317 /*--------------------------------------------------------------------------*/
318 extern int Vector3DcrossProduct
319  (
320  double A[], /* left vector operand */
321  double B[], /* right vector operand */
322  double X[] /* resulting vector */
323  );
324 
325 /*--------------------------------------------------------------------------*/
326 extern int VectorAdd
327  (
328  double A[], /* left vector operand */
329  double B[], /* right vector operand */
330  double X[], /* resulting vector */
331  long Lines /* height of the vectors */
332  );
333 
334 /*--------------------------------------------------------------------------*/
339 extern int VectorAngle
340  (
341  double A[], /* 1st input vector */
342  double B[], /* 2nd input vector */
343  double *Angle, /* resulting scalar angle in rad */
344  long Lines, /* height of the vectors */
345  double Tolerance /* admissible relative error */
346  );
347 
348 /*--------------------------------------------------------------------------*/
354 extern int VectorHomogenize
355  (
356  double A[], /* input vector */
357  double X[], /* output homogenous vector */
358  long Lines, /* height of the vectors */
359  double Tolerance /* admissible relative error */
360  );
361 
362 /*--------------------------------------------------------------------------*/
363 extern int VectorNorm
364  (
365  double A[], /* input vector */
366  double *Norm, /* resulting scalar norm */
367  long Lines /* height of the vector */
368  );
369 
370 /*--------------------------------------------------------------------------*/
371 extern int VectorNormalize
372  (
373  double A[], /* input vector */
374  double X[], /* resulting normalized vector */
375  long Lines /* height of the vector */
376  );
377 
378 /*--------------------------------------------------------------------------*/
379 extern int VectorScalarProduct
380  (
381  double A[], /* left vector operand */
382  double B[], /* right vector operand */
383  double *X, /* resulting scalar product */
384  long Lines /* height of the vector */
385  );
386 
387 /*--------------------------------------------------------------------------*/
388 extern int VectorScale
389  (
390  double A[], /* input vector */
391  double X[], /* output vector */
392  double Scale, /* scale factor */
393  long Lines /* height of the vector */
394  );
395 
396 /*--------------------------------------------------------------------------*/
397 extern int VectorSubtract
398  (
399  double A[], /* left vector operand */
400  double B[], /* right vector operand */
401  double X[], /* resulting vector */
402  long Lines /* height of the vectors */
403  );
405 #endif
int FreeMatrix(double **Matrix)
int VectorAdd(double A[], double B[], double X[], long Lines)
int multiply_5Matrices(double *A, double *B, double *C, double *D, double *E, double *X, long Lines, long CommonSizeH1, long CommonSizeW1, long CommonSizeW2, long CommonSizeH2, long Columns)
Definition: Vector.h:37
int VectorScalarProduct(double A[], double B[], double *X, long Lines)
int MatrixTimesVector(double *A, double *B, double *X, long Lines, long Columns)
int QRdecomposition(double *Q, double *R, long Lines, long Columns, double Tolerance, int *Status)
int multiply_4Matrices(double *A, double *B, double *C, double *D, double *X, long Lines, long CommonSizeH1, long CommonSizeW1, long CommonSizeW2, long Columns)
int MatrixRank(double *A, long Lines, long Columns, long *Rank, double Tolerance, long MaxIterations, int *Status)
int MatrixMultiply(double *A, double *B, double *X, long Lines, long CommonSize, long Columns)
#define i
int FreeVector(double *(Vector[]))
int VectorScale(double A[], double X[], double Scale, long Lines)
int LinearLeastSquares(double *A, long Lines, long Columns, double B[], double X[], double Tolerance, int *Status)
int MatrixAdd(double *A, double *B, double *X, long Lines, long Columns)
int Vector3DcrossProduct(double A[], double B[], double X[])
int MatrixGramSchmidtOrthonormalize(double *A, double *B, long Lines, long Columns, double Tolerance)
Definition: Matrix.h:38
int SingularValueBackSubstitution(double *U, double W[], double *V, long Lines, long Columns, double B[], double X[], int *Status)
int MatrixTranspose(double *A, double *At, long Lines, long Columns)
#define j
int SquareMatrixTrace(double *A, double *Trace, long Size)
int VectorNormalize(double A[], double X[], long Lines)
int VectorHomogenize(double A[], double X[], long Lines, double Tolerance)
int AllocateMatrix(double **Matrix, long Lines, long Columns, int *Status)
int VectorSubtract(double A[], double B[], double X[], long Lines)
int VectorAngle(double A[], double B[], double *Angle, long Lines, double Tolerance)
int AllocateVector(double *(Vector[]), long Lines, int *Status)
int MatrixConditionNumber(double *A, long Lines, long Columns, double *ConditionNumber, double Tolerance, long MaxIterations, int *Status)
int SingularValueDecomposition(double *U, long Lines, long Columns, double W[], double *V, long MaxIterations, int *Status)
int VectorNorm(double A[], double *Norm, long Lines)
int GetIdentitySquareMatrix(double *A, long Size)
int multiply_3Matrices(double *A, double *B, double *C, double *X, long Lines, long CommonSizeH, long CommonSizeW, long Columns)
int SquareMatrixInvertGauss(double *Direct, double *Inverse, long Size, double Tolerance, int *Status)
int FrobeniusNorm(double *A, double *Norm, long Lines, long Columns)
int MatrixSubtract(double *A, double *B, double *X, long Lines, long Columns)
int SquareMatrixDeterminant(double *A, long Size, double *Determinant, int *Status)
int SquareMatrixSquareRoot(double *A, double *B, long Size, double Tolerance, long MaxIterations, int *Status)
int MatrixMinor(double *A, double *B, long Lines, long Columns, long i, long j)