57 using namespace fourier;
58 using namespace fspecial;
61 #define D(con) ((constant *) (con))->d
62 #define C(con) ((constant *) (con))->c
63 #define V(con) ((constant *) (con))->v
64 #define M(con) ((constant *) (con))->m
65 #define MV(con) ((constant *) (con))->mv
66 #define STR(con) ((constant *) (con))->s
67 #define CHR(con) ((constant *) (con))->chr
68 #define INT(con) ((int) D (con))
69 #define RNG(con) ((constant *) (con))->r
70 #define B(con) ((constant *) (con))->b
72 #define A(a) ((assignment *) (a))
73 #define R(r) ((reference *) (r))
76 #define _ARES(idx) args->getResult(idx)
77 #define _ARG(idx) args->get(idx)
79 #define _D(var,idx) nr_double_t (var) = D (_ARES (idx));
80 #define _BO(var,idx) bool (var) = B (_ARES (idx));
81 #define _CX(var,idx) nr_complex_t * (var) = C (_ARES (idx));
82 #define _V(var,idx) vector * (var) = V (_ARES (idx));
83 #define _M(var,idx) matrix * (var) = M (_ARES (idx));
84 #define _MV(var,idx) matvec * (var) = MV (_ARES (idx));
85 #define _I(var,idx) int (var) = INT (_ARES (idx));
86 #define _R(var,idx) range * (var) = RNG (_ARES (idx));
88 #define _ARR0(var) _R (var,0)
89 #define _ARR1(var) _R (var,1)
90 #define _ARR2(var) _R (var,2)
91 #define _ARI0(var) _I (var,0)
92 #define _ARI1(var) _I (var,1)
93 #define _ARI2(var) _I (var,2)
94 #define _ARD0(var) _D (var,0)
95 #define _ARD1(var) _D (var,1)
96 #define _ARD2(var) _D (var,2)
97 #define _ARB0(var) _BO (var,0)
98 #define _ARB1(var) _BO (var,1)
99 #define _ARB2(var) _BO (var,2)
100 #define _ARC0(var) _CX (var,0)
101 #define _ARC1(var) _CX (var,1)
102 #define _ARC2(var) _CX (var,2)
103 #define _ARM0(var) _M (var,0)
104 #define _ARM1(var) _M (var,1)
105 #define _ARM2(var) _M (var,2)
106 #define _ARV0(var) _V (var,0)
107 #define _ARV1(var) _V (var,1)
108 #define _ARV2(var) _V (var,2)
109 #define _ARMV0(var) _MV (var,0)
110 #define _ARMV1(var) _MV (var,1)
111 #define _ARMV2(var) _MV (var,2)
114 #define _DEFD() constant * res = new constant (TAG_DOUBLE);
115 #define _DEFB() constant * res = new constant (TAG_BOOLEAN);
116 #define _DEFC() constant * res = new constant (TAG_COMPLEX);
117 #define _DEFV() constant * res = new constant (TAG_VECTOR);
118 #define _DEFM() constant * res = new constant (TAG_MATRIX);
119 #define _DEFMV() constant * res = new constant (TAG_MATVEC);
120 #define _DEFR() constant * res = new constant (TAG_RANGE);
123 #define _RETD(var) res->d = (var); return res;
124 #define _RETB(var) res->b = (var); return res;
125 #define _RETC(var) res->c = new nr_complex_t (var); return res;
126 #define _RETV(var) res->v = new vector (var); return res;
127 #define _RETM(var) res->m = new matrix (var); return res;
128 #define _RETMV(var) res->mv = new matvec (var); return res;
129 #define _RETR(var) res->r = (var); return res;
132 #define __RETC() res->c = new nr_complex_t (); return res;
133 #define __RETV() res->v = new vector (); return res;
134 #define __RETM() res->m = new matrix (); return res;
135 #define __RETMV() res->mv = new matvec (); return res;
137 #define SOLVEE(idx) args->get(idx)->solvee
140 #define THROW_MATH_EXCEPTION(txt) do { \
141 qucs::exception * e = new qucs::exception (EXCEPTION_MATH); \
142 e->setText (txt); throw_exception (e); } while (0)
148 #if defined (__STDC__) || defined (__cplusplus)
149 # define QUCS_CONCAT2(a, b) a##b
150 # define QUCS_CONCAT3(a, b, c) a##b##c
152 # define QUCS_CONCAT2(a, b) ab
153 # define QUCS_CONCAT3(a, b, c) abc
157 #define MAKE_FUNC_DEFINITION_0(cfunc) \
158 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d) (constant * args) { \
163 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c) (constant * args) { \
166 _RETC (cfunc (*c)); \
168 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
171 _RETV (cfunc (*v)); \
174 #define MAKE_FUNC_DEFINITION_1(cfunc) \
175 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d) (constant * args) { \
180 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c) (constant * args) { \
183 res->d = cfunc (*c); return res; \
185 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
188 _RETV (cfunc (*v)); \
190 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m) (constant * args) { \
193 _RETM (cfunc (*m)); \
195 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv) (constant * args) {\
198 _RETMV (cfunc (*mv)); \
408 char * p = (
char *) malloc (strlen (s1) + strlen (s2) + 1);
409 strcpy (p, s1); strcat (p, s2);
418 char * p = (
char *) malloc (strlen (s2) + 2);
419 p[0] = c1; strcpy (&p[1], s2);
428 char * p = (
char *) malloc (strlen (s1) + 2);
429 strcpy (p, s1); p[strlen (s1)] = c2; p[strlen (s1) + 1] =
'\0';
629 _RETC ((*c1) * (*c2));
686 if (m1->getCols () != m2->getRows ()) {
688 res->m =
new matrix (m1->getRows (), m2->getCols ());
690 res->m =
new matrix (*m1 * *m2);
727 if (v1->getCols () != v2->getRows ()) {
729 res->mv =
new matvec (v1->getSize (), v1->getRows (), v2->getCols ());
731 res->mv =
new matvec (*v1 * *v2);
768 if (v1->getCols () != m2->getRows ()) {
770 res->mv =
new matvec (v1->getSize (), v1->getRows (), m2->getCols ());
772 res->mv =
new matvec (*v1 * *m2);
781 if (m1->getCols () != v2->getRows ()) {
783 res->mv =
new matvec (v2->getSize (), m1->getRows (), v2->getCols ());
785 res->mv =
new matvec (*m1 * *v2);
921 _RETC ((*c1) % (*c2));
1190 _RETD (d1 < 0.0 ? 180.0 : 0.0);
1287 for (
int i = 0;
i < v1->getSize ();
i++) v->
add (
rad (
real (v1->get (
i))));
1308 for (
int i = 0;
i < v1->getSize ();
i++) v->
add (
deg (
real (v1->get (
i))));
1688 _RETD (0.5 *
log ((1.0 + d1) / (1.0 - d1)));
1707 _RETD (0.5 *
log ((d1 + 1.0) / (d1 - 1.0)));
1723 #define MAKE_FUNC_DEFINITION_2(cfunc) \
1724 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d) (constant * args) { \
1727 _RETD (real (cfunc (rect (d, 0)))); \
1729 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d_d) (constant * args) { \
1733 _RETD (real (cfunc (rect (d, 0), z))); \
1735 constant * evaluate:: QUCS_CONCAT2 (cfunc,_d_c) (constant * args) { \
1739 _RETC (cfunc (rect (d, 0), *z)); \
1741 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c) (constant * args) { \
1744 _RETC (cfunc (*c)); \
1746 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c_d) (constant * args) { \
1750 _RETC (cfunc (*c, z)); \
1752 constant * evaluate:: QUCS_CONCAT2 (cfunc,_c_c) (constant * args) { \
1756 _RETC (cfunc (*c, *z)); \
1758 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
1761 _RETV (cfunc (*v)); \
1763 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v_d) (constant * args) { \
1767 _RETV (cfunc (*v, z)); \
1769 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v_c) (constant * args) { \
1773 _RETV (cfunc (*v, *z)); \
1785 _RETD ((1 + fabs (d1)) / (1 - fabs (d1)));
1797 res->v =
new vector (v1->getSize ());
1798 for (
int i = 0;
i < v1->getSize ();
i++)
1799 res->v->
set ((1 +
abs (v1->get (
i))) / (1 -
abs (v1->get (
i))),
i);
1832 res->d = -
abs (*c1);
1839 _RETD (v1->maximum ());
1892 res->d = -
abs (*c1);
1899 _RETD (v1->minimum ());
2010 _RETD (v1->getSize ());
2021 _RETD (mv->getSize ());
2030 if (r < 1 || r > mv->getRows () || c < 1 || c > mv->getCols ()) {
2032 sprintf (txt,
"matvec indices [%d,%d] out of bounds [1-%d,1-%d]",
2033 r,
c, mv->getRows (), mv->getCols ());
2035 res->v =
new vector (mv->getSize ());
2037 res->v =
new vector (mv->get (r - 1,
c - 1));
2046 if (i < 1 || i > mv->getSize ()) {
2048 sprintf (txt,
"matvec index [%d] out of bounds [1-%d]",
i, mv->getSize ());
2050 res->m =
new matrix (mv->getRows (), mv->getCols ());
2052 res->m =
new matrix (mv->get (
i - 1));
2058 #define EQUATION_HAS_DEPS(v,n) \
2059 ((v)->getDataDependencies() != NULL && \
2060 (v)->getDataDependencies()->length() >= n)
2061 #define EQUATION_DEPS(v) \
2062 ((v)->getDataDependencies() ? (v)->getDataDependencies()->length() : 1)
2070 int type =
_ARG(idx)->getType ();
2073 int didx = (deps ? deps->
length () : 0) - idx;
2074 int dsize =
SOLVEE(0)->getDependencySize (deps, idx);
2080 vres =
new vector (*(res->
v));
2081 skip *= deps ?
SOLVEE(0)->getDataSize (deps->
get (didx - 1)) : 1;
2082 size *= deps ?
SOLVEE(0)->getDataSize (deps->
get (didx)) : 1;
2090 if (i < 0 || i >= len) {
2092 sprintf (txt,
"vector index %d out of bounds [%d,%d]", i, 0, len - 1);
2096 if (i < 0 || i >= len) {
2098 sprintf (txt,
"vector index %d out of bounds [%d,%d]", i, 0, len - 1);
2102 for (n = 0; n < len; n++)
if (r->
inside (n)) size++;
2103 vres =
new vector (size);
2104 for (k = 0, n = 0; n < len; n++) {
2106 vres->
set (res->
v->
get (n), k++);
2112 vres =
new vector (dsize * size);
2113 int len = deps ?
SOLVEE(0)->getDataSize (deps->
get (didx)) : v->getSize ();
2114 if (i < 0 || i >= len) {
2116 sprintf (txt,
"vector index %d (%d) out of bounds [%d,%d]",
2117 idx, i, 0, len - 1);
2121 for (n = k = 0; k < dsize * size; n += skip, k++) {
2122 vres->
set (res->
v->
get (dsize * i + n), k);
2125 if (deps && didx >= 0) {
2129 if (res->
v != NULL)
delete res->
v;
2136 int skip = 1, size = 1;
2137 res->v =
new vector (*v);
2138 extract_vector (args, 1, skip, size, res);
2145 int skip = 1, size = 1;
2146 res->v =
new vector (*v);
2149 sprintf (txt,
"invalid number of vector indices (%d > %d)", 2,
2154 extract_vector (args, 1, skip, size, res);
2155 extract_vector (args, 2, skip, size, res);
2164 if (r < 1 || r > m->getRows () || c < 1 || c > m->getCols ()) {
2166 sprintf (txt,
"matrix indices [%d,%d] out of bounds [1-%d,1-%d]",
2167 r,
c, m->getRows (), m->getCols ());
2180 res->
chr = (
i >= 0 &&
i < (int) strlen (s)) ? s[
i] :
' ';
2185 #define INTERPOL_HELPER() \
2186 constant * arg = new constant (TAG_DOUBLE); \
2188 arg->solvee = args->getResult(0)->solvee; \
2195 return interpolate_v_v_d (args);
2203 if (v1->getSize () < 3) {
2209 nr_double_t last =
real (v2->get (v2->getSize () - 1));
2210 nr_double_t first =
real (v2->get (0));
2219 for (
int k = 0; k < arg->v->getSize (); k++) {
2223 node * gen =
SOLVEE(0)->addGeneratedEquation (arg->v,
"Interpolate");
2224 res->addPrepDependencies (
A(gen)->result);
2231 #define FOURIER_HELPER_1(efunc,cfunc,isign,dep) \
2232 constant * evaluate:: QUCS_CONCAT2 (efunc,_v_v) (constant * args) { \
2236 vector * val = new vector (QUCS_CONCAT2 (cfunc,_1d) (*v)); \
2237 int k = val->getSize (); \
2238 *val = isign > 0 ? *val / k : *val * k; \
2240 int n = t->getSize (); \
2242 THROW_MATH_EXCEPTION ("nonconformant vector lengths"); \
2244 nr_double_t last = real (t->get (n - 1)); \
2245 nr_double_t first = real (t->get (0)); \
2246 nr_double_t delta = (last - first) / (n - 1); \
2247 constant * arg = new constant (TAG_VECTOR); \
2248 arg->v = new vector (::linspace (0, 1.0 / delta, n)); \
2249 arg->solvee = args->getResult(0)->solvee; \
2251 node * gen = SOLVEE(0)->addGeneratedEquation (arg->v, dep); \
2252 res->addPrepDependencies (A(gen)->result); \
2253 res->dropdeps = 1; \
2254 args->append (arg); \
2258 #define FOURIER_HELPER_2(cfunc) \
2259 constant * evaluate:: QUCS_CONCAT2 (cfunc,_v) (constant * args) { \
2262 vector * val = new vector (QUCS_CONCAT2 (cfunc,_1d) (*v)); \
2264 res->dropdeps = 1; \
2284 #define MAKE_FUNC_DEFINITION_3(cfunc) \
2285 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m) (constant * args) { \
2288 _RETM (cfunc (*m)); \
2290 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m_d) (constant * args) { \
2294 _RETM (cfunc (*m, rect (z, 0))); \
2296 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m_c) (constant * args) { \
2300 _RETM (cfunc (*m, *z)); \
2302 constant * evaluate:: QUCS_CONCAT2 (cfunc,_m_v) (constant * args) { \
2306 _RETM (cfunc (*m, *z)); \
2308 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv) (constant * args) { \
2311 _RETMV (cfunc (*m)); \
2313 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv_d) (constant * args) { \
2317 _RETMV (cfunc (*m, rect (z, 0))); \
2319 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv_c) (constant * args) { \
2323 _RETMV (cfunc (*m, *z)); \
2325 constant * evaluate:: QUCS_CONCAT2 (cfunc,_mv_v) (constant * args) { \
2329 _RETMV (cfunc (*m, *z)); \
2364 if (m->getCols () != m->getRows ()) { \
2365 THROW_MATH_EXCEPTION ("stos: not a square matrix"); \
2366 res->m = new matrix (m->getRows (), m->getCols ()); \
2368 #define _CHKMV(mv) \
2369 if (mv->getCols () != mv->getRows ()) { \
2370 THROW_MATH_EXCEPTION ("stos: not a square matrix"); \
2371 res->mv = new matvec (mv->getSize (), mv->getRows (), mv->getCols ()); \
2373 #define _CHKMA(m,cond) \
2375 THROW_MATH_EXCEPTION ("stos: nonconformant arguments"); \
2376 res->m = new matrix (m->getRows (), m->getCols ()); \
2378 #define _CHKMVA(mv,cond) \
2380 THROW_MATH_EXCEPTION ("stos: nonconformant arguments"); \
2381 res->mv = new matvec (mv->getSize (), mv->getRows (), mv->getCols ()); \
2429 _CHKM (m);
_CHKMA (m, m->getRows () == zref->getSize ());
2436 _CHKM (m);
_CHKMA (m, m->getRows () == zref->getSize ());
2443 _CHKM (m);
_CHKMA (m, m->getRows () == zref->getSize ());
2450 _CHKM (m);
_CHKMA (m, m->getRows () == z0->getSize ());
2457 _CHKM (m);
_CHKMA (m, m->getRows () == z0->getSize ());
2464 _CHKM (m);
_CHKMA (m, m->getRows () == z0->getSize () &&
2465 m->getRows () == zref->getSize ());
2514 _CHKMV (mv);
_CHKMVA (mv, mv->getRows () == zref->getSize ());
2521 _CHKMV (mv);
_CHKMVA (mv, mv->getRows () == zref->getSize ());
2528 _CHKMV (mv);
_CHKMVA (mv, mv->getRows () == zref->getSize ());
2535 _CHKMV (mv);
_CHKMVA (mv, mv->getRows () == z0->getSize ());
2542 _CHKMV (mv);
_CHKMVA (mv, mv->getRows () == z0->getSize ());
2549 _CHKMV (mv);
_CHKMVA (mv, mv->getRows () == z0->getSize () &&
2550 mv->getRows () == zref->getSize ());
2559 if (m->getRows () < 2 || m->getCols () < 2) {
2572 if (mv->getRows () < 2 || mv->getCols () < 2) {
2651 k = (1 -
norm (m->get (0, 0))) /
2652 (
abs (m->get (1, 1) -
conj (m->get (0, 0)) *
det (*m)) +
2653 abs (m->get (0, 1) * m->get (1, 0)));
2661 k = (1 -
norm (mv->get (0, 0))) /
2662 (
abs (mv->get (1, 1) -
conj (mv->get (0, 0)) *
det (*mv)) +
2663 abs (mv->get (0, 1) * mv->get (1, 0)));
2671 k = (1 -
norm (m->get (1, 1))) /
2672 (
abs (m->get (0, 0) -
conj (m->get (1, 1)) *
det (*m)) +
2673 abs (m->get (0, 1) * m->get (1, 0)));
2681 k = (1 -
norm (mv->get (1, 1))) /
2682 (
abs (mv->get (0, 0) -
conj (mv->get (1, 1)) *
det (*mv)) +
2683 abs (mv->get (0, 1) * mv->get (1, 0)));
2723 if (start * stop <= 0) {
2725 res->v =
new vector (points);
2732 #define CIRCLE_HELPER_D(argi) \
2733 int n = INT (args->getResult (argi)); \
2735 THROW_MATH_EXCEPTION ("Circle: number of points must be greater than 1"); \
2737 res->v = new vector (); \
2740 constant * arg = new constant (TAG_VECTOR); \
2741 arg->v = new vector (::linspace (0, 360, n)); \
2742 arg->solvee = args->getResult(0)->solvee; \
2744 delete args->get(argi); \
2745 args->get((argi)-1)->setNext (NULL); \
2749 #define CIRCLE_HELPER_A() \
2750 constant * arg = new constant (TAG_VECTOR); \
2751 arg->v = new vector (::linspace (0, 360, 64)); \
2752 arg->solvee = args->getResult(0)->solvee; \
2761 nr_double_t F =
D (
_ARES(3));
2770 for (i = 0, j = 0; i < C.
getSize (); i++) {
2771 for (a = 0; a < arc->
getSize (); a++, j++) {
2777 node * gen =
SOLVEE(4)->addGeneratedEquation (arc,
"Arcs");
2778 res->addPrepDependencies (
A(gen)->result);
2785 return noise_circle_d_v (args);
2790 return noise_circle_d_v (args);
2804 for (f = 0; f < F->
getSize (); f++) {
2806 R =
sqrt (N * N + N * (1 -
norm (*Sopt))) / (1 +
N);
2807 C = *Sopt / (1 +
N);
2808 for (i = 0; i < C.
getSize (); i++) {
2809 for (a = 0; a < arc->
getSize (); a++) {
2818 gen =
SOLVEE(3)->addGeneratedEquation (F,
"NF");
2819 res->addPrepDependencies (
A(gen)->result);
2820 gen =
SOLVEE(4)->addGeneratedEquation (arc,
"Arcs");
2821 res->addPrepDependencies (
A(gen)->result);
2829 return noise_circle_v_v (args);
2834 return noise_circle_v_v (args);
2845 vector * circle =
new vector (
S->getSize () * arc->getSize ());
2847 for (i = 0, d = 0; i <
S->getSize (); i++) {
2848 for (a = 0; a < arc->getSize (); a++, d++) {
2849 v = C.get (i) + R.
get (i) *
exp (
rect (0, 1) *
rad (arc->get (a)));
2853 node * gen =
SOLVEE(1)->addGeneratedEquation (arc,
"Arcs");
2854 res->addPrepDependencies (
A(gen)->result);
2861 return stab_circle_l_v (args);
2866 return stab_circle_l_v (args);
2876 vector * circle =
new vector (
S->getSize () * arc->getSize ());
2878 for (i = 0, d = 0; i <
S->getSize (); i++) {
2879 for (a = 0; a < arc->getSize (); a++, d++) {
2880 v = C.get (i) + R.
get (i) *
exp (
rect (0, 1) *
rad (arc->get (a)));
2884 node * gen =
SOLVEE(1)->addGeneratedEquation (arc,
"Arcs");
2885 res->addPrepDependencies (
A(gen)->result);
2892 return stab_circle_s_v (args);
2897 return stab_circle_s_v (args);
2908 c =
S->get (0, 0) -
conj (
S->get (1, 1)) * D;
2910 s =
S->get (0, 1) *
S->get (1, 0);
2911 g =
G /
norm (
S->get (1, 0));
2912 d = 1 + g * (
norm (
S->get (0, 0)) -
norm (D));
2913 C = g *
conj (c) / d;
2916 vector * circle =
new vector (
S->getSize () * arc->getSize ());
2918 for (i = 0, j = 0; i < C.getSize (); i++) {
2919 for (a = 0; a < arc->getSize (); a++, j++) {
2920 v = C.get (i) + R.
get (i) *
exp (
rect (0, 1) *
rad (arc->get (a)));
2925 node * gen =
SOLVEE(2)->addGeneratedEquation (arc,
"Arcs");
2926 res->addPrepDependencies (
A(gen)->result);
2933 return ga_circle_d_v (args);
2938 return ga_circle_d_v (args);
2947 new vector (
S->getSize () * arc->getSize () *
G->getSize ());
2948 int i, a, j, f;
nr_complex_t v;
vector g,
D,
c,
s, k,
R,
C, d;
2950 c =
S->get (0, 0) -
conj (
S->get (1, 1)) * D;
2952 s =
S->get (0, 1) *
S->get (1, 0);
2953 for (f = 0; f <
G->getSize (); f++) {
2954 g =
G->get (f) /
norm (
S->get (1, 0));
2955 d = 1 + g * (
norm (
S->get (0, 0)) -
norm (D));
2956 C = g *
conj (c) / d;
2958 for (i = 0; i < C.getSize (); i++) {
2959 for (a = 0; a < arc->getSize (); a++) {
2960 v = C.get (i) + R.
get (i) *
exp (
rect (0, 1) *
rad (arc->get (a)));
2961 j = i *
G->getSize () * arc->getSize () + f * arc->getSize () + a;
2968 gen =
SOLVEE(1)->addGeneratedEquation (
G,
"Ga");
2969 res->addPrepDependencies (
A(gen)->result);
2970 gen =
SOLVEE(2)->addGeneratedEquation (arc,
"Arcs");
2971 res->addPrepDependencies (
A(gen)->result);
2978 return ga_circle_v_v (args);
2983 return ga_circle_v_v (args);
2993 c =
S->get (1, 1) -
conj (
S->get (0, 0)) * D;
2995 s =
S->get (0, 1) *
S->get (1, 0);
2996 g =
G /
norm (
S->get (1, 0));
2997 d = 1 + g * (
norm (
S->get (1, 1)) -
norm (D));
2998 C = g *
conj (c) / d;
3001 vector * circle =
new vector (
S->getSize () * arc->getSize ());
3003 for (i = 0, j = 0; i < C.getSize (); i++) {
3004 for (a = 0; a < arc->getSize (); a++, j++) {
3005 v = C.get (i) + R.
get (i) *
exp (
rect (0, 1) *
rad (arc->get (a)));
3010 node * gen =
SOLVEE(2)->addGeneratedEquation (arc,
"Arcs");
3011 res->addPrepDependencies (
A(gen)->result);
3018 return gp_circle_d_v (args);
3023 return gp_circle_d_v (args);
3032 new vector (
S->getSize () * arc->getSize () *
G->getSize ());
3033 int i, a, j, f;
nr_complex_t v;
vector g,
D,
c,
s, k,
R,
C, d;
3035 c =
S->get (1, 1) -
conj (
S->get (0, 0)) * D;
3037 s =
S->get (0, 1) *
S->get (1, 0);
3038 for (f = 0; f <
G->getSize (); f++) {
3039 g =
G->get (f) /
norm (
S->get (1, 0));
3040 d = 1 + g * (
norm (
S->get (1, 1)) -
norm (D));
3041 C = g *
conj (c) / d;
3043 for (i = 0; i < C.getSize (); i++) {
3044 for (a = 0; a < arc->getSize (); a++) {
3045 v = C.get (i) + R.
get (i) *
exp (
rect (0, 1) *
rad (arc->get (a)));
3046 j = i *
G->getSize () * arc->getSize () + f * arc->getSize () + a;
3053 gen =
SOLVEE(1)->addGeneratedEquation (
G,
"Gp");
3054 res->addPrepDependencies (
A(gen)->result);
3055 gen =
SOLVEE(2)->addGeneratedEquation (arc,
"Arcs");
3056 res->addPrepDependencies (
A(gen)->result);
3063 return gp_circle_v_v (args);
3068 return gp_circle_v_v (args);
3077 node * gen =
arg->solvee->addGeneratedEquation (
V (
_ARES (i)),
"Versus");
3078 res->addPrepDependencies (
A(gen)->result);
3090 node * gen =
arg->solvee->addGeneratedEquation (
V (
_ARES (i)),
"Versus");
3091 res->addPrepDependencies (
A(gen)->result);
3103 strlist * deps =
_ARG(0)->collectDataDependencies ();
3104 if (!deps || deps->
length () != 1) {
3110 nr_double_t
t,
diff = NR_MAX;
3111 for (idx = i = 0; i < v->getSize (); i++) {
3112 t =
abs (v->get (i) - d);
3125 strlist * deps =
_ARG(0)->collectDataDependencies ();
3126 if (!deps || deps->
length () != 1) {
3132 nr_double_t
t,
diff = NR_MAX;
3133 for (idx = i = 0; i < v->getSize (); i++) {
3134 t =
abs (v->get (i) - *
c);
3148 strlist * deps =
_ARG(0)->collectDataDependencies ();
3149 if (!deps || deps->
length () != 1) {
3155 nr_double_t
t,
diff = NR_MAX;
3156 for (idx = i = 0; i < indep->
getSize (); i++) {
3157 t =
abs (indep->
get (i) - d);
3163 _RETC (v->get (idx));
3170 strlist * deps =
_ARG(0)->collectDataDependencies ();
3171 if (!deps || deps->
length () != 1) {
3177 nr_double_t
t,
diff = NR_MAX;
3178 for (idx = i = 0; i < indep->
getSize (); i++) {
3179 t =
abs (indep->
get (i) - *
c);
3185 _RETC (v->get (idx));
3193 strlist * deps =
_ARG(0)->collectDataDependencies ();
3194 if (!deps || deps->
length () != 1) {
3200 nr_double_t d,
M = -NR_MAX;
3201 for (
int i = 0;
i < indep->
getSize ();
i++) {
3202 if (r->inside (
real (indep->
get (
i)))) {
3215 strlist * deps =
_ARG(0)->collectDataDependencies ();
3216 if (!deps || deps->
length () != 1) {
3222 nr_double_t d,
M = +NR_MAX;
3223 for (
int i = 0;
i < indep->
getSize ();
i++) {
3224 if (r->inside (
real (indep->
get (
i)))) {
3237 strlist * deps =
_ARG(0)->collectDataDependencies ();
3238 if (!deps || deps->
length () != 1) {
3245 for (k = i = 0; i < indep->
getSize (); i++) {
3246 if (r->inside (
real (indep->
get (i)))) {
3251 _RETC (c / (nr_double_t) k);
3380 _RETD (v1->variance ());
3397 _RETD (v1->stddev ());
3526 if ((
x == 0) && (y == 0)) {
3558 _RETD (0.001 *
pow (10.0, d1 / 10.0));
3564 _RETC (0.001 *
pow (10.0, *c1 / 10.0));
3689 "larger or equal 1");
3701 "larger or equal 1");
3711 if (n < 1 || n >
x->getSize ()) {
3713 "larger or equal 1 and less or equal than the "
3714 "number of vector elements");
3737 for (
int i = 0;
i < v1->getSize ();
i++) v->
add (v1->get (
i) *
kBoverQ);
3748 nr_double_t sval = 0.0;
3754 for (i = 0; i < size / 2; i++) {
3755 sval +=
i0 (
M_PI * alpha *
sqrt (1.0 -
sqr (4.0 * i / size - 1.0)));
3759 sval +=
i0 (
M_PI * alpha *
sqrt (1.0 -
sqr (4.0 * (size / 2) / size - 1.0)));
3761 for (i = 0; i < size / 2; i++) {
3762 v (i) =
sqrt (v (i) / sval);
3763 v (size - 1 - i) = v (i);
3774 return kbd_d_d (args);
3783 _RETD (cond ? d1 : d2);
3799 _RETD (cond ? d1 : (b2 ? 1.0 : 0.0));
3807 _RETD (cond ? (
b1 ? 1.0 : 0.0) : d2);
3812 int t1 =
_ARG(1)->getType ();
3813 int t2 =
_ARG(2)->getType ();
3820 c1 =
B(
_ARES(1)) ? 1.0 : 0.0;
3826 c2 =
B(
_ARES(2)) ? 1.0 : 0.0;
3828 _RETC (cond ? c1 : c2);
3833 int t1 =
_ARG(1)->getType ();
3834 int t2 =
_ARG(2)->getType ();
3842 m1 =
matrix (1); m1 (1,1) =
B(
_ARES(1)) ? 1.0 : 0.0;
break;
3844 m1 = *
M(
_ARES(1));
break;
3852 m2 =
matrix (1); m2 (0,0) =
B(
_ARES(2)) ? 1.0 : 0.0;
break;
3854 m2 = *
M(
_ARES(2));
break;
3857 _RETM (cond ? m1 : m2);
3862 int t1 =
_ARG(1)->getType ();
3863 int t2 =
_ARG(2)->getType ();
3871 v1 =
vector (1); v1 (0) =
B(
_ARES(1)) ? 1.0 : 0.0;
break;
3873 v1 = *
V(
_ARES(1));
break;
3881 v2 =
vector (1); v2 (0) =
B(
_ARES(2)) ? 1.0 : 0.0;
break;
3883 v2 = *
V(
_ARES(2));
break;
3886 _RETV (cond ? v1 : v2);
3891 int t1 =
_ARG(1)->getType ();
3892 int t2 =
_ARG(2)->getType ();
3900 v1 =
vector (1); v1 (0) =
B(
_ARES(1)) ? 1.0 : 0.0;
break;
3902 v1 = *
V(
_ARES(1));
break;
3910 v2 =
vector (1); v2 (0) =
B(
_ARES(2)) ? 1.0 : 0.0;
break;
3912 v2 = *
V(
_ARES(2));
break;
3917 for (a = b = i = 0; i < cond->getSize (); i++) {
3918 v->
add (cond->get (i) != 0.0 ? v1 (a) : v2 (b));
3921 if (a >= v1.
getSize ()) a = 0;
3922 if (b >= v2.
getSize ()) b = 0;
3948 for (
int i = 0;
i < v1->getSize ();
i++) {
3949 v->
add (d0 < v1->
get (
i) ? 1.0 : 0.0);
3974 for (
int i = 0;
i < v1->getSize ();
i++) {
3975 v->
add (*c0 < v1->
get (
i) ? 1.0 : 0.0);
3986 for (
int i = 0;
i < v0->getSize ();
i++) {
3987 v->
add (
real (v0->get (
i)) < d1 ? 1.0 : 0.0);
3998 for (
int i = 0;
i < v0->getSize ();
i++) {
3999 v->
add (v0->get (
i) < *c1 ? 1.0 : 0.0);
4010 for (
int i = 0;
i < v0->getSize ();
i++) {
4011 v->
add (v0->get (
i) < v1->get (
i) ? 1.0 : 0.0);
4037 for (
int i = 0;
i < v1->getSize ();
i++) {
4038 v->
add (d0 >
real (v1->get (
i)) ? 1.0 : 0.0);
4063 for (
int i = 0;
i < v1->getSize ();
i++) {
4064 v->
add (*c0 > v1->get (
i) ? 1.0 : 0.0);
4075 for (
int i = 0;
i < v0->getSize ();
i++) {
4076 v->
add (
real (v0->get (
i)) > d1 ? 1.0 : 0.0);
4087 for (
int i = 0;
i < v0->getSize ();
i++) {
4088 v->
add (v0->get (
i) > *c1 ? 1.0 : 0.0);
4099 for (
int i = 0;
i < v0->getSize ();
i++) {
4100 v->
add (v0->get (
i) > v1->get (
i) ? 1.0 : 0.0);
4126 for (
int i = 0;
i < v1->getSize ();
i++) {
4127 v->
add (d0 <=
real (v1->get (
i)) ? 1.0 : 0.0);
4152 for (
int i = 0;
i < v1->getSize ();
i++) {
4153 v->
add (*c0 <= v1->
get (
i) ? 1.0 : 0.0);
4164 for (
int i = 0;
i < v0->getSize ();
i++) {
4165 v->
add (
real (v0->get (
i)) <= d1 ? 1.0 : 0.0);
4176 for (
int i = 0;
i < v0->getSize ();
i++) {
4177 v->
add (v0->get (
i) <= *c1 ? 1.0 : 0.0);
4188 for (
int i = 0;
i < v0->getSize ();
i++) {
4189 v->
add (v0->get (
i) <= v1->get (
i) ? 1.0 : 0.0);
4215 for (
int i = 0;
i < v1->getSize ();
i++) {
4216 v->
add (d0 >=
real (v1->get (
i)) ? 1.0 : 0.0);
4241 for (
int i = 0;
i < v1->getSize ();
i++) {
4242 v->
add (*c0 >= v1->get (
i) ? 1.0 : 0.0);
4253 for (
int i = 0;
i < v0->getSize ();
i++) {
4254 v->
add (
real (v0->get (
i)) >= d1 ? 1.0 : 0.0);
4265 for (
int i = 0;
i < v0->getSize ();
i++) {
4266 v->
add (v0->get (
i) >= *c1 ? 1.0 : 0.0);
4277 for (
int i = 0;
i < v0->getSize ();
i++) {
4278 v->
add (v0->get (
i) >= v1->get (
i) ? 1.0 : 0.0);
4304 for (
int i = 0;
i < v1->getSize ();
i++) {
4305 v->
add (d0 ==
real (v1->get (
i)) ? 1.0 : 0.0);
4330 for (
int i = 0;
i < v1->getSize ();
i++) {
4331 v->
add (*c0 == v1->get (
i) ? 1.0 : 0.0);
4342 for (
int i = 0;
i < v0->getSize ();
i++) {
4343 v->
add (
real (v0->get (
i)) == d1 ? 1.0 : 0.0);
4354 for (
int i = 0;
i < v0->getSize ();
i++) {
4355 v->
add (v0->get (
i) == *c1 ? 1.0 : 0.0);
4366 for (
int i = 0;
i < v0->getSize ();
i++) {
4367 v->
add (v0->get (
i) == v1->get (
i) ? 1.0 : 0.0);
4400 for (
int i = 0;
i < v1->getSize ();
i++) {
4401 v->
add (d0 !=
real (v1->get (
i)) ? 1.0 : 0.0);
4426 for (
int i = 0;
i < v1->getSize ();
i++) {
4427 v->
add (*c0 != v1->get (
i) ? 1.0 : 0.0);
4438 for (
int i = 0;
i < v0->getSize ();
i++) {
4439 v->
add (
real (v0->get (
i)) != d1 ? 1.0 : 0.0);
4450 for (
int i = 0;
i < v0->getSize ();
i++) {
4451 v->
add (v0->get (
i) != *c1 ? 1.0 : 0.0);
4462 for (
int i = 0;
i < v0->getSize ();
i++) {
4463 v->
add (v0->get (
i) != v1->get (
i) ? 1.0 : 0.0);
4502 _RETD (((nr_double_t) ::rand ()) / (nr_double_t) RAND_MAX);
4506 static int done = 0;
4510 unsigned int i0 = (
unsigned int) d0;
4525 switch (
arg->getType ()) {
4527 v->
add (*(c->
c));
break;
4529 v->
add (c->
d);
break;
4531 v->
add (c->
b ? 1.0 : 0.0);
break;
4533 v->
add (c->
v);
break;
4535 v->
add (0.0);
break;
4551 switch (
arg->getType ()) {
4553 v->
add (*(c->
c));
break;
4555 v->
add (c->
d);
break;
4557 v->
add (c->
b ? 1.0 : 0.0);
break;
4559 v->
add (c->
v);
break;
4561 if (c->
chr ==
';') {
4570 v->
add (0.0);
break;
4575 for (r = 0, c = 0, v = va; v != NULL; v = (
vector *) v->
getNext (), r++) {
4576 if (c < v->getSize ()) c = v->
getSize ();
4581 for (r = 0, v = va; v != NULL; v = vn, r++) {
4582 for (c = 0; c < v->
getSize (); c++) {
4583 m->
set (r, c, v->
get (c));
4613 for (
int i = 0;
i < rlen;
i++) {
4620 node * gen =
SOLVEE(0)->addGeneratedEquation (rfeq,
"Frequency");
4621 res->addPrepDependencies (
A(gen)->result);