212 for (
int r = 0;
r <
rows;
r++) {
213 for (
int c = 0;
c <
cols;
c++) {
214 fprintf (stderr,
"%+.2e,%+.2e ", (
double)
real (
get (
r,
c)),
215 (
double)
imag (
get (
r,
c)));
217 fprintf (stderr,
"\n");
229 assert (a.getRows () == b.getRows () && a.getCols () == b.getCols ());
231 matrix res (a.getRows (), a.getCols ());
232 for (
int r = 0;
r < a.getRows ();
r++)
233 for (
int c = 0;
c < a.getCols ();
c++)
234 res.
set (
r,
c, a.get (
r,
c) + b.get (
r,
c));
247 for (i = 0, r = 0; r < a.
getRows (); r++)
248 for (c = 0; c < a.
getCols (); c++, i++)
260 assert (a.getRows () == b.getRows () && a.getCols () == b.getCols ());
262 matrix res (a.getRows (), a.getCols ());
263 for (
int r = 0;
r < a.getRows ();
r++)
264 for (
int c = 0;
c < a.getCols ();
c++)
265 res.
set (
r,
c, a.get (
r,
c) - b.get (
r,
c));
273 for (i = 0, r = 0; r <
getRows (); r++)
274 for (c = 0; c <
getCols (); c++, i++)
286 for (i = 0, r = 0; r < a.
getRows (); r++)
287 for (c = 0; c < a.
getCols (); c++, i++)
299 matrix res (a.getRows (), a.getCols ());
300 for (
int r = 0;
r < a.getRows ();
r++)
301 for (
int c = 0;
c < a.getCols ();
c++)
302 res.
set (
r,
c, a.get (
r,
c) * z);
324 matrix res (a.getRows (), a.getCols ());
325 for (
int r = 0;
r < a.getRows ();
r++)
326 for (
int c = 0;
c < a.getCols ();
c++)
349 matrix res (a.getRows (), a.getCols ());
350 for (
int r = 0;
r < a.getRows ();
r++)
351 for (
int c = 0;
c < a.getCols ();
c++)
352 res.
set (
r,
c, a.get (
r,
c) / z);
363 matrix res (a.getRows (), a.getCols ());
364 for (
int r = 0;
r < a.getRows ();
r++)
365 for (
int c = 0;
c < a.getCols ();
c++)
379 assert (a.getCols () == b.getRows ());
381 int r,
c,
i,
n = a.getCols ();
383 matrix res (a.getRows (), b.getCols ());
384 for (r = 0; r < a.getRows (); r++) {
385 for (c = 0; c < b.getCols (); c++) {
386 for (i = 0, z = 0; i <
n; i++) z += a.get (r, i) * b.get (i, c);
400 matrix res (a.getRows (), a.getCols ());
401 for (
int r = 0;
r < a.getRows ();
r++)
402 for (
int c = 0;
c < a.getCols ();
c++)
403 res.
set (
r,
c, a.get (
r,
c) + z);
425 matrix res (a.getRows (), a.getCols ());
426 for (
int r = 0;
r < a.getRows ();
r++)
427 for (
int c = 0;
c < a.getCols ();
c++)
493 matrix res (a.getCols (), a.getRows ());
494 for (
int r = 0;
r < a.getRows ();
r++)
495 for (
int c = 0;
c < a.getCols ();
c++)
506 matrix res (a.getRows (), a.getCols ());
507 for (
int r = 0;
r < a.getRows ();
r++)
508 for (
int c = 0;
c < a.getCols ();
c++)
532 matrix res (a.getRows (), a.getCols ());
533 for (
int r = 0;
r < a.getRows ();
r++)
534 for (
int c = 0;
c < a.getCols ();
c++)
542 matrix
dB (matrix a) {
543 matrix res (a.getRows (), a.getCols ());
544 for (
int r = 0;
r < a.getRows ();
r++)
545 for (
int c = 0;
c < a.getCols ();
c++)
546 res.set (
r,
c,
dB (a.get (
r,
c)));
556 matrix res (a.getRows (), a.getCols ());
557 for (
int r = 0;
r < a.getRows ();
r++)
558 for (
int c = 0;
c < a.getCols ();
c++)
569 matrix res (a.getRows (), a.getCols ());
570 for (
int r = 0;
r < a.getRows ();
r++)
571 for (
int c = 0;
c < a.getCols ();
c++)
582 matrix res (a.getRows (), a.getCols ());
583 for (
int r = 0;
r < a.getRows ();
r++)
584 for (
int c = 0;
c < a.getCols ();
c++)
603 matrix
eye (
int rs,
int cs) {
605 for (
int r = 0;
r < res.getRows ();
r++)
606 for (
int c = 0;
c < res.getCols ();
c++)
607 if (
r ==
c) res.set (
r,
c, 1);
627 for (
int i = 0;
i <
size;
i++) res (
i,
i) = diag (
i);
635 res =
eye (a.getRows (), a.getCols ());
638 res = a = n < 0 ?
inverse (a) : a;
658 matrix res (a.getRows () - 1, a.getCols () - 1);
660 for (ra = r = 0; r < res.getRows (); r++, ra++) {
662 for (ca = c = 0; c < res.getCols (); c++, ca++) {
664 res.set (r, c, a.get (ra, ca));
668 return ((u + v) & 1) ? -z : z;
687 assert (a.getRows () == a.getCols ());
688 int s = a.getRows ();
694 for (
int i = 0;
i <
s;
i++) {
718 assert (a.getRows () == a.getCols ());
719 nr_double_t MaxPivot;
722 int i,
c,
r, pivot,
n = a.getCols ();
725 if (n == 0)
return 1;
726 if (n == 1)
return a (0, 0);
732 for (res = 1, i = 0; i <
n; i++) {
734 for (MaxPivot = 0, pivot = r = i; r <
n; r++) {
735 if (
abs (b.get (r, i)) > MaxPivot) {
736 MaxPivot =
abs (b.get (r, i));
741 assert (MaxPivot != 0);
742 if (i != pivot) { b.exchangeRows (i, pivot); res = -res; }
744 for (r = i + 1; r <
n; r++) {
745 f = b.get (r, i) / b.get (i, i);
746 for (c = i + 1; c <
n; c++) {
747 b.set (r, c, b.get (r, c) - f * b.get (i, c));
753 for (i = 0; i <
n; i++) res *= b.get (i, i);
780 matrix res (a.getRows (), a.getCols ());
782 assert (
abs (d) != 0);
783 for (
int r = 0;
r < a.getRows ();
r++)
784 for (
int c = 0;
c < a.getCols ();
c++)
799 nr_double_t MaxPivot;
802 int i,
c,
r, pivot,
n = a.getCols ();
809 for (i = 0; i <
n; i++) {
811 for (MaxPivot = 0, pivot = r = i; r <
n; r++) {
812 if (
abs (b (r, i)) > MaxPivot) {
813 MaxPivot =
abs (b (r, i));
818 assert (MaxPivot != 0);
820 b.exchangeRows (i, pivot);
821 e.exchangeRows (i, pivot);
825 for (f = b (i, i), c = 0; c <
n; c++) {
831 for (r = 0; r <
n; r++) {
833 for (f = b (r, i), c = 0; c <
n; c++) {
834 b (r, c) -= f * b (i, c);
835 e (r, c) -= f * e (i, c);
891 int d = s.getRows ();
894 assert (d == s.getCols () && d == z0.
getSize () && d == zref.
getSize ());
897 r =
diagonal ((z0 - zref) / (z0 + zref));
911 int d = s.getRows ();
923 matrix
stos (matrix
s, nr_double_t
zref, nr_double_t z0) {
974 int d = s.getRows ();
975 matrix e,
zref, gref;
977 assert (d == s.getCols () && d == z0.
getSize ());
1019 int d = z.getRows ();
1020 matrix e,
zref, gref;
1022 assert (d == z.getCols () && d == z0.
getSize ());
1051 assert (z.getRows () == z.getCols ());
1083 int d = s.getRows ();
1084 matrix e,
zref, gref;
1086 assert (d == s.getCols () && d == z0.
getSize ());
1134 int d = y.getRows ();
1135 matrix e,
zref, gref;
1137 assert (d == y.getCols () && d == z0.
getSize ());
1142 return gref * (e - zref *
y) *
inverse (e + zref * y) *
inverse (gref);
1186 assert (s.getRows () >= 2 && s.getCols () >= 2);
1188 a.set (0, 0, (
conj (z1) + z1 * s (0, 0) -
1189 conj (z1) * s (1, 1) - z1 * d) / n);
1190 a.set (0, 1, (
conj (z1) *
conj (z2) + z1 *
conj (z2) * s (0, 0) +
1191 conj (z1) * z2 * s (1, 1) + z1 * z2 * d) / n);
1192 a.set (1, 0, (1.0 - s (0, 0) - s (1, 1) + d) / n);
1193 a.set (1, 1, (
conj (z2) -
conj (z2) * s (0, 0) +
1194 z2 * s (1, 1) - z2 * d) / n);
1225 a (1, 0) * z1 * z2 + a (1, 1) * z1;
1228 assert (a.getRows () >= 2 && a.getCols () >= 2);
1230 s.set (0, 0, (a (0, 0) * z2 + a (0, 1)
1231 - a (1, 0) *
conj (z1) * z2 - a (1, 1) *
conj (z1)) / n);
1232 s.set (0, 1, (a (0, 0) * a (1, 1) -
1233 a (0, 1) * a (1, 0)) * d / n);
1234 s.set (1, 0, d / n);
1235 s.set (1, 1, (a (1, 1) * z1 - a (0, 0) *
conj (z2) +
1236 a (0, 1) - a (1, 0) * z1 *
conj (z2)) / n);
1274 assert (s.getRows () >= 2 && s.getCols () >= 2);
1276 h.set (0, 0, ((1.0 + s (0, 0)) * (1.0 + s (1, 1)) - n) * z1 / d);
1277 h.set (0, 1, +2.0 * s (0, 1) / d);
1278 h.set (1, 0, -2.0 * s (1, 0) / d);
1279 h.set (1, 1, ((1.0 - s (0, 0)) * (1.0 - s (1, 1)) - n) / z2 / d);
1309 nr_complex_t d = (1.0 +
h (0, 0) / z1) * (1.0 + z2 * h (1, 1)) - n;
1312 assert (h.getRows () >= 2 && h.getCols () >= 2);
1314 s.set (0, 0, ((h (0, 0) / z1 - 1.0) * (1.0 + z2 * h (1, 1)) - n) / d);
1315 s.set (0, 1, +2.0 * h (0, 1) / d);
1316 s.set (1, 0, -2.0 * h (1, 0) / d);
1317 s.set (1, 1, ((1.0 + h (0, 0) / z1) * (1.0 - z2 * h (1, 1)) + n) / d);
1336 assert (s.getRows () >= 2 && s.getCols () >= 2);
1338 g.set (0, 0, ((1.0 - s (0, 0)) * (1.0 - s (1, 1)) - n) / z1 / d);
1339 g.set (0, 1, -2.0 * s (0, 1) / d);
1340 g.set (1, 0, +2.0 * s (1, 0) / d);
1341 g.set (1, 1, ((1.0 + s (0, 0)) * (1.0 + s (1, 1)) - n) * z2 / d);
1357 nr_complex_t d = (1.0 + g (0, 0) * z1) * (1.0 + g (1, 1) / z2) - n;
1360 assert (g.getRows () >= 2 && g.getCols () >= 2);
1362 s.set (0, 0, ((1.0 - g (0, 0) * z1) * (1.0 + g (1, 1) / z2) + n) / d);
1363 s.set (0, 1, -2.0 * g (0, 1) / d);
1364 s.set (1, 0, +2.0 * g (1, 0) / d);
1365 s.set (1, 1, ((g (0, 0) * z1 + 1.0) * (g (1, 1) / z2 - 1.0) - n) / d);
1381 assert (y.getRows () == y.getCols ());
1405 matrix e =
eye (s.getRows ());
1407 assert (cy.getRows () == cy.getCols () && s.getRows () == s.getCols () &&
1408 cy.getRows () == s.getRows ());
1410 return (e + s) * cy *
adjoint (e + s) / 4;
1431 matrix e =
eye (y.getRows ());
1433 assert (cs.getRows () == cs.getCols () && y.getRows () == y.getCols () &&
1434 cs.getRows () == y.getRows ());
1436 return (e + y) * cs *
adjoint (e + y);
1458 matrix e =
eye (s.getRows ());
1460 assert (cz.getRows () == cz.getCols () && s.getRows () == s.getCols () &&
1461 cz.getRows () == s.getRows ());
1463 return (e - s) * cz *
adjoint (e - s) / 4;
1484 assert (cs.getRows () == cs.getCols () && z.getRows () == z.getCols () &&
1485 cs.getRows () == z.getRows ());
1486 matrix e =
eye (z.getRows ());
1487 return (e + z) * cs *
adjoint (e + z);
1508 assert (cz.getRows () == cz.getCols () && y.getRows () == y.getCols () &&
1509 cz.getRows () == y.getRows ());
1532 assert (cy.getRows () == cy.getCols () && z.getRows () == z.getCols () &&
1533 cy.getRows () == z.getRows ());
1547 assert (r1 >= 0 && r2 >= 0 && r1 < rows && r2 < rows);
1549 memcpy (s, &
data[r1 * cols], len);
1550 memcpy (&
data[r1 * cols], &
data[r2 * cols], len);
1551 memcpy (&
data[r2 * cols], s, len);
1564 assert (c1 >= 0 && c2 >= 0 && c1 < cols && c2 < cols);
1595 assert (m.getRows () >= 2 && m.getCols () >= 2);
1606 d = m (0, 0) * m (1, 1) - m (0, 1) * m (1, 0);
1607 res.set (0, 0, m (1, 1) / d);
1608 res.set (0, 1, -m (0, 1) / d);
1609 res.set (1, 0, -m (1, 0) / d);
1610 res.set (1, 1, m (0, 0) / d);
1614 res.set (0, 0, 1.0 / d);
1615 res.set (0, 1, -m (0, 1) / d);
1616 res.set (1, 0, m (1, 0) / d);
1617 res.set (1, 1, m (1, 1) - m (0, 1) * m (1, 0) / d);
1621 res.set (0, 0, m (0, 0) - m (0, 1) * m (1, 0) / d);
1622 res.set (0, 1, m (0, 1) / d);
1623 res.set (1, 0, -m (1, 0) / d);
1624 res.set (1, 1, 1.0 / d);
1628 res.set (0, 0, -m (1, 1) / d);
1629 res.set (0, 1, -1.0 / d);
1630 res.set (1, 0, m (0, 1) - m (1, 1) * m (0, 0) / d);
1631 res.set (1, 1, -m (0, 0) / d);
1641 d = m (0, 0) * m (1, 1) - m (0, 1) * m (1, 0);
1642 res.set (0, 0, m (1, 1) / d);
1643 res.set (0, 1, -m (0, 1) / d);
1644 res.set (1, 0, -m (1, 0) / d);
1645 res.set (1, 1, m (0, 0) / d);
1652 res.set (0, 0, m (0, 0) - m (0, 1) * m (1, 0) / d);
1653 res.set (0, 1, m (0, 1) / d);
1654 res.set (1, 0, -m (1, 0) / d);
1655 res.set (1, 1, 1.0 / d);
1659 res.set (0, 0, 1.0 / d);
1660 res.set (0, 1, -m (0, 1) / d);
1661 res.set (1, 0, m (1, 0) / d);
1662 res.set (1, 1, m (1, 1) - m (0, 1) * m (1, 0) / d);
1666 res.set (0, 0, m (0, 0) / d);
1667 res.set (0, 1, m (0, 0) * m (1, 1) / d - m (0, 1));
1668 res.set (1, 0, 1.0 / d);
1669 res.set (1, 1, m (1, 1) / d);
1680 res.set (0, 0, 1.0 / d);
1681 res.set (0, 1, -m (0, 1) / d);
1682 res.set (1, 0, m (1, 0) / d);
1683 res.set (1, 1, m (1, 1) - m (0, 1) * m.get(2, 1) /
d);
1687 res.set (0, 0, m (0, 0) - m (0, 1) * m (1, 0) / d);
1688 res.set (0, 1, m (0, 1) / d);
1689 res.set (1, 0, -m (1, 0) / d);
1690 res.set (1, 1, 1.0 / d);
1696 d = m (0, 0) * m (1, 1) - m (0, 1) * m (1, 0);
1697 res.set (0, 0, m (1, 1) / d);
1698 res.set (0, 1, -m (0, 1) / d);
1699 res.set (1, 0, -m (1, 0) / d);
1700 res.set (1, 1, m (0, 0) / d);
1704 res.set (0, 0, m (0, 1) - m (0, 0) * m (1, 1) / d);
1705 res.set (0, 1, -m (0, 0) / d);
1706 res.set (1, 0, -m (1, 1) / d);
1707 res.set (1, 1, -1.0 / d);
1718 res.set (0, 0, m (0, 0) - m (0, 1) * m (1, 0) / d);
1719 res.set (0, 1, m (0, 1) / d);
1720 res.set (1, 0, -m (1, 0) / d);
1721 res.set (1, 1, 1.0 / d);
1725 res.set (0, 0, 1.0 / d);
1726 res.set (0, 1, -m (0, 1) / d);
1727 res.set (1, 0, m (1, 0) / d);
1728 res.set (1, 1, m (1, 1) - m (0, 1) * m (1, 0) / d);
1731 d = m (0, 0) * m (1, 1) - m (0, 1) * m (1, 0);
1732 res.set (0, 0, m (1, 1) / d);
1733 res.set (0, 1, -m (0, 1) / d);
1734 res.set (1, 0, -m (1, 0) / d);
1735 res.set (1, 1, m (0, 0) / d);
1742 res.set (0, 0, 1.0 / d);
1743 res.set (0, 1, m (1, 1) / d);
1744 res.set (1, 0, m (0, 0) / d);
1745 res.set (1, 1, m (0, 0) * m (1, 1) / d - m (0, 1));
1756 res.set (0, 0, m (1, 1) / d);
1757 res.set (0, 1, m (1, 0) - m (0, 0) * m (1, 1) / d);
1758 res.set (1, 0, -1.0 / d);
1759 res.set (1, 1, m (0, 0) / d);
1763 res.set (0, 0, m (0, 0) / d);
1764 res.set (0, 1, m (0, 0) * m (1, 1) / d - m (0, 1));
1765 res.set (1, 0, 1.0 / d);
1766 res.set (1, 1, m (1, 1) / d);
1770 res.set (0, 0, m (0, 1) / d);
1771 res.set (0, 1, m (0, 0) - m (0, 1) * m (1, 0) / d);
1772 res.set (1, 0, -1.0 / d);
1773 res.set (1, 1, m (1, 0) / d);
1777 res.set (0, 0, m (1, 0) / d);
1778 res.set (0, 1, m (1, 0) * m (0, 1) / d - m (1, 1));
1779 res.set (1, 0, 1.0 / d);
1780 res.set (1, 1, m (0, 1) / d);
1797 res.set (0, 0, m (0, 1) - m (0, 0) * m (1, 1) / d);
1798 res.set (0, 1, m (0, 0) / d);
1799 res.set (1, 0, -m (1, 1) / d);
1800 res.set (0, 1, 1.0 / d);
1823 res.set (0, 0, m (0, 1) / d);
1824 res.set (0, 1, m (0, 0) - m (0, 1) * m (1, 0) / d);
1825 res.set (1, 0, 1.0 / d);
1826 res.set (0, 1, -m (1, 0) / d);
1854 nr_double_t
rollet (matrix m) {
1855 assert (m.getRows () >= 2 && m.getCols () >= 2);
1858 2 /
abs (m (0, 1) * m (1, 0));
1863 nr_double_t
b1 (matrix m) {
1864 assert (m.getRows () >= 2 && m.getCols () >= 2);
matrix operator-()
Unary minus.
matrix inverse(matrix a)
Compute inverse matrix.
std::complex< nr_double_t > nr_complex_t
matrix adjoint(matrix a)
adjoint matrix
matrix ytos(matrix y, qucs::vector z0)
Admittance matrix to scattering parameters.
matrix real(matrix a)
Real part matrix.
matrix abs(matrix a)
Computes magnitude of each matrix element.
nr_complex_t get(int, int)
Returns the matrix element at the given row and column.
matrix ytoz(matrix y)
Convert admittance matrix to impedance matrix.
matrix operator*(matrix a, nr_complex_t z)
Matrix scaling complex version.
nr_complex_t pow(const nr_complex_t z, const nr_double_t d)
Compute power function with real exponent.
matrix stos(matrix s, qucs::vector zref, qucs::vector z0)
S params to S params.
nr_complex_t detLaplace(matrix a)
Compute determinant of the given matrix using Laplace expansion.
void exchangeRows(int, int)
The function swaps the given rows with each other.
matrix twoport(matrix m, char in, char out)
Generic conversion matrix.
const matrix & operator=(const matrix &)
Assignment operator.
nr_double_t rollet(matrix)
matrix stoh(matrix s, nr_complex_t z1, nr_complex_t z2)
Converts scattering parameters to hybrid matrix.
matrix diagonal(qucs::vector diag)
Create a diagonal matrix from a vector.
matrix()
Create an empty matrix.
matrix inverseGaussJordan(matrix a)
Compute inverse matrix using Gauss-Jordan elimination.
matrix htos(matrix h, nr_complex_t z1, nr_complex_t z2)
Converts hybrid matrix to scattering parameters.
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
matrix imag(matrix a)
Imaginary part matrix.
matrix operator-(matrix a, matrix b)
Matrix subtraction.
void exchangeCols(int, int)
The function swaps the given column with each other.
nr_complex_t sqrt(const nr_complex_t z)
Compute principal value of square root.
matrix stoy(matrix s, qucs::vector z0)
Scattering parameters to admittance matrix.
matrix inverseLaplace(matrix a)
Compute inverse matrix using Laplace expansion.
matrix cztocs(matrix cz, matrix s)
Converts impedance noise correlation matrix to S-parameter noise correlation matrix.
matrix operator+=(matrix)
Intrinsic matrix addition.
nr_double_t dB(const nr_complex_t z)
Magnitude in dB Compute .
matrix ztos(matrix z, qucs::vector z0)
Convert impedance matrix scattering parameters.
matrix operator/(matrix a, nr_complex_t z)
Matrix scaling division by complex version.
nr_complex_t detGauss(matrix a)
Compute determinant Gaussian algorithm.
matrix cstocz(matrix cs, matrix z)
Converts S-parameter noise correlation matrix to impedance noise correlation matrix.
nr_complex_t det(matrix a)
Compute determinant of the given matrix.
Declaration sizeof(struct vcd_scope))
void set(int, int, nr_complex_t)
Sets the matrix element at the given row and column.
matrix cytocz(matrix cy, matrix z)
Converts admittance noise correlation matrix to impedance noise correlation matrix.
matrix transpose(matrix a)
Matrix transposition.
Dense matrix class header file.
matrix operator+(matrix a, matrix b)
Matrix addition.
matrix cstocy(matrix cs, matrix y)
Converts S-parameter noise correlation matrix to admittance noise correlation matrix.
Dense complex matrix class This class defines a matrix object with its methods, operators and operati...
nr_complex_t cofactor(matrix a, int u, int v)
Computes the complex cofactor of the given determinant.
matrix cytocs(matrix cy, matrix s)
Admittance noise correlation matrix to S-parameter noise correlation matrix.
matrix stoa(matrix s, nr_complex_t z1, nr_complex_t z2)
Converts chain matrix to scattering parameters.
matrix stoz(matrix s, qucs::vector z0)
Scattering parameters to impedance matrix.
matrix cztocy(matrix cz, matrix y)
Converts impedance noise correlation matrix to admittance noise correlation matrix.
nr_double_t norm(const nr_complex_t z)
Compute euclidian norm of complex number.
matrix stog(matrix s, nr_complex_t z1, nr_complex_t z2)
matrix gtos(matrix g, nr_complex_t z1, nr_complex_t z2)
matrix eye(int rs, int cs)
Create identity matrix with specified number of rows and columns.
friend matrix imag(matrix)
matrix conj(matrix a)
Conjugate complex matrix.
matrix atos(matrix a, nr_complex_t z1, nr_complex_t z2)
Converts chain matrix to scattering parameters.
friend matrix real(matrix)
matrix ztoy(matrix z)
impedance matrix to admittance matrix.
matrix arg(matrix a)
Computes the argument of each matrix element.
matrix operator-=(matrix)
Intrinsic matrix subtraction.