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 |
1368
|
34 #include "f77-uscore.h" |
|
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 { |
|
197 int len = length (); |
|
198 return ComplexColumnVector (dup (data (), len), len); |
|
199 } |
|
200 |
|
201 ComplexRowVector |
|
202 conj (const ComplexRowVector& a) |
|
203 { |
|
204 int a_len = a.length (); |
|
205 ComplexRowVector retval; |
|
206 if (a_len > 0) |
|
207 retval = ComplexRowVector (conj_dup (a.data (), a_len), a_len); |
|
208 return retval; |
|
209 } |
|
210 |
|
211 // resize is the destructive equivalent for this one |
|
212 |
|
213 ComplexRowVector |
|
214 ComplexRowVector::extract (int c1, int c2) const |
|
215 { |
|
216 if (c1 > c2) { int tmp = c1; c1 = c2; c2 = tmp; } |
|
217 |
|
218 int new_c = c2 - c1 + 1; |
|
219 |
|
220 ComplexRowVector result (new_c); |
|
221 |
|
222 for (int i = 0; i < new_c; i++) |
|
223 result.elem (i) = elem (c1+i); |
|
224 |
|
225 return result; |
|
226 } |
|
227 |
|
228 // row vector by row vector -> row vector operations |
|
229 |
|
230 ComplexRowVector& |
|
231 ComplexRowVector::operator += (const RowVector& a) |
|
232 { |
|
233 int len = length (); |
|
234 if (len != a.length ()) |
|
235 { |
|
236 (*current_liboctave_error_handler) |
|
237 ("nonconformant vector += operation attempted"); |
|
238 return *this; |
|
239 } |
|
240 |
|
241 if (len == 0) |
|
242 return *this; |
|
243 |
|
244 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
245 |
|
246 add2 (d, a.data (), len); |
|
247 return *this; |
|
248 } |
|
249 |
|
250 ComplexRowVector& |
|
251 ComplexRowVector::operator -= (const RowVector& a) |
|
252 { |
|
253 int len = length (); |
|
254 if (len != a.length ()) |
|
255 { |
|
256 (*current_liboctave_error_handler) |
|
257 ("nonconformant vector -= operation attempted"); |
|
258 return *this; |
|
259 } |
|
260 |
|
261 if (len == 0) |
|
262 return *this; |
|
263 |
|
264 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
265 |
|
266 subtract2 (d, a.data (), len); |
|
267 return *this; |
|
268 } |
|
269 |
|
270 ComplexRowVector& |
|
271 ComplexRowVector::operator += (const ComplexRowVector& a) |
|
272 { |
|
273 int len = length (); |
|
274 if (len != a.length ()) |
|
275 { |
|
276 (*current_liboctave_error_handler) |
|
277 ("nonconformant vector += operation attempted"); |
|
278 return *this; |
|
279 } |
|
280 |
|
281 if (len == 0) |
|
282 return *this; |
|
283 |
|
284 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
285 |
|
286 add2 (d, a.data (), len); |
|
287 return *this; |
|
288 } |
|
289 |
|
290 ComplexRowVector& |
|
291 ComplexRowVector::operator -= (const ComplexRowVector& a) |
|
292 { |
|
293 int len = length (); |
|
294 if (len != a.length ()) |
|
295 { |
|
296 (*current_liboctave_error_handler) |
|
297 ("nonconformant vector -= operation attempted"); |
|
298 return *this; |
|
299 } |
|
300 |
|
301 if (len == 0) |
|
302 return *this; |
|
303 |
|
304 Complex *d = fortran_vec (); // Ensures only one reference to my privates! |
|
305 |
|
306 subtract2 (d, a.data (), len); |
|
307 return *this; |
|
308 } |
|
309 |
|
310 // row vector by scalar -> row vector operations |
|
311 |
|
312 ComplexRowVector |
|
313 operator + (const ComplexRowVector& v, double s) |
|
314 { |
|
315 int len = v.length (); |
|
316 return ComplexRowVector (add (v.data (), len, s), len); |
|
317 } |
|
318 |
|
319 ComplexRowVector |
|
320 operator - (const ComplexRowVector& v, double s) |
|
321 { |
|
322 int len = v.length (); |
|
323 return ComplexRowVector (subtract (v.data (), len, s), len); |
|
324 } |
|
325 |
|
326 ComplexRowVector |
|
327 operator * (const ComplexRowVector& v, double s) |
|
328 { |
|
329 int len = v.length (); |
|
330 return ComplexRowVector (multiply (v.data (), len, s), len); |
|
331 } |
|
332 |
|
333 ComplexRowVector |
|
334 operator / (const ComplexRowVector& v, double s) |
|
335 { |
|
336 int len = v.length (); |
|
337 return ComplexRowVector (divide (v.data (), len, s), len); |
|
338 } |
|
339 |
1205
|
340 ComplexRowVector |
|
341 operator + (const RowVector& v, const Complex& s) |
|
342 { |
|
343 int len = v.length (); |
|
344 return ComplexRowVector (add (v.data (), len, s), len); |
|
345 } |
|
346 |
|
347 ComplexRowVector |
|
348 operator - (const RowVector& v, const Complex& s) |
|
349 { |
|
350 int len = v.length (); |
|
351 return ComplexRowVector (subtract (v.data (), len, s), len); |
|
352 } |
|
353 |
|
354 ComplexRowVector |
|
355 operator * (const RowVector& v, const Complex& s) |
|
356 { |
|
357 int len = v.length (); |
|
358 return ComplexRowVector (multiply (v.data (), len, s), len); |
|
359 } |
|
360 |
|
361 ComplexRowVector |
|
362 operator / (const RowVector& v, const Complex& s) |
|
363 { |
|
364 int len = v.length (); |
|
365 return ComplexRowVector (divide (v.data (), len, s), len); |
|
366 } |
|
367 |
458
|
368 // scalar by row vector -> row vector operations |
|
369 |
|
370 ComplexRowVector |
|
371 operator + (double s, const ComplexRowVector& a) |
|
372 { |
|
373 int a_len = a.length (); |
|
374 return ComplexRowVector (add (a.data (), a_len, s), a_len); |
|
375 } |
|
376 |
|
377 ComplexRowVector |
|
378 operator - (double s, const ComplexRowVector& a) |
|
379 { |
|
380 int a_len = a.length (); |
|
381 return ComplexRowVector (subtract (s, a.data (), a_len), a_len); |
|
382 } |
|
383 |
|
384 ComplexRowVector |
|
385 operator * (double s, const ComplexRowVector& a) |
|
386 { |
|
387 int a_len = a.length (); |
|
388 return ComplexRowVector (multiply (a.data (), a_len, s), a_len); |
|
389 } |
|
390 |
|
391 ComplexRowVector |
|
392 operator / (double s, const ComplexRowVector& a) |
|
393 { |
|
394 int a_len = a.length (); |
|
395 return ComplexRowVector (divide (s, a.data (), a_len), a_len); |
|
396 } |
|
397 |
1205
|
398 ComplexRowVector |
|
399 operator + (const Complex& s, const RowVector& a) |
458
|
400 { |
1485
|
401 int a_len = a.length (); |
|
402 return ComplexRowVector (add (a.data (), a_len, s), a_len); |
458
|
403 } |
|
404 |
1205
|
405 ComplexRowVector |
|
406 operator - (const Complex& s, const RowVector& a) |
458
|
407 { |
1485
|
408 int a_len = a.length (); |
|
409 return ComplexRowVector (subtract (s, a.data (), a_len), a_len); |
1205
|
410 } |
458
|
411 |
1205
|
412 ComplexRowVector |
|
413 operator * (const Complex& s, const RowVector& a) |
|
414 { |
1485
|
415 int a_len = a.length (); |
|
416 return ComplexRowVector (multiply (a.data (), a_len, s), a_len); |
1205
|
417 } |
458
|
418 |
1205
|
419 ComplexRowVector |
|
420 operator / (const Complex& s, const RowVector& a) |
|
421 { |
1485
|
422 int a_len = a.length (); |
|
423 return ComplexRowVector (divide (s, a.data (), a_len), a_len); |
458
|
424 } |
|
425 |
|
426 // row vector by matrix -> row vector |
|
427 |
|
428 ComplexRowVector |
|
429 operator * (const ComplexRowVector& v, const ComplexMatrix& a) |
|
430 { |
|
431 int len = v.length (); |
|
432 if (a.rows () != len) |
|
433 { |
|
434 (*current_liboctave_error_handler) |
|
435 ("nonconformant vector multiplication attempted"); |
|
436 return ComplexRowVector (); |
|
437 } |
|
438 |
1677
|
439 if (len == 0) |
|
440 return ComplexRowVector (a.cols (), 0.0); |
458
|
441 |
1360
|
442 // Transpose A to form A'*x == (x'*A)' |
458
|
443 |
|
444 int a_nr = a.rows (); |
|
445 int a_nc = a.cols (); |
|
446 |
|
447 int ld = a_nr; |
|
448 |
1677
|
449 Complex *y = new Complex [a_nc]; |
458
|
450 |
1678
|
451 F77_FCN (zgemv, ZGEMV) ("T", a_nr, a_nc, 1.0, a.data (), ld, |
1253
|
452 v.data (), 1, 0.0, y, 1, 1L); |
458
|
453 |
1677
|
454 return ComplexRowVector (y, a_nc); |
458
|
455 } |
|
456 |
1205
|
457 ComplexRowVector |
|
458 operator * (const RowVector& v, const ComplexMatrix& a) |
|
459 { |
|
460 ComplexRowVector tmp (v); |
|
461 return tmp * a; |
|
462 } |
|
463 |
458
|
464 // row vector by row vector -> row vector operations |
|
465 |
|
466 ComplexRowVector |
|
467 operator + (const ComplexRowVector& v, const RowVector& a) |
|
468 { |
|
469 int len = v.length (); |
|
470 if (len != a.length ()) |
|
471 { |
|
472 (*current_liboctave_error_handler) |
|
473 ("nonconformant vector addition attempted"); |
|
474 return ComplexRowVector (); |
|
475 } |
|
476 |
|
477 if (len == 0) |
|
478 return ComplexRowVector (0); |
|
479 |
|
480 return ComplexRowVector (add (v.data (), a.data (), len), len); |
|
481 } |
|
482 |
|
483 ComplexRowVector |
|
484 operator - (const ComplexRowVector& v, const RowVector& a) |
|
485 { |
|
486 int len = v.length (); |
|
487 if (len != a.length ()) |
|
488 { |
|
489 (*current_liboctave_error_handler) |
|
490 ("nonconformant vector subtraction attempted"); |
|
491 return ComplexRowVector (); |
|
492 } |
|
493 |
|
494 if (len == 0) |
|
495 return ComplexRowVector (0); |
|
496 |
|
497 return ComplexRowVector (subtract (v.data (), a.data (), len), len); |
|
498 } |
|
499 |
|
500 ComplexRowVector |
1205
|
501 operator + (const RowVector& v, const ComplexRowVector& a) |
|
502 { |
|
503 int len = v.length (); |
|
504 if (len != a.length ()) |
|
505 { |
|
506 (*current_liboctave_error_handler) |
|
507 ("nonconformant vector addition attempted"); |
|
508 return ComplexRowVector (); |
|
509 } |
|
510 |
|
511 if (len == 0) |
|
512 return ComplexRowVector (0); |
|
513 |
|
514 return ComplexRowVector (add (v.data (), a.data (), len), len); |
|
515 } |
|
516 |
|
517 ComplexRowVector |
|
518 operator - (const RowVector& v, const ComplexRowVector& a) |
|
519 { |
|
520 int len = v.length (); |
|
521 if (len != a.length ()) |
|
522 { |
|
523 (*current_liboctave_error_handler) |
|
524 ("nonconformant vector subtraction attempted"); |
|
525 return ComplexRowVector (); |
|
526 } |
|
527 |
|
528 if (len == 0) |
|
529 return ComplexRowVector (0); |
|
530 |
|
531 return ComplexRowVector (subtract (v.data (), a.data (), len), len); |
|
532 } |
|
533 |
|
534 ComplexRowVector |
458
|
535 product (const ComplexRowVector& v, const RowVector& a) |
|
536 { |
|
537 int len = v.length (); |
|
538 if (len != a.length ()) |
|
539 { |
|
540 (*current_liboctave_error_handler) |
|
541 ("nonconformant vector product attempted"); |
|
542 return ComplexRowVector (); |
|
543 } |
|
544 |
|
545 if (len == 0) |
|
546 return ComplexRowVector (0); |
|
547 |
|
548 return ComplexRowVector (multiply (v.data (), a.data (), len), len); |
|
549 } |
|
550 |
|
551 ComplexRowVector |
|
552 quotient (const ComplexRowVector& v, const RowVector& a) |
|
553 { |
|
554 int len = v.length (); |
|
555 if (len != a.length ()) |
|
556 { |
|
557 (*current_liboctave_error_handler) |
|
558 ("nonconformant vector quotient attempted"); |
|
559 return ComplexRowVector (); |
|
560 } |
|
561 |
|
562 if (len == 0) |
|
563 return ComplexRowVector (0); |
|
564 |
|
565 return ComplexRowVector (divide (v.data (), a.data (), len), len); |
|
566 } |
|
567 |
1205
|
568 ComplexRowVector |
|
569 product (const RowVector& v, const ComplexRowVector& a) |
|
570 { |
|
571 int len = v.length (); |
|
572 if (len != a.length ()) |
|
573 { |
|
574 (*current_liboctave_error_handler) |
|
575 ("nonconformant vector product attempted"); |
|
576 return ComplexRowVector (); |
|
577 } |
|
578 |
|
579 if (len == 0) |
|
580 return ComplexRowVector (0); |
|
581 |
|
582 return ComplexRowVector (multiply (v.data (), a.data (), len), len); |
|
583 } |
|
584 |
|
585 ComplexRowVector |
|
586 quotient (const RowVector& v, const ComplexRowVector& a) |
|
587 { |
|
588 int len = v.length (); |
|
589 if (len != a.length ()) |
|
590 { |
|
591 (*current_liboctave_error_handler) |
|
592 ("nonconformant vector quotient attempted"); |
|
593 return ComplexRowVector (); |
|
594 } |
|
595 |
|
596 if (len == 0) |
|
597 return ComplexRowVector (0); |
|
598 |
|
599 return ComplexRowVector (divide (v.data (), a.data (), len), len); |
|
600 } |
|
601 |
458
|
602 // other operations |
|
603 |
|
604 ComplexRowVector |
|
605 map (c_c_Mapper f, const ComplexRowVector& a) |
|
606 { |
|
607 ComplexRowVector b (a); |
|
608 b.map (f); |
|
609 return b; |
|
610 } |
|
611 |
|
612 void |
|
613 ComplexRowVector::map (c_c_Mapper f) |
|
614 { |
|
615 for (int i = 0; i < length (); i++) |
|
616 elem (i) = f (elem (i)); |
|
617 } |
|
618 |
|
619 Complex |
|
620 ComplexRowVector::min (void) const |
|
621 { |
|
622 int len = length (); |
|
623 if (len == 0) |
|
624 return Complex (0.0); |
|
625 |
|
626 Complex res = elem (0); |
|
627 double absres = abs (res); |
|
628 |
|
629 for (int i = 1; i < len; i++) |
|
630 if (abs (elem (i)) < absres) |
|
631 { |
|
632 res = elem (i); |
|
633 absres = abs (res); |
|
634 } |
|
635 |
|
636 return res; |
|
637 } |
|
638 |
|
639 Complex |
|
640 ComplexRowVector::max (void) const |
|
641 { |
|
642 int len = length (); |
|
643 if (len == 0) |
|
644 return Complex (0.0); |
|
645 |
|
646 Complex res = elem (0); |
|
647 double absres = abs (res); |
|
648 |
|
649 for (int i = 1; i < len; i++) |
|
650 if (abs (elem (i)) > absres) |
|
651 { |
|
652 res = elem (i); |
|
653 absres = abs (res); |
|
654 } |
|
655 |
|
656 return res; |
|
657 } |
|
658 |
|
659 // i/o |
|
660 |
|
661 ostream& |
|
662 operator << (ostream& os, const ComplexRowVector& a) |
|
663 { |
|
664 // int field_width = os.precision () + 7; |
|
665 for (int i = 0; i < a.length (); i++) |
|
666 os << " " /* setw (field_width) */ << a.elem (i); |
|
667 return os; |
|
668 } |
|
669 |
|
670 istream& |
|
671 operator >> (istream& is, ComplexRowVector& a) |
|
672 { |
|
673 int len = a.length(); |
|
674 |
|
675 if (len < 1) |
|
676 is.clear (ios::badbit); |
|
677 else |
|
678 { |
|
679 Complex tmp; |
|
680 for (int i = 0; i < len; i++) |
|
681 { |
|
682 is >> tmp; |
|
683 if (is) |
|
684 a.elem (i) = tmp; |
|
685 else |
|
686 break; |
|
687 } |
|
688 } |
532
|
689 return is; |
458
|
690 } |
|
691 |
1205
|
692 // row vector by column vector -> scalar |
|
693 |
|
694 // row vector by column vector -> scalar |
|
695 |
|
696 Complex |
|
697 operator * (const ComplexRowVector& v, const ColumnVector& a) |
|
698 { |
|
699 ComplexColumnVector tmp (a); |
|
700 return v * tmp; |
|
701 } |
|
702 |
|
703 Complex |
|
704 operator * (const ComplexRowVector& v, const ComplexColumnVector& a) |
|
705 { |
|
706 int len = v.length (); |
|
707 if (len != a.length ()) |
|
708 { |
|
709 (*current_liboctave_error_handler) |
|
710 ("nonconformant vector multiplication attempted"); |
|
711 return 0.0; |
|
712 } |
|
713 |
|
714 Complex retval (0.0, 0.0); |
|
715 |
|
716 for (int i = 0; i < len; i++) |
|
717 retval += v.elem (i) * a.elem (i); |
|
718 |
|
719 return retval; |
|
720 } |
|
721 |
|
722 // other operations |
|
723 |
|
724 ComplexRowVector |
|
725 linspace (const Complex& x1, const Complex& x2, int n) |
|
726 { |
|
727 ComplexRowVector retval; |
|
728 |
|
729 if (n > 0) |
|
730 { |
|
731 retval.resize (n); |
|
732 Complex delta = (x2 - x1) / (n - 1); |
|
733 retval.elem (0) = x1; |
|
734 for (int i = 1; i < n-1; i++) |
|
735 retval.elem (i) = x1 + i * delta; |
|
736 retval.elem (n-1) = x2; |
|
737 } |
|
738 |
|
739 return retval; |
|
740 } |
|
741 |
458
|
742 /* |
|
743 ;;; Local Variables: *** |
|
744 ;;; mode: C++ *** |
|
745 ;;; page-delimiter: "^/\\*" *** |
|
746 ;;; End: *** |
|
747 */ |