Qucs-core  0.0.18
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
matvec.cpp
Go to the documentation of this file.
1 /*
2  * matvec.cpp - matrix vector class implementation
3  *
4  * Copyright (C) 2004-2009 Stefan Jahn <stefan@lkcc.org>
5  *
6  * This is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This software is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this package; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  * $Id$
22  *
23  */
24 
25 #if HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28 
29 #include <assert.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <cmath>
34 
35 #include "logging.h"
36 #include "object.h"
37 #include "complex.h"
38 #include "vector.h"
39 #include "matrix.h"
40 #include "matvec.h"
41 
42 #if !HAVE_STRCHR
43 # define strchr index
44 # define strrchr rindex
45 #endif
46 
47 namespace qucs {
48 
49 // Constructor creates an unnamed instance of the matvec class.
51  size = 0;
52  rows = cols = 0;
53  name = NULL;
54  data = NULL;
55 }
56 
57 /* Constructor creates an unnamed instance of the matvec class with a
58  certain number of empty matrices. */
59 matvec::matvec (int length, int r, int c) {
60  size = length;
61  rows = r;
62  cols = c;
63  name = NULL;
64  if (size > 0) {
65  data = new matrix[size];
66  for (int i = 0; i < size; i++) data[i] = matrix (r, c);
67  } else {
68  data = NULL;
69  }
70 }
71 
72 /* The copy constructor creates a new instance based on the given
73  matvec object. */
74 matvec::matvec (const matvec & m) {
75  size = m.size;
76  rows = m.rows;
77  cols = m.cols;
78  name = m.name ? strdup (m.name) : NULL;
79  data = NULL;
80 
81  // copy matvec elements
82  if (size > 0) {
83  data = new matrix[size];
84  for (int i = 0; i < size; i++) data[i] = m.data[i];
85  }
86 }
87 
88 // Destructor deletes a matvec object.
90  if (name) free (name);
91  if (data) delete[] data;
92 }
93 
94 // Sets the name of the matvec object.
95 void matvec::setName (const char * n) {
96  if (name) free (name);
97  name = n ? strdup (n) : NULL;
98 }
99 
100 // Returns the name of the matvec object.
101 char * matvec::getName (void) {
102  return name;
103 }
104 
105 /* This function saves the given vector to the matvec object with the
106  appropriate matrix indices. */
107 void matvec::set (qucs::vector v, int r, int c) {
108  assert (v.getSize () == size &&
109  r >= 0 && r < rows && c >= 0 && c < cols);
110  for (int i = 0; i < size; i++) data[i].set (r, c, v.get (i));
111 }
112 
113 /* The function returns the vector specified by the given matrix
114  indices. If the matrix vector has a valid name 'A' the returned
115  vector gets the name 'A[r,c]'. */
117  assert (r >= 0 && r < rows && c >= 0 && c < cols);
118  qucs::vector res;
119  for (int i = 0; i < size; i++) res.add (data[i].get (r, c));
120  if (name != NULL) {
121  res.setName (createMatrixString (name, r, c));
122  }
123  return res;
124 }
125 
126 /* This function returns a static text representation with the
127  'n[r,c]' scheme indicating a matrix (vector) entry. */
128 char * matvec::createMatrixString (const char * n, int r, int c) {
129  static char str[256]; // hopefully enough
130  sprintf (str, "%s[%d,%d]", n, r + 1, c + 1);
131  return str;
132 }
133 
134 /* This function also returns a static text representation with the
135  'n[r,c]' scheme indicating a matrix (vector) entry but with
136  different arguments. */
137 char * matvec::createMatrixString (char n, int r, int c) {
138  static char str[256]; // hopefully enough
139  sprintf (str, "%c[%d,%d]", n, r + 1, c + 1);
140  return str;
141 }
142 
143 /* The function investigates the given vectors name. If this name
144  matches the 'n[r,c]' pattern it returns the name 'n' and saves the
145  row and column indices as well. The caller is responsible to
146  'free()' the returned string. If the vectors name does not match
147  the pattern the function returns NULL. */
148 char * matvec::isMatrixVector (char * n, int& r, int& c) {
149  char * p; int len;
150  if (n == NULL) return NULL; // nothing todo here
151  if ((p = strchr (n, '[')) != NULL) { // find first '['
152  r = atoi (p + 1) - 1; // get first index
153  if ((p = strchr (p, ',')) != NULL) { // find the ','
154  c = atoi (p + 1) - 1; // get second index
155  if ((p = strchr (p, ']')) != NULL) { // find trailing ']'
156  if (p[1] == '\0') { // identifier must end in ']'
157  // parse actual identifier
158  if ((len = strchr (n, '[') - n) > 0) {
159  p = (char *) malloc (len + 1);
160  memcpy (p, n, len);
161  p[len] = '\0';
162  return p;
163  }
164  }
165  }
166  }
167  }
168  return NULL;
169 }
170 
171 /* This function looks through the vector list given in `data' to find
172  matrix entries specified by `name' and returns the matrix vector
173  dimensions. */
175  int& rs, int& cs, int& ss) {
176  qucs::vector * v;
177  char * vn, * n;
178  int r, c, s;
179  rs = cs = ss = -1;
180  // go through vector list
181  for (v = data; v != NULL; v = (qucs::vector *) v->getNext ()) {
182  vn = v->getName ();
183  // requested matrix name found?
184  if (strstr (vn, name) == vn) {
185  if ((n = matvec::isMatrixVector (vn, r, c)) != NULL) {
186  if (rs < r) rs = r;
187  if (cs < c) cs = c;
188  s = v->getSize ();
189  if (ss < s) ss = s;
190  free (n);
191  }
192  }
193  }
194 }
195 
196 /* This function looks through the vector list given in `data' to find
197  matrix entries specified by `name' and returns a matrix vector
198  object. If there are no such matrices the function returns
199  NULL. */
201 
202  // obtain matrix vector dimensions
203  int rs, cs, ss;
204  getMatrixVectorSize (data, name, rs, cs, ss);
205 
206  qucs::vector * v;
207  char * vn, * n;
208  int r, c;
209  // valid matrix entries found
210  if (rs >= 0 && cs >= 0 && ss > 0) {
211  // create matrix vector
212  matvec * mv = new matvec (ss, rs + 1, cs + 1);
213  mv->setName (name);
214  // go through vector list again and fill in matrix vectors
215  for (v = data; v; v = (qucs::vector *) v->getNext ()) {
216  vn = v->getName ();
217  if (strstr (vn, name) == vn) {
218  if ((n = matvec::isMatrixVector (vn, r, c)) != NULL) {
219  mv->set (*v, r, c);
220  free (n);
221  }
222  }
223  }
224  return mv;
225  }
226  return NULL;
227 }
228 
229 /* This function saves the given matrix in the matrix vector at the
230  specified position. */
231 void matvec::set (matrix m, int idx) {
232  assert (m.getRows () == rows && m.getCols () == cols &&
233  idx >= 0 && idx < size);
234  data[idx] = m;
235 }
236 
237 /* The function returns the matrix stored within the matrix vector at
238  the given position. */
239 matrix matvec::get (int idx) {
240  assert (idx >= 0 && idx < size);
241  matrix res (data[idx]);
242  return res;
243 }
244 
245 // Matrix vector addition.
246 matvec operator + (matvec a, matvec b) {
247  assert (a.getRows () == b.getRows () && a.getCols () == b.getCols () &&
248  a.getSize () == b.getSize ());
249  matvec res (a.getSize (), a.getRows (), a.getCols ());
250  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) + b.get (i), i);
251  return res;
252 }
253 
254 // Matrix vector addition with single matrix.
255 matvec operator + (matvec a, matrix b) {
256  assert (a.getRows () == b.getRows () && a.getCols () == b.getCols ());
257  matvec res (a.getSize (), a.getRows (), a.getCols ());
258  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) + b, i);
259  return res;
260 }
261 
262 // Matrix vector addition with vector.
263 matvec operator + (matvec a, qucs::vector b) {
264  assert (a.getSize () == b.getSize ());
265  matvec res (a.getSize (), a.getRows (), a.getCols ());
266  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) + b.get (i), i);
267  return res;
268 }
269 
270 // Matrix vector addition with vector in different order.
271 matvec operator + (qucs::vector b, matvec a) {
272  return a + b;
273 }
274 
275 // Matrix vector addition with single matrix in different order.
276 matvec operator + (matrix a, matvec b) {
277  return b + a;
278 }
279 
280 // Matrix vector scalar addition.
281 matvec operator + (matvec a, nr_complex_t z) {
282  matvec res (a.getSize (), a.getRows (), a.getCols ());
283  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) + z, i);
284  return res;
285 }
286 
287 // Matrix vector scalar addition in different order.
288 matvec operator + (nr_complex_t z, matvec a) {
289  matvec res (a.getSize (), a.getRows (), a.getCols ());
290  for (int i = 0; i < a.getSize (); i++) res.set (z + a.get (i), i);
291  return res;
292 }
293 
294 // Matrix vector scalar addition.
295 matvec operator + (matvec a, nr_double_t d) {
296  matvec res (a.getSize (), a.getRows (), a.getCols ());
297  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) + d, i);
298  return res;
299 }
300 
301 // Matrix vector scalar addition in different order.
302 matvec operator + (nr_double_t d, matvec a) {
303  matvec res (a.getSize (), a.getRows (), a.getCols ());
304  for (int i = 0; i < a.getSize (); i++) res.set (d + a.get (i), i);
305  return res;
306 }
307 
308 // Matrix vector scalar subtraction.
309 matvec operator - (matvec a, nr_complex_t z) {
310  matvec res (a.getSize (), a.getRows (), a.getCols ());
311  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) - z, i);
312  return res;
313 }
314 
315 // Matrix vector scalar subtraction in different order.
316 matvec operator - (nr_complex_t z, matvec a) {
317  matvec res (a.getSize (), a.getRows (), a.getCols ());
318  for (int i = 0; i < a.getSize (); i++) res.set (z - a.get (i), i);
319  return res;
320 }
321 
322 // Matrix vector scalar subtraction.
323 matvec operator - (matvec a, nr_double_t d) {
324  matvec res (a.getSize (), a.getRows (), a.getCols ());
325  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) - d, i);
326  return res;
327 }
328 
329 // Matrix vector scalar subtraction in different order.
330 matvec operator - (nr_double_t d, matvec a) {
331  matvec res (a.getSize (), a.getRows (), a.getCols ());
332  for (int i = 0; i < a.getSize (); i++) res.set (d - a.get (i), i);
333  return res;
334 }
335 
336 // Intrinsic matrix vector addition.
338  assert (a.getRows () == rows && a.getCols () == cols &&
339  a.getSize () == size);
340  for (int i = 0; i < size; i++) data[i] = data[i] + a.get (i);
341  return *this;
342 }
343 
344 // Matrix vector subtraction.
345 matvec operator - (matvec a, matvec b) {
346  assert (a.getRows () == b.getRows () && a.getCols () == b.getCols () &&
347  a.getSize () == b.getSize ());
348  matvec res (a.getSize (), a.getRows (), a.getCols ());
349  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) - b.get (i), i);
350  return res;
351 }
352 
353 // Matrix vector subtraction with single matrix.
354 matvec operator - (matvec a, matrix b) {
355  assert (a.getRows () == b.getRows () && a.getCols () == b.getCols ());
356  matvec res (a.getSize (), a.getRows (), a.getCols ());
357  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) - b, i);
358  return res;
359 }
360 
361 // Matrix vector subtraction with single matrix in different order.
362 matvec operator - (matrix a, matvec b) {
363  return -b + a;
364 }
365 
366 // Matrix vector subtraction with vector.
367 matvec operator - (matvec a, qucs::vector b) {
368  return -b + a;
369 }
370 
371 // Matrix vector subtraction with vector in different order.
372 matvec operator - (qucs::vector b, matvec a) {
373  return -a + b;
374 }
375 
376 // Unary minus.
378  matvec res (getSize (), getRows (), getCols ());
379  for (int i = 0; i < getSize (); i++) res.set (-data[i], i);
380  return res;
381 }
382 
383 // Intrinsic matrix vector subtraction.
385  assert (a.getRows () == rows && a.getCols () == cols &&
386  a.getSize () == size);
387  for (int i = 0; i < a.getSize (); i++) data[i] = data[i] - a.get (i);
388  return *this;
389 }
390 
391 // Matrix vector scaling.
392 matvec operator * (matvec a, nr_complex_t z) {
393  matvec res (a.getSize (), a.getRows (), a.getCols ());
394  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) * z, i);
395  return res;
396 }
397 
398 // Matrix vector scaling in different order.
399 matvec operator * (nr_complex_t z, matvec a) {
400  return a * z;
401 }
402 
403 // Scalar matrix vector scaling.
404 matvec operator * (matvec a, nr_double_t d) {
405  matvec res (a.getSize (), a.getRows (), a.getCols ());
406  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) * d, i);
407  return res;
408 }
409 
410 // Scalar matrix vector scaling in different order.
411 matvec operator * (nr_double_t d, matvec a) {
412  return a * d;
413 }
414 
415 // Matrix vector scaling by a second vector.
416 matvec operator * (matvec a, qucs::vector b) {
417  assert (a.getSize () == b.getSize ());
418  matvec res (a.getSize (), a.getRows (), a.getCols ());
419  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) * b.get (i), i);
420  return res;
421 }
422 
423 // Matrix vector scaling by a second vector in different order.
424 matvec operator * (qucs::vector a, matvec b) {
425  return b * a;
426 }
427 
428 // Matrix vector scaling.
429 matvec operator / (matvec a, nr_complex_t z) {
430  matvec res (a.getSize (), a.getRows (), a.getCols ());
431  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) / z, i);
432  return res;
433 }
434 
435 // Scalar matrix vector scaling.
436 matvec operator / (matvec a, nr_double_t d) {
437  matvec res (a.getSize (), a.getRows (), a.getCols ());
438  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) / d, i);
439  return res;
440 }
441 
442 // Matrix vector scaling by a second vector.
443 matvec operator / (matvec a, qucs::vector b) {
444  assert (a.getSize () == b.getSize ());
445  matvec res (a.getSize (), a.getRows (), a.getCols ());
446  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) / b.get (i), i);
447  return res;
448 }
449 
450 // Matrix vector multiplication.
451 matvec operator * (matvec a, matvec b) {
452  assert (a.getCols () == b.getRows () && a.getSize () == b.getSize ());
453  matvec res (a.getSize (), a.getRows (), b.getCols ());
454  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) * b.get (i), i);
455  return res;
456 }
457 
458 // Matrix vector multiplication with a single matrix.
459 matvec operator * (matvec a, matrix b) {
460  assert (a.getCols () == b.getRows ());
461  matvec res (a.getSize (), a.getRows (), b.getCols ());
462  for (int i = 0; i < a.getSize (); i++) res.set (a.get (i) * b, i);
463  return res;
464 }
465 
466 // Matrix vector multiplication with a single matrix in different order.
467 matvec operator * (matrix a, matvec b) {
468  return b * a;
469 }
470 
471 // Compute determinants of the given matrix vector.
472 qucs::vector det (matvec a) {
473  qucs::vector res (a.getSize ());
474  for (int i = 0; i < a.getSize (); i++) res.set (det (a.get (i)), i);
475  return res;
476 }
477 
478 // Compute inverse matrices of the given matrix vector.
479 matvec inverse (matvec a) {
480  matvec res (a.getSize (), a.getRows (), a.getCols ());
481  for (int i = 0; i < a.getSize (); i++) res.set (inverse (a.get (i)), i);
482  return res;
483 }
484 
485 // Compute inverse matrices of the given matrix vector.
486 matvec sqr (matvec a) {
487  return a * a;
488 }
489 
490 // Compute n-th power of the given matrix vector.
491 matvec pow (matvec a, int n) {
492  matvec res (a.getSize (), a.getRows (), a.getCols ());
493  for (int i = 0; i < a.getSize (); i++) res.set (pow (a.get (i), n), i);
494  return res;
495 }
496 
497 // Compute n-th powers in the vector of the given matrix vector.
498 matvec pow (matvec a, qucs::vector v) {
499  assert (a.getSize () == v.getSize ());
500  matvec res (a.getSize (), a.getRows (), a.getCols ());
501  for (int i = 0; i < a.getSize (); i++)
502  res.set (pow (a.get (i), (int) real (v.get (i))), i);
503  return res;
504 }
505 
506 // Conjugate complex matrix vector.
507 matvec conj (matvec a) {
508  matvec res (a.getSize (), a.getRows (), a.getCols ());
509  for (int i = 0; i < a.getSize (); i++) res.set (conj (a.get (i)), i);
510  return res;
511 }
512 
513 // Computes magnitude of each matrix vector element.
514 matvec abs (matvec a) {
515  matvec res (a.getSize (), a.getRows (), a.getCols ());
516  for (int i = 0; i < a.getSize (); i++) res.set (abs (a.get (i)), i);
517  return res;
518 }
519 
520 // Computes magnitude in dB of each matrix vector element.
521 matvec dB (matvec a) {
522  matvec res (a.getSize (), a.getRows (), a.getCols ());
523  for (int i = 0; i < a.getSize (); i++) res.set (dB (a.get (i)), i);
524  return res;
525 }
526 
527 // Computes the argument of each matrix vector element.
528 matvec arg (matvec a) {
529  matvec res (a.getSize (), a.getRows (), a.getCols ());
530  for (int i = 0; i < a.getSize (); i++) res.set (arg (a.get (i)), i);
531  return res;
532 }
533 
534 // Real part matrix vector.
535 matvec real (matvec a) {
536  matvec res (a.getSize (), a.getRows (), a.getCols ());
537  for (int i = 0; i < a.getSize (); i++) res.set (real (a.get (i)), i);
538  return res;
539 }
540 
541 // Real part matrix vector.
542 matvec imag (matvec a) {
543  matvec res (a.getSize (), a.getRows (), a.getCols ());
544  for (int i = 0; i < a.getSize (); i++) res.set (imag (a.get (i)), i);
545  return res;
546 }
547 
548 /* The function returns the adjoint complex matrix vector. This is
549  also called the adjugate or transpose conjugate. */
550 matvec adjoint (matvec a) {
551  matvec res (a.getSize (), a.getRows (), a.getCols ());
552  for (int i = 0; i < a.getSize (); i++) res.set (adjoint (a.get (i)), i);
553  return res;
554 }
555 
556 // Transpose the matrix vector.
557 matvec transpose (matvec a) {
558  matvec res (a.getSize (), a.getCols (), a.getRows ());
559  for (int i = 0; i < a.getSize (); i++) res.set (transpose (a.get (i)), i);
560  return res;
561 }
562 
563 /* Convert scattering parameters with the reference impedance 'zref'
564  to scattering parameters with the reference impedance 'z0'. */
565 matvec stos (matvec s, qucs::vector zref, qucs::vector z0) {
566  assert (s.getCols () == s.getRows () &&
567  s.getCols () == zref.getSize () && s.getCols () == z0.getSize ());
568  matvec res (s.getSize (), s.getCols (), s.getRows ());
569  for (int i = 0; i < s.getSize (); i++)
570  res.set (stos (s.get (i), zref, z0), i);
571  return res;
572 }
573 
574 matvec stos (matvec s, nr_complex_t zref, nr_complex_t z0) {
575  int d = s.getRows ();
576  return stos (s, qucs::vector (d, zref), qucs::vector (d, z0));
577 }
578 
579 matvec stos (matvec s, nr_double_t zref, nr_double_t z0) {
580  return stos (s, nr_complex_t (zref, 0), nr_complex_t (z0, 0));
581 }
582 
583 matvec stos (matvec s, qucs::vector zref, nr_complex_t z0) {
584  return stos (s, zref, qucs::vector (zref.getSize (), z0));
585 }
586 
587 matvec stos (matvec s, nr_complex_t zref, qucs::vector z0) {
588  return stos (s, qucs::vector (z0.getSize (), zref), z0);
589 }
590 
591 // Convert scattering parameters to admittance matrix vector.
592 matvec stoy (matvec s, qucs::vector z0) {
593  assert (s.getCols () == s.getRows () && s.getCols () == z0.getSize ());
594  matvec res (s.getSize (), s.getCols (), s.getRows ());
595  for (int i = 0; i < s.getSize (); i++) res.set (stoy (s.get (i), z0), i);
596  return res;
597 }
598 
599 matvec stoy (matvec s, nr_complex_t z0) {
600  return stoy (s, qucs::vector (s.getCols (), z0));
601 }
602 
603 // Convert admittance matrix to scattering parameter matrix vector.
604 matvec ytos (matvec y, qucs::vector z0) {
605  assert (y.getCols () == y.getRows () && y.getCols () == z0.getSize ());
606  matvec res (y.getSize (), y.getCols (), y.getRows ());
607  for (int i = 0; i < y.getSize (); i++) res.set (ytos (y.get (i), z0), i);
608  return res;
609 }
610 
611 matvec ytos (matvec y, nr_complex_t z0) {
612  return ytos (y, qucs::vector (y.getCols (), z0));
613 }
614 
615 // Convert scattering parameters to impedance matrix vector.
616 matvec stoz (matvec s, qucs::vector z0) {
617  assert (s.getCols () == s.getRows () && s.getCols () == z0.getSize ());
618  matvec res (s.getSize (), s.getCols (), s.getRows ());
619  for (int i = 0; i < s.getSize (); i++) res.set (stoz (s.get (i), z0), i);
620  return res;
621 }
622 
623 matvec stoz (matvec s, nr_complex_t z0) {
624  return stoz (s, qucs::vector (s.getCols (), z0));
625 }
626 
627 // Convert impedance matrix vector scattering parameter matrix vector.
628 matvec ztos (matvec z, qucs::vector z0) {
629  assert (z.getCols () == z.getRows () && z.getCols () == z0.getSize ());
630  matvec res (z.getSize (), z.getCols (), z.getRows ());
631  for (int i = 0; i < z.getSize (); i++) res.set (ztos (z.get (i), z0), i);
632  return res;
633 }
634 
635 matvec ztos (matvec z, nr_complex_t z0) {
636  return ztos (z, qucs::vector (z.getCols (), z0));
637 }
638 
639 // Convert impedance matrix vector to admittance matrix vector.
640 matvec ztoy (matvec z) {
641  assert (z.getCols () == z.getRows ());
642  matvec res (z.getSize (), z.getCols (), z.getRows ());
643  for (int i = 0; i < z.getSize (); i++) res.set (ztoy (z.get (i)), i);
644  return res;
645 }
646 
647 // Convert admittance matrix vector to impedance matrix vector.
648 matvec ytoz (matvec y) {
649  assert (y.getCols () == y.getRows ());
650  matvec res (y.getSize (), y.getCols (), y.getRows ());
651  for (int i = 0; i < y.getSize (); i++) res.set (ytoz (y.get (i)), i);
652  return res;
653 }
654 
655 /* This function converts 2x2 matrix vectors from any of the matrix
656  forms Y, Z, H, G and A to any other. Also converts S<->(A, T, H, Y
657  and Z) matrix vectors. */
658 matvec twoport (matvec m, char in, char out) {
659  assert (m.getCols () >= 2 && m.getRows () >= 2);
660  matvec res (m.getSize (), 2, 2);
661  for (int i = 0; i < m.getSize (); i++)
662  res.set (twoport (m.get (i), in, out), i);
663  return res;
664 }
665 
666 /* The function returns the Rollet stability factor vector of the
667  given S-parameter matrix vector. */
668 qucs::vector rollet (matvec m) {
669  assert (m.getCols () >= 2 && m.getRows () >= 2);
670  qucs::vector res (m.getSize ());
671  for (int i = 0; i < m.getSize (); i++) res.set (rollet (m.get (i)), i);
672  return res;
673 }
674 
675 /* The function returns the stability measure B1 vector of the given
676  S-parameter matrix vector. */
677 qucs::vector b1 (matvec m) {
678  assert (m.getCols () >= 2 && m.getRows () >= 2);
679  qucs::vector res (m.getSize ());
680  for (int i = 0; i < m.getSize (); i++) res.set (b1 (m.get (i)), i);
681  return res;
682 }
683 
684 } // namespace qucs
qucs::vector get(int, int)
Definition: matvec.cpp:116
matrix inverse(matrix a)
Compute inverse matrix.
Definition: matrix.cpp:847
std::complex< nr_double_t > nr_complex_t
Definition: complex.h:31
matrix adjoint(matrix a)
adjoint matrix
Definition: matrix.cpp:522
char * name
Definition: matvec.h:163
matrix ytos(matrix y, qucs::vector z0)
Admittance matrix to scattering parameters.
Definition: matrix.cpp:1133
matrix real(matrix a)
Real part matrix.
Definition: matrix.cpp:568
matrix abs(matrix a)
Computes magnitude of each matrix element.
Definition: matrix.cpp:531
nr_complex_t get(int, int)
Returns the matrix element at the given row and column.
Definition: matrix.cpp:194
matrix ytoz(matrix y)
Convert admittance matrix to impedance matrix.
Definition: matrix.cpp:1380
int getSize(void) const
Definition: vector.cpp:192
matrix operator*(matrix a, nr_complex_t z)
Matrix scaling complex version.
Definition: matrix.cpp:298
name
Definition: parse_mdl.y:352
nr_complex_t pow(const nr_complex_t z, const nr_double_t d)
Compute power function with real exponent.
Definition: complex.cpp:238
matrix stos(matrix s, qucs::vector zref, qucs::vector z0)
S params to S params.
Definition: matrix.cpp:890
matrix * data
Definition: matvec.h:164
matrix twoport(matrix m, char in, char out)
Generic conversion matrix.
Definition: matrix.cpp:1594
nr_double_t rollet(matrix)
n
Definition: parse_citi.y:147
r
Definition: parse_mdl.y:515
nr_double_t b1(matrix)
object * getNext(void)
Definition: object.h:59
void setName(const char *)
Definition: matvec.cpp:95
i
Definition: parse_mdl.y:516
nr_complex_t sqr(const nr_complex_t z)
Square of complex number.
Definition: complex.cpp:673
matrix imag(matrix a)
Imaginary part matrix.
Definition: matrix.cpp:581
matrix operator-(matrix a, matrix b)
Matrix subtraction.
Definition: matrix.cpp:259
static matvec * getMatrixVector(qucs::vector *, char *)
Definition: matvec.cpp:200
int rows
Definition: matvec.h:161
matrix stoy(matrix s, qucs::vector z0)
Scattering parameters to admittance matrix.
Definition: matrix.cpp:1082
void setName(const char *)
Definition: object.cpp:78
matvec operator+=(matvec)
Definition: matvec.cpp:337
matvec operator-=(matvec)
Definition: matvec.cpp:384
int getRows(void)
Definition: matvec.h:75
nr_double_t dB(const nr_complex_t z)
Magnitude in dB Compute .
Definition: complex.cpp:528
matrix ztos(matrix z, qucs::vector z0)
Convert impedance matrix scattering parameters.
Definition: matrix.cpp:1018
free($1)
void add(nr_complex_t)
Definition: vector.cpp:151
matrix operator/(matrix a, nr_complex_t z)
Matrix scaling division by complex version.
Definition: matrix.cpp:348
void set(nr_double_t, int)
Definition: vector.cpp:183
nr_complex_t det(matrix a)
Compute determinant of the given matrix.
Definition: matrix.cpp:762
void set(int, int, nr_complex_t)
Sets the matrix element at the given row and column.
Definition: matrix.cpp:205
matvec operator-()
Definition: matvec.cpp:377
matrix transpose(matrix a)
Matrix transposition.
Definition: matrix.cpp:492
Dense matrix class header file.
matrix operator+(matrix a, matrix b)
Matrix addition.
Definition: matrix.cpp:228
Dense complex matrix class This class defines a matrix object with its methods, operators and operati...
Definition: matrix.h:92
v
Definition: parse_zvr.y:141
int cols
Definition: matvec.h:162
char * getName(void)
Definition: matvec.cpp:101
matrix stoz(matrix s, qucs::vector z0)
Scattering parameters to impedance matrix.
Definition: matrix.cpp:973
int getCols(void)
Definition: matrix.h:103
List int
Definition: parse_citi.y:183
y
Definition: parse_mdl.y:499
int getSize(void)
Definition: matvec.h:73
int getCols(void)
Definition: matvec.h:74
void set(qucs::vector, int, int)
Definition: matvec.cpp:107
char * getName(void)
Definition: object.cpp:84
matrix conj(matrix a)
Conjugate complex matrix.
Definition: matrix.cpp:505
zref
Definition: parse_zvr.y:130
#define strchr
Definition: matvec.cpp:43
matrix ztoy(matrix z)
impedance matrix to admittance matrix.
Definition: matrix.cpp:1050
static void getMatrixVectorSize(qucs::vector *, char *, int &, int &, int &)
Definition: matvec.cpp:174
int size
Definition: matvec.h:160
int getRows(void)
Definition: matrix.h:104
nr_complex_t get(int)
Definition: vector.cpp:179
matrix arg(matrix a)
Computes the argument of each matrix element.
Definition: matrix.cpp:555
static char * isMatrixVector(char *, int &, int &)
Definition: matvec.cpp:148
static char * createMatrixString(const char *, int, int)
Definition: matvec.cpp:128
data
Definition: parse_citi.y:117