IT++ 4.3.1
specmat.h
Go to the documentation of this file.
1
29
30#ifndef SPECMAT_H
31#define SPECMAT_H
32
33#include <itpp/base/vec.h>
34#include <itpp/base/mat.h>
36#include <itpp/itexports.h>
37
38namespace itpp
39{
40
45ITPP_EXPORT ivec find(const bvec &invector);
46
50
53
55ITPP_EXPORT vec ones(int size);
57ITPP_EXPORT bvec ones_b(int size);
59ITPP_EXPORT ivec ones_i(int size);
61ITPP_EXPORT cvec ones_c(int size);
62
64ITPP_EXPORT mat ones(int rows, int cols);
66ITPP_EXPORT bmat ones_b(int rows, int cols);
68ITPP_EXPORT imat ones_i(int rows, int cols);
70ITPP_EXPORT cmat ones_c(int rows, int cols);
71
73ITPP_EXPORT vec zeros(int size);
75ITPP_EXPORT bvec zeros_b(int size);
77ITPP_EXPORT ivec zeros_i(int size);
79ITPP_EXPORT cvec zeros_c(int size);
80
82ITPP_EXPORT mat zeros(int rows, int cols);
84ITPP_EXPORT bmat zeros_b(int rows, int cols);
86ITPP_EXPORT imat zeros_i(int rows, int cols);
88ITPP_EXPORT cmat zeros_c(int rows, int cols);
89
91ITPP_EXPORT mat eye(int size);
93ITPP_EXPORT bmat eye_b(int size);
95ITPP_EXPORT imat eye_i(int size);
97ITPP_EXPORT cmat eye_c(int size);
99template <class T>
100void eye(int size, Mat<T> &m)
101{
102 m.set_size(size, size, false);
103 m = T(0);
104 for (int i = size - 1; i >= 0; i--)
105 m(i, i) = T(1);
106}
107
109ITPP_EXPORT vec impulse(int size);
110
112ITPP_EXPORT vec linspace(double from, double to, int length = 100);
113
115template<class T>
116Vec<T> linspace_fixed_step(T from, T to, T step = 1)
117{
118 int points = 0;
119 if (0 != step) {
120 points = itpp::floor_i(double(to-from)/step)+1;
121 }
122 if (0 >= points) {
123 return Vec<T>(0);
124 }
125
126 Vec<T> output(points);
127 output(0) = from;
128 for (int n = 1; n < points; ++n) {
129 output(n) = output(n-1)+step;
130 }
131 return output;
132}
133
162ITPP_EXPORT vec zigzag_space(double t0, double t1, int K = 5);
163
170ITPP_EXPORT imat hadamard(int size);
171
188ITPP_EXPORT imat jacobsthal(int p);
189
203ITPP_EXPORT imat conference(int n);
204
228template <typename Num_T>
229const Mat<Num_T> toeplitz(const Vec<Num_T> &c, const Vec<Num_T> &r)
230{
231 int n_rows = c.size();
232 int n_cols = r.size();
233 Mat<Num_T> output(n_rows, n_cols);
234 for (int i = 0; i < n_rows; ++i) {
235 int j_limit = std::min(n_cols, n_rows - i);
236 for (int j = 0; j < j_limit; ++j) {
237 output(i + j, j) = c(i);
238 }
239 }
240 for (int j = 1; j < n_cols; ++j) {
241 int i_limit = std::min(n_rows, n_cols - j);
242 for (int i = 0; i < i_limit; ++i) {
243 output(i, i + j) = r(j);
244 }
245 }
246 return output;
247}
248
250template <typename Num_T>
252{
253 int s = c.size();
254 Mat<Num_T> output(s, s);
255 for (int i = 0; i < s; ++i) {
256 for (int j = 0; j < s - i; ++j) {
257 output(i + j, j) = c(i);
258 }
259 }
260 for (int j = 1; j < s; ++j) {
261 for (int i = 0; i < s - j; ++i) {
262 output(i, i + j) = c(j);
263 }
264 }
265 return output;
266}
267
269ITPP_EXPORT const cmat toeplitz(const cvec &c);
270
271
273
274
279ITPP_EXPORT mat rotation_matrix(int dim, int plane1, int plane2, double angle);
280
285ITPP_EXPORT void house(const vec &x, vec &v, double &beta);
286
291ITPP_EXPORT void givens(double a, double b, double &c, double &s);
292
297ITPP_EXPORT void givens(double a, double b, mat &m);
298
303ITPP_EXPORT mat givens(double a, double b);
304
309ITPP_EXPORT void givens_t(double a, double b, mat &m);
310
315ITPP_EXPORT mat givens_t(double a, double b);
316
321template <class T>
323{
324 Vec<T> v(1);
325 v(0) = v0;
326 return v;
327}
328
333template <class T>
335{
336 Vec<T> v(2);
337 v(0) = v0;
338 v(1) = v1;
339 return v;
340}
341
346template <class T>
347Vec<T> vec_3(T v0, T v1, T v2)
348{
349 Vec<T> v(3);
350 v(0) = v0;
351 v(1) = v1;
352 v(2) = v2;
353 return v;
354}
355
360template <class T>
362{
363 Mat<T> m(1, 1);
364 m(0, 0) = m00;
365 return m;
366}
367
372template <class T>
373Mat<T> mat_1x2(T m00, T m01)
374{
375 Mat<T> m(1, 2);
376 m(0, 0) = m00;
377 m(0, 1) = m01;
378 return m;
379}
380
385template <class T>
387 T m10)
388{
389 Mat<T> m(2, 1);
390 m(0, 0) = m00;
391 m(1, 0) = m10;
392 return m;
393}
394
399template <class T>
400Mat<T> mat_2x2(T m00, T m01,
401 T m10, T m11)
402{
403 Mat<T> m(2, 2);
404 m(0, 0) = m00;
405 m(0, 1) = m01;
406 m(1, 0) = m10;
407 m(1, 1) = m11;
408 return m;
409}
410
415template <class T>
416Mat<T> mat_1x3(T m00, T m01, T m02)
417{
418 Mat<T> m(1, 3);
419 m(0, 0) = m00;
420 m(0, 1) = m01;
421 m(0, 2) = m02;
422 return m;
423}
424
429template <class T>
431 T m10,
432 T m20)
433{
434 Mat<T> m(3, 1);
435 m(0, 0) = m00;
436 m(1, 0) = m10;
437 m(2, 0) = m20;
438 return m;
439}
440
445template <class T>
446Mat<T> mat_2x3(T m00, T m01, T m02,
447 T m10, T m11, T m12)
448{
449 Mat<T> m(2, 3);
450 m(0, 0) = m00;
451 m(0, 1) = m01;
452 m(0, 2) = m02;
453 m(1, 0) = m10;
454 m(1, 1) = m11;
455 m(1, 2) = m12;
456 return m;
457}
458
463template <class T>
464Mat<T> mat_3x2(T m00, T m01,
465 T m10, T m11,
466 T m20, T m21)
467{
468 Mat<T> m(3, 2);
469 m(0, 0) = m00;
470 m(0, 1) = m01;
471 m(1, 0) = m10;
472 m(1, 1) = m11;
473 m(2, 0) = m20;
474 m(2, 1) = m21;
475 return m;
476}
477
482template <class T>
483Mat<T> mat_3x3(T m00, T m01, T m02,
484 T m10, T m11, T m12,
485 T m20, T m21, T m22)
486{
487 Mat<T> m(3, 3);
488 m(0, 0) = m00;
489 m(0, 1) = m01;
490 m(0, 2) = m02;
491 m(1, 0) = m10;
492 m(1, 1) = m11;
493 m(1, 2) = m12;
494 m(2, 0) = m20;
495 m(2, 1) = m21;
496 m(2, 2) = m22;
497 return m;
498}
499
500} //namespace itpp
501
502#endif // #ifndef SPECMAT_H
Matrix Class (Templated)
Definition mat.h:202
void set_size(int rows, int cols, bool copy=false)
Set size of matrix. If copy = true then keep the data before resizing.
Definition mat.h:647
Mat(const Factory &f=DEFAULT_FACTORY)
Mat< T > mat_3x3(T m00, T m01, T m02, T m10, T m11, T m12, T m20, T m21, T m22)
Matrix of size 3 by 3.
Definition specmat.h:483
Mat< T > mat_1x2(T m00, T m01)
Matrix of size 1 by 2.
Definition specmat.h:373
Mat< T > mat_2x1(T m00, T m10)
Matrix of size 2 by 1.
Definition specmat.h:386
Mat< double > T() const
Definition mat.h:337
Mat< T > mat_3x1(T m00, T m10, T m20)
Matrix of size 3 by 1.
Definition specmat.h:430
Mat< T > mat_2x2(T m00, T m01, T m10, T m11)
Matrix of size 2 by 2.
Definition specmat.h:400
Mat< T > mat_1x3(T m00, T m01, T m02)
Matrix of size 1 by 3.
Definition specmat.h:416
Mat< T > mat_2x3(T m00, T m01, T m02, T m10, T m11, T m12)
Matrix of size 2 by 3.
Definition specmat.h:446
Mat< T > mat_3x2(T m00, T m01, T m10, T m11, T m20, T m21)
Matrix of size 3 by 2.
Definition specmat.h:464
Mat< T > mat_1x1(T m00)
Matrix of size 1 by 1.
Definition specmat.h:361
Vector Class (Templated)
Definition vec.h:245
Vec< T > vec_3(T v0, T v1, T v2)
Vector of length 3.
Definition specmat.h:347
Vec< T > vec_1(T v0)
Vector of length 1.
Definition specmat.h:322
int size() const
The size of the vector.
Definition vec.h:271
Vec< T > vec_2(T v0, T v1)
Vector of length 2.
Definition specmat.h:334
Mat< double > T() const
Definition vec.h:318
Vec(const Factory &f=DEFAULT_FACTORY)
Definitions of converters between different vector and matrix types.
T to(double x)
Convert double to T.
int size(const Vec< T > &v)
Length of vector.
Definition matfunc.h:55
int length(const Vec< T > &v)
Length of vector.
Definition matfunc.h:51
vec angle(const cvec &x)
Angle.
Definition elem_math.h:218
void givens_t(double a, double b, mat &m)
Calculate the transposed Givens rotation matrix.
Definition specmat.cpp:336
void house(const vec &x, vec &v, double &beta)
Calcualte the Householder vector.
Definition specmat.cpp:251
mat rotation_matrix(int dim, int plane1, int plane2, double angle)
Create a rotation matrix that rotates the given plane angle radians. Note that the order of the plane...
Definition specmat.cpp:229
ivec find(const bvec &invector)
Return a integer vector with indicies where bvec == 1.
Definition specmat.cpp:40
void givens(double a, double b, double &c, double &s)
Calculate the Givens rotation values.
Definition specmat.cpp:277
vec linspace(double from, double to, int points)
linspace (works in the same way as the MATLAB version)
Definition specmat.cpp:106
ITPP_EXPORT vec zeros(int size)
A Double vector of zeros.
const cmat toeplitz(const cvec &c)
Generate symmetric Toeplitz matrix from vector c (complex valued)
Definition specmat.cpp:210
ITPP_EXPORT cvec zeros_c(int size)
A Double Complex vector of zeros.
ITPP_EXPORT cmat eye_c(int size)
A Double Complex (size,size) unit matrix.
imat hadamard(int size)
Hadamard matrix.
Definition specmat.cpp:149
ITPP_EXPORT ivec ones_i(int size)
A Int vector of ones.
ITPP_EXPORT imat eye_i(int size)
A Int (size,size) unit matrix.
vec impulse(int size)
Impulse vector.
Definition specmat.cpp:98
ITPP_EXPORT bmat eye_b(int size)
A Binary (size,size) unit matrix.
imat conference(int n)
Conference matrix.
Definition specmat.cpp:196
ITPP_EXPORT cvec ones_c(int size)
A float Complex vector of ones.
ITPP_EXPORT bvec ones_b(int size)
A Binary vector of ones.
ITPP_EXPORT bvec zeros_b(int size)
A Binary vector of zeros.
ITPP_EXPORT vec ones(int size)
A float vector of ones.
imat jacobsthal(int p)
Jacobsthal matrix.
Definition specmat.cpp:172
vec zigzag_space(double t0, double t1, int K)
Zig-zag space function (variation on linspace)
Definition specmat.cpp:125
ITPP_EXPORT ivec zeros_i(int size)
A Int vector of zeros.
Matrix Class Definitions.
Mat< bin > bmat
bin matrix
Definition mat.h:508
itpp namespace
Definition itmex.h:37
template vec linspace_fixed_step(double, double, double)
Template instantiation of linspace_fixed_step.
template void eye(int, mat &)
Template instantiation of eye.
int floor_i(double x)
The nearest smaller integer.
Definition converters.h:350
Templated Vector Class Definitions.