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