458
|
1 // RowVector manipulations. -*- C++ -*- |
|
2 /* |
|
3 |
1011
|
4 Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton |
458
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
458
|
21 |
|
22 */ |
|
23 |
1296
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
458
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
458
|
30 #endif |
|
31 |
|
32 #include <iostream.h> |
|
33 |
1847
|
34 #include "f77-fcn.h" |
1368
|
35 #include "lo-error.h" |
458
|
36 #include "mx-base.h" |
|
37 #include "mx-inlines.cc" |
1650
|
38 #include "oct-cmplx.h" |
458
|
39 |
|
40 // Fortran functions we call. |
|
41 |
|
42 extern "C" |
|
43 { |
1253
|
44 int F77_FCN (zgemv, ZGEMV) (const char*, const int&, const int&, |
|
45 const Complex&, const Complex*, |
|
46 const int&, const Complex*, const int&, |
|
47 const Complex&, Complex*, const int&, |
|
48 long); |
458
|
49 } |
|
50 |
1360
|
51 // Complex Row Vector class |
458
|
52 |
|
53 ComplexRowVector::ComplexRowVector (const RowVector& a) |
1214
|
54 : MArray<Complex> (a.length ()) |
458
|
55 { |
|
56 for (int i = 0; i < length (); i++) |
|
57 elem (i) = a.elem (i); |
|
58 } |
|
59 |
|
60 int |
|
61 ComplexRowVector::operator == (const ComplexRowVector& a) const |
|
62 { |
|
63 int len = length (); |
|
64 if (len != a.length ()) |
|
65 return 0; |
|
66 return equal (data (), a.data (), len); |
|
67 } |
|
68 |
|
69 int |
|
70 ComplexRowVector::operator != (const ComplexRowVector& a) const |
|
71 { |
|
72 return !(*this == a); |
|
73 } |
|
74 |
|
75 // destructive insert/delete/reorder operations |
|
76 |
|
77 ComplexRowVector& |
|
78 ComplexRowVector::insert (const RowVector& a, int c) |
|
79 { |
|
80 int a_len = a.length (); |
1699
|
81 if (c < 0 || c + a_len > length ()) |
458
|
82 { |
|
83 (*current_liboctave_error_handler) ("range error for insert"); |
|
84 return *this; |
|
85 } |
|
86 |
|
87 for (int i = 0; i < a_len; i++) |
|
88 elem (c+i) = a.elem (i); |
|
89 |
|
90 return *this; |
|
91 } |
|
92 |
|
93 ComplexRowVector& |
|
94 ComplexRowVector::insert (const ComplexRowVector& a, int c) |
|
95 { |
|
96 int a_len = a.length (); |
1699
|
97 if (c < 0 || c + a_len > length ()) |
458
|
98 { |
|
99 (*current_liboctave_error_handler) ("range error for insert"); |
|
100 return *this; |
|
101 } |
|
102 |
|
103 for (int i = 0; i < a_len; i++) |
|
104 elem (c+i) = a.elem (i); |
|
105 |
|
106 return *this; |
|
107 } |
|
108 |
|
109 ComplexRowVector& |
|
110 ComplexRowVector::fill (double val) |
|
111 { |
|
112 int len = length (); |
|
113 if (len > 0) |
|
114 for (int i = 0; i < len; i++) |
|
115 elem (i) = val; |
|
116 return *this; |
|
117 } |
|
118 |
|
119 ComplexRowVector& |
|
120 ComplexRowVector::fill (const Complex& val) |
|
121 { |
|
122 int len = length (); |
|
123 if (len > 0) |
|
124 for (int i = 0; i < len; i++) |
|
125 elem (i) = val; |
|
126 return *this; |
|
127 } |
|
128 |
|
129 ComplexRowVector& |
|
130 ComplexRowVector::fill (double val, int c1, int c2) |
|
131 { |
|
132 int len = length (); |
|
133 if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) |
|
134 { |
|
135 (*current_liboctave_error_handler) ("range error for fill"); |
|
136 return *this; |
|
137 } |
|
138 |
|
139 if (c1 > c2) { int tmp = c1; c1 = c2; c2 = tmp; } |
|
140 |
|
141 for (int i = c1; i <= c2; i++) |
|
142 elem (i) = val; |
|
143 |
|
144 return *this; |
|
145 } |
|
146 |
|
147 ComplexRowVector& |
|
148 ComplexRowVector::fill (const Complex& val, int c1, int c2) |
|
149 { |
|
150 int len = length (); |
|
151 if (c1 < 0 || c2 < 0 || c1 >= len || c2 >= len) |
|
152 { |
|
153 (*current_liboctave_error_handler) ("range error for fill"); |
|
154 return *this; |
|
155 } |
|
156 |
|
157 if (c1 > c2) { int tmp = c1; c1 = c2; c2 = tmp; } |
|
158 |
|
159 for (int i = c1; i <= c2; i++) |
|
160 elem (i) = val; |
|
161 |
|
162 return *this; |
|
163 } |
|
164 |
|
165 ComplexRowVector |
|
166 ComplexRowVector::append (const RowVector& a) const |
|
167 { |
|
168 int len = length (); |
|
169 int nc_insert = len; |
|
170 ComplexRowVector retval (len + a.length ()); |
|
171 retval.insert (*this, 0); |
|
172 retval.insert (a, nc_insert); |
|
173 return retval; |
|
174 } |
|
175 |
|
176 ComplexRowVector |
|
177 ComplexRowVector::append (const ComplexRowVector& a) const |
|
178 { |
|
179 int len = length (); |
|
180 int nc_insert = len; |
|
181 ComplexRowVector retval (len + a.length ()); |
|
182 retval.insert (*this, 0); |
|
183 retval.insert (a, nc_insert); |
|
184 return retval; |
|
185 } |
|
186 |
|
187 ComplexColumnVector |
|
188 ComplexRowVector::hermitian (void) const |
|
189 { |
|
190 int len = length (); |
|
191 return ComplexColumnVector (conj_dup (data (), len), len); |
|
192 } |
|
193 |
|
194 ComplexColumnVector |
|
195 ComplexRowVector::transpose (void) const |
|
196 { |
1858
|
197 return ComplexColumnVector (*this); |
458
|
198 } |
|
199 |
|
200 ComplexRowVector |
|
201 conj (const ComplexRowVector& a) |
|
202 { |
|
203 int a_len = a.length (); |
|
204 ComplexRowVector retval; |
|
205 if (a_len > 0) |
|
206 retval = ComplexRowVector (conj_dup (a.data (), a_len), a_len); |
|
207 return retval; |
|
208 } |
|
209 |
|
210 // resize is the destructive equivalent for this one |
|
211 |
|
212 ComplexRowVector |
|
213 ComplexRowVector::extract (int c1, int c2) const |
|
214 { |
|
215 if (c1 > c2) { int tmp = c1; c1 = c2; c2 = tmp; } |
|
216 |
|
217 int new_c = c2 - c1 + 1; |
|
218 |
|
219 ComplexRowVector result (new_c); |
|
220 |
|
221 for (int i = 0; i < new_c; i++) |
|
222 result.elem (i) = elem (c1+i); |
|
223 |
|
224 return result; |
|
225 } |
|
226 |
|
227 // row vector by row vector -> row vector operations |
|
228 |
|
229 ComplexRowVector& |
|
230 ComplexRowVector::operator += (const RowVector& a) |
|
231 { |
|
232 int len = length (); |
|
233 if (len != a.length ()) |
|
234 { |
|
235 (*current_liboctave_error_handler) |
|
236 ("nonconformant vector += operation attempted"); |
|
237 return *this; |
|
238 } |
|
239 |
|
240 if (len == 0) |
|
241 return *this; |
|
242 |
|
243 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
244 |
|
245 add2 (d, a.data (), len); |
|
246 return *this; |
|
247 } |
|
248 |
|
249 ComplexRowVector& |
|
250 ComplexRowVector::operator -= (const RowVector& a) |
|
251 { |
|
252 int len = length (); |
|
253 if (len != a.length ()) |
|
254 { |
|
255 (*current_liboctave_error_handler) |
|
256 ("nonconformant vector -= operation attempted"); |
|
257 return *this; |
|
258 } |
|
259 |
|
260 if (len == 0) |
|
261 return *this; |
|
262 |
|
263 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
264 |
|
265 subtract2 (d, a.data (), len); |
|
266 return *this; |
|
267 } |
|
268 |
|
269 ComplexRowVector& |
|
270 ComplexRowVector::operator += (const ComplexRowVector& a) |
|
271 { |
|
272 int len = length (); |
|
273 if (len != a.length ()) |
|
274 { |
|
275 (*current_liboctave_error_handler) |
|
276 ("nonconformant vector += operation attempted"); |
|
277 return *this; |
|
278 } |
|
279 |
|
280 if (len == 0) |
|
281 return *this; |
|
282 |
|
283 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
284 |
|
285 add2 (d, a.data (), len); |
|
286 return *this; |
|
287 } |
|
288 |
|
289 ComplexRowVector& |
|
290 ComplexRowVector::operator -= (const ComplexRowVector& a) |
|
291 { |
|
292 int len = length (); |
|
293 if (len != a.length ()) |
|
294 { |
|
295 (*current_liboctave_error_handler) |
|
296 ("nonconformant vector -= operation attempted"); |
|
297 return *this; |
|
298 } |
|
299 |
|
300 if (len == 0) |
|
301 return *this; |
|
302 |
|
303 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
304 |
|
305 subtract2 (d, a.data (), len); |
|
306 return *this; |
|
307 } |
|
308 |
|
309 // row vector by scalar -> row vector operations |
|
310 |
|
311 ComplexRowVector |
|
312 operator + (const ComplexRowVector& v, double s) |
|
313 { |
|
314 int len = v.length (); |
|
315 return ComplexRowVector (add (v.data (), len, s), len); |
|
316 } |
|
317 |
|
318 ComplexRowVector |
|
319 operator - (const ComplexRowVector& v, double s) |
|
320 { |
|
321 int len = v.length (); |
|
322 return ComplexRowVector (subtract (v.data (), len, s), len); |
|
323 } |
|
324 |
|
325 ComplexRowVector |
|
326 operator * (const ComplexRowVector& v, double s) |
|
327 { |
|
328 int len = v.length (); |
|
329 return ComplexRowVector (multiply (v.data (), len, s), len); |
|
330 } |
|
331 |
|
332 ComplexRowVector |
|
333 operator / (const ComplexRowVector& v, double s) |
|
334 { |
|
335 int len = v.length (); |
|
336 return ComplexRowVector (divide (v.data (), len, s), len); |
|
337 } |
|
338 |
1205
|
339 ComplexRowVector |
|
340 operator + (const RowVector& v, const Complex& s) |
|
341 { |
|
342 int len = v.length (); |
|
343 return ComplexRowVector (add (v.data (), len, s), len); |
|
344 } |
|
345 |
|
346 ComplexRowVector |
|
347 operator - (const RowVector& v, const Complex& s) |
|
348 { |
|
349 int len = v.length (); |
|
350 return ComplexRowVector (subtract (v.data (), len, s), len); |
|
351 } |
|
352 |
|
353 ComplexRowVector |
|
354 operator * (const RowVector& v, const Complex& s) |
|
355 { |
|
356 int len = v.length (); |
|
357 return ComplexRowVector (multiply (v.data (), len, s), len); |
|
358 } |
|
359 |
|
360 ComplexRowVector |
|
361 operator / (const RowVector& v, const Complex& s) |
|
362 { |
|
363 int len = v.length (); |
|
364 return ComplexRowVector (divide (v.data (), len, s), len); |
|
365 } |
|
366 |
458
|
367 // scalar by row vector -> row vector operations |
|
368 |
|
369 ComplexRowVector |
|
370 operator + (double s, const ComplexRowVector& a) |
|
371 { |
|
372 int a_len = a.length (); |
|
373 return ComplexRowVector (add (a.data (), a_len, s), a_len); |
|
374 } |
|
375 |
|
376 ComplexRowVector |
|
377 operator - (double s, const ComplexRowVector& a) |
|
378 { |
|
379 int a_len = a.length (); |
|
380 return ComplexRowVector (subtract (s, a.data (), a_len), a_len); |
|
381 } |
|
382 |
|
383 ComplexRowVector |
|
384 operator * (double s, const ComplexRowVector& a) |
|
385 { |
|
386 int a_len = a.length (); |
|
387 return ComplexRowVector (multiply (a.data (), a_len, s), a_len); |
|
388 } |
|
389 |
|
390 ComplexRowVector |
|
391 operator / (double s, const ComplexRowVector& a) |
|
392 { |
|
393 int a_len = a.length (); |
|
394 return ComplexRowVector (divide (s, a.data (), a_len), a_len); |
|
395 } |
|
396 |
1205
|
397 ComplexRowVector |
|
398 operator + (const Complex& s, const RowVector& a) |
458
|
399 { |
1485
|
400 int a_len = a.length (); |
|
401 return ComplexRowVector (add (a.data (), a_len, s), a_len); |
458
|
402 } |
|
403 |
1205
|
404 ComplexRowVector |
|
405 operator - (const Complex& s, const RowVector& a) |
458
|
406 { |
1485
|
407 int a_len = a.length (); |
|
408 return ComplexRowVector (subtract (s, a.data (), a_len), a_len); |
1205
|
409 } |
458
|
410 |
1205
|
411 ComplexRowVector |
|
412 operator * (const Complex& s, const RowVector& a) |
|
413 { |
1485
|
414 int a_len = a.length (); |
|
415 return ComplexRowVector (multiply (a.data (), a_len, s), a_len); |
1205
|
416 } |
458
|
417 |
1205
|
418 ComplexRowVector |
|
419 operator / (const Complex& s, const RowVector& a) |
|
420 { |
1485
|
421 int a_len = a.length (); |
|
422 return ComplexRowVector (divide (s, a.data (), a_len), a_len); |
458
|
423 } |
|
424 |
|
425 // row vector by matrix -> row vector |
|
426 |
|
427 ComplexRowVector |
|
428 operator * (const ComplexRowVector& v, const ComplexMatrix& a) |
|
429 { |
|
430 int len = v.length (); |
|
431 if (a.rows () != len) |
|
432 { |
|
433 (*current_liboctave_error_handler) |
|
434 ("nonconformant vector multiplication attempted"); |
|
435 return ComplexRowVector (); |
|
436 } |
|
437 |
1677
|
438 if (len == 0) |
|
439 return ComplexRowVector (a.cols (), 0.0); |
458
|
440 |
1360
|
441 // Transpose A to form A'*x == (x'*A)' |
458
|
442 |
|
443 int a_nr = a.rows (); |
|
444 int a_nc = a.cols (); |
|
445 |
|
446 int ld = a_nr; |
|
447 |
1677
|
448 Complex *y = new Complex [a_nc]; |
458
|
449 |
1678
|
450 F77_FCN (zgemv, ZGEMV) ("T", a_nr, a_nc, 1.0, a.data (), ld, |
1253
|
451 v.data (), 1, 0.0, y, 1, 1L); |
458
|
452 |
1677
|
453 return ComplexRowVector (y, a_nc); |
458
|
454 } |
|
455 |
1205
|
456 ComplexRowVector |
|
457 operator * (const RowVector& v, const ComplexMatrix& a) |
|
458 { |
|
459 ComplexRowVector tmp (v); |
|
460 return tmp * a; |
|
461 } |
|
462 |
458
|
463 // row vector by row vector -> row vector operations |
|
464 |
|
465 ComplexRowVector |
|
466 operator + (const ComplexRowVector& v, const RowVector& a) |
|
467 { |
|
468 int len = v.length (); |
|
469 if (len != a.length ()) |
|
470 { |
|
471 (*current_liboctave_error_handler) |
|
472 ("nonconformant vector addition attempted"); |
|
473 return ComplexRowVector (); |
|
474 } |
|
475 |
|
476 if (len == 0) |
|
477 return ComplexRowVector (0); |
|
478 |
|
479 return ComplexRowVector (add (v.data (), a.data (), len), len); |
|
480 } |
|
481 |
|
482 ComplexRowVector |
|
483 operator - (const ComplexRowVector& v, const RowVector& a) |
|
484 { |
|
485 int len = v.length (); |
|
486 if (len != a.length ()) |
|
487 { |
|
488 (*current_liboctave_error_handler) |
|
489 ("nonconformant vector subtraction attempted"); |
|
490 return ComplexRowVector (); |
|
491 } |
|
492 |
|
493 if (len == 0) |
|
494 return ComplexRowVector (0); |
|
495 |
|
496 return ComplexRowVector (subtract (v.data (), a.data (), len), len); |
|
497 } |
|
498 |
|
499 ComplexRowVector |
1205
|
500 operator + (const RowVector& v, const ComplexRowVector& a) |
|
501 { |
|
502 int len = v.length (); |
|
503 if (len != a.length ()) |
|
504 { |
|
505 (*current_liboctave_error_handler) |
|
506 ("nonconformant vector addition attempted"); |
|
507 return ComplexRowVector (); |
|
508 } |
|
509 |
|
510 if (len == 0) |
|
511 return ComplexRowVector (0); |
|
512 |
|
513 return ComplexRowVector (add (v.data (), a.data (), len), len); |
|
514 } |
|
515 |
|
516 ComplexRowVector |
|
517 operator - (const RowVector& v, const ComplexRowVector& a) |
|
518 { |
|
519 int len = v.length (); |
|
520 if (len != a.length ()) |
|
521 { |
|
522 (*current_liboctave_error_handler) |
|
523 ("nonconformant vector subtraction attempted"); |
|
524 return ComplexRowVector (); |
|
525 } |
|
526 |
|
527 if (len == 0) |
|
528 return ComplexRowVector (0); |
|
529 |
|
530 return ComplexRowVector (subtract (v.data (), a.data (), len), len); |
|
531 } |
|
532 |
|
533 ComplexRowVector |
458
|
534 product (const ComplexRowVector& v, const RowVector& a) |
|
535 { |
|
536 int len = v.length (); |
|
537 if (len != a.length ()) |
|
538 { |
|
539 (*current_liboctave_error_handler) |
|
540 ("nonconformant vector product attempted"); |
|
541 return ComplexRowVector (); |
|
542 } |
|
543 |
|
544 if (len == 0) |
|
545 return ComplexRowVector (0); |
|
546 |
|
547 return ComplexRowVector (multiply (v.data (), a.data (), len), len); |
|
548 } |
|
549 |
|
550 ComplexRowVector |
|
551 quotient (const ComplexRowVector& v, const RowVector& a) |
|
552 { |
|
553 int len = v.length (); |
|
554 if (len != a.length ()) |
|
555 { |
|
556 (*current_liboctave_error_handler) |
|
557 ("nonconformant vector quotient attempted"); |
|
558 return ComplexRowVector (); |
|
559 } |
|
560 |
|
561 if (len == 0) |
|
562 return ComplexRowVector (0); |
|
563 |
|
564 return ComplexRowVector (divide (v.data (), a.data (), len), len); |
|
565 } |
|
566 |
1205
|
567 ComplexRowVector |
|
568 product (const RowVector& v, const ComplexRowVector& a) |
|
569 { |
|
570 int len = v.length (); |
|
571 if (len != a.length ()) |
|
572 { |
|
573 (*current_liboctave_error_handler) |
|
574 ("nonconformant vector product attempted"); |
|
575 return ComplexRowVector (); |
|
576 } |
|
577 |
|
578 if (len == 0) |
|
579 return ComplexRowVector (0); |
|
580 |
|
581 return ComplexRowVector (multiply (v.data (), a.data (), len), len); |
|
582 } |
|
583 |
|
584 ComplexRowVector |
|
585 quotient (const RowVector& v, const ComplexRowVector& a) |
|
586 { |
|
587 int len = v.length (); |
|
588 if (len != a.length ()) |
|
589 { |
|
590 (*current_liboctave_error_handler) |
|
591 ("nonconformant vector quotient attempted"); |
|
592 return ComplexRowVector (); |
|
593 } |
|
594 |
|
595 if (len == 0) |
|
596 return ComplexRowVector (0); |
|
597 |
|
598 return ComplexRowVector (divide (v.data (), a.data (), len), len); |
|
599 } |
|
600 |
458
|
601 // other operations |
|
602 |
|
603 ComplexRowVector |
|
604 map (c_c_Mapper f, const ComplexRowVector& a) |
|
605 { |
|
606 ComplexRowVector b (a); |
|
607 b.map (f); |
|
608 return b; |
|
609 } |
|
610 |
|
611 void |
|
612 ComplexRowVector::map (c_c_Mapper f) |
|
613 { |
|
614 for (int i = 0; i < length (); i++) |
|
615 elem (i) = f (elem (i)); |
|
616 } |
|
617 |
|
618 Complex |
|
619 ComplexRowVector::min (void) const |
|
620 { |
|
621 int len = length (); |
|
622 if (len == 0) |
|
623 return Complex (0.0); |
|
624 |
|
625 Complex res = elem (0); |
|
626 double absres = abs (res); |
|
627 |
|
628 for (int i = 1; i < len; i++) |
|
629 if (abs (elem (i)) < absres) |
|
630 { |
|
631 res = elem (i); |
|
632 absres = abs (res); |
|
633 } |
|
634 |
|
635 return res; |
|
636 } |
|
637 |
|
638 Complex |
|
639 ComplexRowVector::max (void) const |
|
640 { |
|
641 int len = length (); |
|
642 if (len == 0) |
|
643 return Complex (0.0); |
|
644 |
|
645 Complex res = elem (0); |
|
646 double absres = abs (res); |
|
647 |
|
648 for (int i = 1; i < len; i++) |
|
649 if (abs (elem (i)) > absres) |
|
650 { |
|
651 res = elem (i); |
|
652 absres = abs (res); |
|
653 } |
|
654 |
|
655 return res; |
|
656 } |
|
657 |
|
658 // i/o |
|
659 |
|
660 ostream& |
|
661 operator << (ostream& os, const ComplexRowVector& a) |
|
662 { |
|
663 // int field_width = os.precision () + 7; |
|
664 for (int i = 0; i < a.length (); i++) |
|
665 os << " " /* setw (field_width) */ << a.elem (i); |
|
666 return os; |
|
667 } |
|
668 |
|
669 istream& |
|
670 operator >> (istream& is, ComplexRowVector& a) |
|
671 { |
|
672 int len = a.length(); |
|
673 |
|
674 if (len < 1) |
|
675 is.clear (ios::badbit); |
|
676 else |
|
677 { |
|
678 Complex tmp; |
|
679 for (int i = 0; i < len; i++) |
|
680 { |
|
681 is >> tmp; |
|
682 if (is) |
|
683 a.elem (i) = tmp; |
|
684 else |
|
685 break; |
|
686 } |
|
687 } |
532
|
688 return is; |
458
|
689 } |
|
690 |
1205
|
691 // row vector by column vector -> scalar |
|
692 |
|
693 // row vector by column vector -> scalar |
|
694 |
|
695 Complex |
|
696 operator * (const ComplexRowVector& v, const ColumnVector& a) |
|
697 { |
|
698 ComplexColumnVector tmp (a); |
|
699 return v * tmp; |
|
700 } |
|
701 |
|
702 Complex |
|
703 operator * (const ComplexRowVector& v, const ComplexColumnVector& a) |
|
704 { |
|
705 int len = v.length (); |
|
706 if (len != a.length ()) |
|
707 { |
|
708 (*current_liboctave_error_handler) |
|
709 ("nonconformant vector multiplication attempted"); |
|
710 return 0.0; |
|
711 } |
|
712 |
|
713 Complex retval (0.0, 0.0); |
|
714 |
|
715 for (int i = 0; i < len; i++) |
|
716 retval += v.elem (i) * a.elem (i); |
|
717 |
|
718 return retval; |
|
719 } |
|
720 |
|
721 // other operations |
|
722 |
|
723 ComplexRowVector |
|
724 linspace (const Complex& x1, const Complex& x2, int n) |
|
725 { |
|
726 ComplexRowVector retval; |
|
727 |
|
728 if (n > 0) |
|
729 { |
|
730 retval.resize (n); |
|
731 Complex delta = (x2 - x1) / (n - 1); |
|
732 retval.elem (0) = x1; |
|
733 for (int i = 1; i < n-1; i++) |
|
734 retval.elem (i) = x1 + i * delta; |
|
735 retval.elem (n-1) = x2; |
|
736 } |
|
737 |
|
738 return retval; |
|
739 } |
|
740 |
458
|
741 /* |
|
742 ;;; Local Variables: *** |
|
743 ;;; mode: C++ *** |
|
744 ;;; page-delimiter: "^/\\*" *** |
|
745 ;;; End: *** |
|
746 */ |