00001
00030 #ifndef SPECMAT_H
00031 #define SPECMAT_H
00032
00033 #include <itpp/base/vec.h>
00034 #include <itpp/base/mat.h>
00035
00036
00037 namespace itpp
00038 {
00039
00044 ivec find(const bvec &invector);
00045
00050
00051
00052
00054 vec ones(int size);
00056 bvec ones_b(int size);
00058 ivec ones_i(int size);
00060 cvec ones_c(int size);
00061
00063 mat ones(int rows, int cols);
00065 bmat ones_b(int rows, int cols);
00067 imat ones_i(int rows, int cols);
00069 cmat ones_c(int rows, int cols);
00070
00072 vec zeros(int size);
00074 bvec zeros_b(int size);
00076 ivec zeros_i(int size);
00078 cvec zeros_c(int size);
00079
00081 mat zeros(int rows, int cols);
00083 bmat zeros_b(int rows, int cols);
00085 imat zeros_i(int rows, int cols);
00087 cmat zeros_c(int rows, int cols);
00088
00090 mat eye(int size);
00092 bmat eye_b(int size);
00094 imat eye_i(int size);
00096 cmat eye_c(int size);
00098 template <class T>
00099 void eye(int size, Mat<T> &m);
00100
00102 vec impulse(int size);
00104 vec linspace(double from, double to, int length = 100);
00133 vec zigzag_space(double t0, double t1, int K = 5);
00134
00141 imat hadamard(int size);
00142
00159 imat jacobsthal(int p);
00160
00174 imat conference(int n);
00175
00199 template <typename Num_T>
00200 const Mat<Num_T> toeplitz(const Vec<Num_T> &c, const Vec<Num_T> &r)
00201 {
00202 int n_rows = c.size();
00203 int n_cols = r.size();
00204 Mat<Num_T> output(n_rows, n_cols);
00205 for (int i = 0; i < n_rows; ++i) {
00206 int j_limit = std::min(n_cols, n_rows - i);
00207 for (int j = 0; j < j_limit; ++j) {
00208 output(i + j, j) = c(i);
00209 }
00210 }
00211 for (int j = 1; j < n_cols; ++j) {
00212 int i_limit = std::min(n_rows, n_cols - j);
00213 for (int i = 0; i < i_limit; ++i) {
00214 output(i, i + j) = r(j);
00215 }
00216 }
00217 return output;
00218 }
00219
00221 template <typename Num_T>
00222 const Mat<Num_T> toeplitz(const Vec<Num_T> &c)
00223 {
00224 int s = c.size();
00225 Mat<Num_T> output(s, s);
00226 for (int i = 0; i < s; ++i) {
00227 for (int j = 0; j < s - i; ++j) {
00228 output(i + j, j) = c(i);
00229 }
00230 }
00231 for (int j = 1; j < s; ++j) {
00232 for (int i = 0; i < s - j; ++i) {
00233 output(i, i + j) = c(j);
00234 }
00235 }
00236 return output;
00237 }
00238
00240 template <>
00241 const cmat toeplitz(const cvec &c);
00242
00244
00245
00250 mat rotation_matrix(int dim, int plane1, int plane2, double angle);
00251
00256 void house(const vec &x, vec &v, double &beta);
00257
00262 void givens(double a, double b, double &c, double &s);
00263
00268 void givens(double a, double b, mat &m);
00269
00274 mat givens(double a, double b);
00275
00280 void givens_t(double a, double b, mat &m);
00281
00286 mat givens_t(double a, double b);
00287
00292 template <class T>
00293 Vec<T> vec_1(T v0)
00294 {
00295 Vec<T> v(1);
00296 v(0) = v0;
00297 return v;
00298 }
00299
00304 template <class T>
00305 Vec<T> vec_2(T v0, T v1)
00306 {
00307 Vec<T> v(2);
00308 v(0) = v0;
00309 v(1) = v1;
00310 return v;
00311 }
00312
00317 template <class T>
00318 Vec<T> vec_3(T v0, T v1, T v2)
00319 {
00320 Vec<T> v(3);
00321 v(0) = v0;
00322 v(1) = v1;
00323 v(2) = v2;
00324 return v;
00325 }
00326
00331 template <class T>
00332 Mat<T> mat_1x1(T m00)
00333 {
00334 Mat<T> m(1, 1);
00335 m(0, 0) = m00;
00336 return m;
00337 }
00338
00343 template <class T>
00344 Mat<T> mat_1x2(T m00, T m01)
00345 {
00346 Mat<T> m(1, 2);
00347 m(0, 0) = m00;
00348 m(0, 1) = m01;
00349 return m;
00350 }
00351
00356 template <class T>
00357 Mat<T> mat_2x1(T m00,
00358 T m10)
00359 {
00360 Mat<T> m(2, 1);
00361 m(0, 0) = m00;
00362 m(1, 0) = m10;
00363 return m;
00364 }
00365
00370 template <class T>
00371 Mat<T> mat_2x2(T m00, T m01,
00372 T m10, T m11)
00373 {
00374 Mat<T> m(2, 2);
00375 m(0, 0) = m00;
00376 m(0, 1) = m01;
00377 m(1, 0) = m10;
00378 m(1, 1) = m11;
00379 return m;
00380 }
00381
00386 template <class T>
00387 Mat<T> mat_1x3(T m00, T m01, T m02)
00388 {
00389 Mat<T> m(1, 3);
00390 m(0, 0) = m00;
00391 m(0, 1) = m01;
00392 m(0, 2) = m02;
00393 return m;
00394 }
00395
00400 template <class T>
00401 Mat<T> mat_3x1(T m00,
00402 T m10,
00403 T m20)
00404 {
00405 Mat<T> m(3, 1);
00406 m(0, 0) = m00;
00407 m(1, 0) = m10;
00408 m(2, 0) = m20;
00409 return m;
00410 }
00411
00416 template <class T>
00417 Mat<T> mat_2x3(T m00, T m01, T m02,
00418 T m10, T m11, T m12)
00419 {
00420 Mat<T> m(2, 3);
00421 m(0, 0) = m00;
00422 m(0, 1) = m01;
00423 m(0, 2) = m02;
00424 m(1, 0) = m10;
00425 m(1, 1) = m11;
00426 m(1, 2) = m12;
00427 return m;
00428 }
00429
00434 template <class T>
00435 Mat<T> mat_3x2(T m00, T m01,
00436 T m10, T m11,
00437 T m20, T m21)
00438 {
00439 Mat<T> m(3, 2);
00440 m(0, 0) = m00;
00441 m(0, 1) = m01;
00442 m(1, 0) = m10;
00443 m(1, 1) = m11;
00444 m(2, 0) = m20;
00445 m(2, 1) = m21;
00446 return m;
00447 }
00448
00453 template <class T>
00454 Mat<T> mat_3x3(T m00, T m01, T m02,
00455 T m10, T m11, T m12,
00456 T m20, T m21, T m22)
00457 {
00458 Mat<T> m(3, 3);
00459 m(0, 0) = m00;
00460 m(0, 1) = m01;
00461 m(0, 2) = m02;
00462 m(1, 0) = m10;
00463 m(1, 1) = m11;
00464 m(1, 2) = m12;
00465 m(2, 0) = m20;
00466 m(2, 1) = m21;
00467 m(2, 2) = m22;
00468 return m;
00469 }
00470
00471 }
00472
00473 #endif // #ifndef SPECMAT_H