-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMatrix.h
More file actions
65 lines (59 loc) · 1.93 KB
/
Matrix.h
File metadata and controls
65 lines (59 loc) · 1.93 KB
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
/*
* MatrixMath.h Library for Matrix Math
*
* Created by Charlie Matlack on 12/18/10.
* Modified from code by RobH45345 on Arduino Forums, taken from unknown source.
*
* Author: Sam Abeyruwn has modified the code to work with Energia and Tiva C.
*
* Matrix.h
*
* Created on: Apr 1, 2014
* Author: sam
*
* @Doc: http://playground.arduino.cc/Code/MatrixMath#.Uzs2-nWx3t7
*/
#ifndef MATRIXMATH_H_
#define MATRIXMATH_H_
#if defined(ENERGIA)
#include "Energia.h"
#else
#include <iostream>
#include <math.h>
//#include <string.h>
#endif
// In order to compile off-line
#if defined(ENERGIA)
typedef String MatrixString;
#else
typedef std::string MatrixString;
#endif
/**
* Matrices should be stored in row-major arrays, which is fairly standard. The user must keep
* track of array dimensions and send them to the functions; mistakes on dimensions will not be
* caught by the library.
*
* It's worth pointing out that the MatrixInvert() function uses Gauss-Jordan elimination with
* partial pivoting. Partial pivoting is a compromise between a numerically unstable algorithm
* and full pivoting, which involves more searching and swapping matrix elements.
*
* Also, the inversion algorithm stores the result matrix on top of the the input matrix, meaning
* no extra memory is allocated during inversion but your original matrix is gone.
*/
class MatrixMath
{
public:
MatrixMath();
~MatrixMath();
void print(float* A, int m, int n, MatrixString label);
void copy(float* A, int n, int m, float* B);
void multiply(float* A, float* B, int m, int p, int n, float* C);
void add(float* A, float* B, int m, int n, float* C);
void subtract(float* A, float* B, int m, int n, float* C);
void transpose(float* A, int m, int n, float* C);
void scale(float* A, int m, int n, float k);
float trace(float* A, int m, int n);
int invert(float* A, int n);
};
extern MatrixMath Matrix;
#endif /* MATRIXMATH_H_ */