forked from mathnet/mathnet-yttrium
/
ComplexMatrix.cs
3208 lines (2855 loc) · 98 KB
/
ComplexMatrix.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#region Math.NET Iridium (LGPL) by Ruegg
// Math.NET Iridium, part of the Math.NET Project
// http://mathnet.opensourcedotnet.info
//
// Copyright (c) 2004-2008, Christoph Rüegg, http://christoph.ruegg.name
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#endregion
using System;
using System.Text;
using System.Collections.Generic;
using MathNet.Numerics.Distributions;
namespace MathNet.Numerics.LinearAlgebra
{
/// <summary>
/// Complex Matrix.
/// </summary>
[Serializable]
public class ComplexMatrix :
IMatrix<Complex>,
ICloneable
{
int _rowCount;
int _columnCount;
/// <summary>
/// Array for internal storage of elements.
/// </summary>
Complex[][] _data;
/// <summary>
/// Gets the number of rows.
/// </summary>
public int RowCount
{
get { return _rowCount; }
}
/// <summary>
/// Gets the number of columns.
/// </summary>
public int ColumnCount
{
get { return _columnCount; }
}
/// <summary>
/// Gets or set the element indexed by <c>(i, j)</c>
/// in the <c>Matrix</c>.
/// </summary>
/// <param name="i">Row index.</param>
/// <param name="j">Column index.</param>
public Complex this[int i, int j]
{
get
{
return _data[i][j];
}
set
{
_data[i][j] = value;
// NOTE (cdr, 2008-03-11): The folloing line is cheap,
// but still expensive if this setter is called
// a lot of times.
// - We should recommend out users to build the internal
// jagged array first and then create the matrix for it;
// or to get the internal double[][] handle.
// - Consider to omit it here and make the users call
// ResetComputations() after they finished chaniging the matrix.
ResetOnDemandComputations();
}
}
#region Data -> Matrix: Constructors and static constructive methods
/// <summary>
/// Construct an m-by-n matrix of zeros.
/// </summary>
/// <param name="m">Number of rows.</param>
/// <param name="n">Number of columns.</param>
public
ComplexMatrix(
int m,
int n
)
{
_data = CreateMatrixData(m, n);
_rowCount = m;
_columnCount = n;
InitOnDemandComputations();
}
/// <summary>
/// Constructs a m-by-m square matrix.
/// </summary>
/// <param name="m">Size of the square matrix.</param>
/// <param name="s">Diagonal value.</param>
public
ComplexMatrix(
int m,
Complex s
)
{
_data = new Complex[m][];
_rowCount = m;
_columnCount = m;
for(int i = 0; i < m; i++)
{
Complex[] col = new Complex[m];
col[i] = s;
_data[i] = col;
}
InitOnDemandComputations();
}
/// <summary>
/// Construct an m-by-n constant matrix.
/// </summary>
/// <param name="m">Number of rows.</param>
/// <param name="n">Number of columns.</param>
/// <param name="s">Fill the matrix with this scalar value.</param>
public
ComplexMatrix(
int m,
int n,
Complex s
)
{
_data = new Complex[m][];
_rowCount = m;
_columnCount = n;
for(int i = 0; i < m; i++)
{
Complex[] col = new Complex[n];
for(int j = 0; j < n; j++)
{
col[j] = s;
}
_data[i] = col;
}
InitOnDemandComputations();
}
/// <summary>
/// Constructs a matrix from a jagged 2-D array,
/// directly using the provided array as internal data structure.
/// </summary>
/// <param name="A">Two-dimensional jagged array of complex numbers.</param>
/// <exception cref="System.ArgumentException">All rows must have the same length.</exception>
/// <seealso cref="ComplexMatrix.Create(Complex[][])"/>
/// <seealso cref="ComplexMatrix.Create(Complex[,])"/>
public
ComplexMatrix(
Complex[][] A
)
{
_data = A;
GetRowColumnCount(_data, out _rowCount, out _columnCount);
InitOnDemandComputations();
}
/// <summary>
/// Construct a matrix from a one-dimensional packed array.
/// </summary>
/// <param name="vals">One-dimensional array of complex numbers, packed by columns (ala Fortran).</param>
/// <param name="m">Number of rows.</param>
/// <exception cref="System.ArgumentException">Array length must be a multiple of m.</exception>
public
ComplexMatrix(
Complex[] vals,
int m
)
{
_rowCount = m;
if(m == 0)
{
_columnCount = 0;
if(vals.Length != 0)
{
throw new ArgumentException(Properties.LocalStrings.ArgumentVectorLengthsMultipleOf("m"));
}
}
else
{
int rem;
_columnCount = Math.DivRem(vals.Length, m, out rem);
if(rem != 0)
{
throw new ArgumentException(Properties.LocalStrings.ArgumentVectorLengthsMultipleOf("m"));
}
}
_data = new Complex[_rowCount][];
for(int i = 0; i < _rowCount; i++)
{
Complex[] col = new Complex[_columnCount];
for(int j = 0; j < _columnCount; j++)
{
col[j] = vals[i + j * _rowCount];
}
_data[i] = col;
}
InitOnDemandComputations();
}
/// <summary>
/// Constructs a matrix from a copy of a 2-D array by deep-copy.
/// </summary>
/// <param name="A">Two-dimensional array of complex numbers.</param>
public static
ComplexMatrix
Create(
Complex[][] A
)
{
return new ComplexMatrix(CloneMatrixData(A));
}
/// <summary>
/// Constructs a matrix from a copy of a 2-D array by deep-copy.
/// </summary>
/// <param name="A">Two-dimensional array of complex numbers.</param>
[CLSCompliant(false)]
public static
ComplexMatrix
Create(
Complex[,] A
)
{
int rows = A.GetLength(0);
int columns = A.GetLength(1);
Complex[][] newData = new Complex[rows][];
for(int i = 0; i < rows; i++)
{
Complex[] col = new Complex[columns];
for(int j = 0; j < columns; j++)
{
col[j] = A[i, j];
}
newData[i] = col;
}
return new ComplexMatrix(newData);
}
/// <summary>
/// Construct a matrix from a real matrix by deep-copy.
/// </summary>
/// <param name="realMatrix">The real matrix to copy from.</param>
public static
ComplexMatrix
Create(
IMatrix<double> realMatrix
)
{
int rows = realMatrix.RowCount;
int columns = realMatrix.ColumnCount;
Complex[][] newData = new Complex[rows][];
for(int i = 0; i < rows; i++)
{
Complex[] col = new Complex[columns];
for(int j = 0; j < columns; j++)
{
col[j] = realMatrix[i, j];
}
newData[i] = col;
}
return new ComplexMatrix(newData);
}
/// <summary>
/// Construct a complex matrix from a set of complex column vectors.
/// </summary>
public static
ComplexMatrix
CreateFromColumns(
IList<ComplexVector> columnVectors
)
{
if(null == columnVectors)
{
throw new ArgumentNullException("columnVectors");
}
if(0 == columnVectors.Count)
{
throw new ArgumentOutOfRangeException("columnVectors");
}
int rows = columnVectors[0].Length;
int columns = columnVectors.Count;
Complex[][] newData = new Complex[rows][];
for(int i = 0; i < rows; i++)
{
Complex[] newRow = new Complex[columns];
for(int j = 0; j < columns; j++)
{
newRow[j] = columnVectors[j][i];
}
newData[i] = newRow;
}
return new ComplexMatrix(newData);
}
/// <summary>
/// Construct a complex matrix from a set of complex row vectors.
/// </summary>
public static
ComplexMatrix
CreateFromRows(
IList<ComplexVector> rowVectors
)
{
if(null == rowVectors)
{
throw new ArgumentNullException("columnVectors");
}
if(0 == rowVectors.Count)
{
throw new ArgumentOutOfRangeException("columnVectors");
}
int rows = rowVectors.Count;
Complex[][] newData = new Complex[rows][];
for(int i = 0; i < rows; i++)
{
newData[i] = rowVectors[i].CopyToArray();
}
return new ComplexMatrix(newData);
}
/// <summary>
/// Generates the identity matrix.
/// </summary>
/// <param name="m">Number of rows.</param>
/// <param name="n">Number of columns.</param>
/// <returns>An m-by-n matrix with ones on the diagonal and zeros elsewhere.</returns>
public static
ComplexMatrix
Identity(
int m,
int n
)
{
Complex[][] data = new Complex[m][];
for(int i = 0; i < m; i++)
{
Complex[] col = new Complex[n];
if(i < n)
{
col[i] = Complex.One;
}
data[i] = col;
}
return new ComplexMatrix(data);
}
/// <summary>
/// Creates a new diagonal m-by-n matrix based on the diagonal vector.
/// </summary>
/// <param name="diagonalVector">The values of the matrix diagonal.</param>
/// <param name="m">Number of rows.</param>
/// <param name="n">Number of columns.</param>
/// <returns>
/// An m-by-n matrix with the values from the diagonal vector on the diagonal and zeros elsewhere.
/// </returns>
public static
ComplexMatrix
Diagonal(
IVector<Complex> diagonalVector,
int m,
int n
)
{
Complex[][] data = new Complex[m][];
for(int i = 0; i < m; i++)
{
Complex[] col = new Complex[n];
if((i < n) && (i < diagonalVector.Length))
{
col[i] = diagonalVector[i];
}
data[i] = col;
}
return new ComplexMatrix(data);
}
/// <summary>
/// Creates a new square diagonal matrix based on the diagonal vector.
/// </summary>
/// <param name="diagonalVector">The values of the matrix diagonal.</param>
/// <returns>
/// An m-by-n matrix with the values from the diagonal vector on the diagonal and zeros elsewhere.
/// </returns>
public static
ComplexMatrix
Diagonal(
IVector<Complex> diagonalVector
)
{
return Diagonal(diagonalVector, diagonalVector.Length, diagonalVector.Length);
}
/// <summary>
/// Generates an m-by-m matrix filled with 1.
/// </summary>
/// <param name="m">Number of rows = Number of columns</param>
public static
ComplexMatrix
Ones(
int m
)
{
return new ComplexMatrix(m, m, Complex.One);
}
/// <summary>
/// Generates an m-by-m matrix filled with 0.
/// </summary>
/// <param name="m">Number of rows = Number of columns</param>
public static
ComplexMatrix
Zeros(
int m
)
{
return new ComplexMatrix(m, m);
}
/// <summary>
/// Generates matrix with random real and imaginary elements.
/// </summary>
/// <param name="m">Number of rows.</param>
/// <param name="n">Number of columns.</param>
/// <param name="randomDistribution">Continuous Random Distribution or Source</param>
/// <returns>An m-by-n matrix with real and imaginary elements distributed according to the provided distribution.</returns>
public static
ComplexMatrix
Random(
int m,
int n,
IContinuousGenerator randomDistribution
)
{
Complex[][] data = new Complex[m][];
for(int i = 0; i < m; i++)
{
Complex[] col = new Complex[n];
for(int j = 0; j < n; j++)
{
col[j] = Complex.Random(
randomDistribution,
randomDistribution
);
}
data[i] = col;
}
return new ComplexMatrix(data);
}
/// <summary>
/// Generates matrix with random real and zero imaginary elements.
/// </summary>
/// <param name="m">Number of rows.</param>
/// <param name="n">Number of columns.</param>
/// <param name="realRandomDistribution">Continuous Random Distribution or Source for the real part.</param>
/// <returns>An m-by-n matrix with real parts distributed according to the provided distribution.</returns>
public static
ComplexMatrix
RandomReal(
int m,
int n,
IContinuousGenerator realRandomDistribution
)
{
Complex[][] data = new Complex[m][];
for(int i = 0; i < m; i++)
{
Complex[] col = new Complex[n];
for(int j = 0; j < n; j++)
{
col[j] = new Complex(
realRandomDistribution.NextDouble(),
0d
);
}
data[i] = col;
}
return new ComplexMatrix(data);
}
/// <summary>
/// Generates matrix with random modulus and argument elements.
/// </summary>
/// <param name="m">Number of rows.</param>
/// <param name="n">Number of columns.</param>
/// <param name="modulusRandomDistribution">Continuous Random Distribution or Source for the modulus part (must be non-negative!).</param>
/// <param name="argumentRandomDistribution">Continuous Random Distribution or Source for the argument part.</param>
/// <returns>An m-by-n matrix with imaginary parts distributed according to the provided distribution.</returns>
public static
ComplexMatrix
RandomPolar(
int m,
int n,
IContinuousGenerator modulusRandomDistribution,
IContinuousGenerator argumentRandomDistribution
)
{
Complex[][] data = new Complex[m][];
for(int i = 0; i < m; i++)
{
Complex[] col = new Complex[n];
for(int j = 0; j < n; j++)
{
col[j] = Complex.RandomPolar(
modulusRandomDistribution,
argumentRandomDistribution
);
}
data[i] = col;
}
return new ComplexMatrix(data);
}
/// <summary>
/// Generates a matrix of complex numbers on the unit circle with random argument.
/// </summary>
/// <param name="m">Number of rows.</param>
/// <param name="n">Number of columns.</param>
/// <param name="argumentRandomDistribution">Continuous random distribution or source for the complex number arguments.</param>
/// <returns>An m-by-n matrix with complex arguments distributed according to the provided distribution.</returns>
public static
ComplexMatrix
RandomUnitCircle(
int m,
int n,
IContinuousGenerator argumentRandomDistribution
)
{
Complex[][] data = new Complex[m][];
for(int i = 0; i < m; i++)
{
Complex[] col = new Complex[n];
for(int j = 0; j < n; j++)
{
col[j] = Complex.RandomUnitCircle(
argumentRandomDistribution
);
}
data[i] = col;
}
return new ComplexMatrix(data);
}
#endregion // Constructors
#region Matrix -> Data: Back Conversions
/// <summary>
/// Copies the internal data structure to a 2-dimensional array.
/// </summary>
public
Complex[,]
CopyToArray()
{
Complex[,] newData = new Complex[_rowCount, _columnCount];
for(int i = 0; i < _rowCount; i++)
{
for(int j = 0; j < _columnCount; j++)
{
newData[i, j] = _data[i][j];
}
}
return newData;
}
/// <summary>
/// Copies the internal data structure to a jagged rectangular array.
/// </summary>
/// <returns></returns>
public
Complex[][]
CopyToJaggedArray()
{
return CloneMatrixData(_data);
}
/// <summary>
/// Returns the internal data structure array.
/// </summary>
public
Complex[][]
GetArray()
{
return _data;
}
/// <summary>Implicit convertion to a <c>Complex[][]</c> array.</summary>
public static implicit
operator Complex[][](
ComplexMatrix m
)
{
return m._data;
}
/// <summary>
/// Explicit convertion to a <c>Complex[]</c> array of a single column matrix.
/// </summary>
/// <param name="m">Exactly one column expected.</param>
public static explicit
operator Complex[](
ComplexMatrix m
)
{
if(m.ColumnCount != 1)
{
throw new InvalidOperationException(Properties.LocalStrings.ArgumentMatrixSingleColumn);
}
Complex[] array = new Complex[m.RowCount];
for(int i = 0; i < m.RowCount; i++)
{
array[i] = m[i, 0];
}
return array;
}
/// <summary>
/// Excplicit conversion to a <c>Complex</c> scalar of a single column and row (1-by-1) matrix.
/// </summary>
/// <param name="m">1-by-1 Matrix</param>
public static explicit
operator Complex(
ComplexMatrix m
)
{
if(m.ColumnCount != 1 || m.RowCount != 1)
{
throw new InvalidOperationException(Properties.LocalStrings.ArgumentMatrixSingleColumnRow);
}
return m[0, 0];
}
#endregion
#region Internal Data Stucture
/// <summary>
/// Create the internal matrix data structure for a matrix of the given size.
/// Initializing matrices directly on the internal structure may be faster
/// than accessing the cells through the matrix class.
/// </summary>
/// <param name="m">Number of rows.</param>
/// <param name="n">Number of columns.</param>
public static
Complex[][]
CreateMatrixData(
int m,
int n
)
{
Complex[][] data = new Complex[m][];
for(int i = 0; i < m; i++)
{
data[i] = new Complex[n];
}
return data;
}
/// <summary>
/// Creates a copy of a given internal matrix data structure.
/// </summary>
public static
Complex[][]
CloneMatrixData(
Complex[][] data
)
{
int rows, columns;
GetRowColumnCount(data, out rows, out columns);
Complex[][] newData = new Complex[rows][];
for(int i = 0; i < rows; i++)
{
Complex[] col = new Complex[columns];
for(int j = 0; j < columns; j++)
{
col[j] = data[i][j];
}
newData[i] = col;
}
return newData;
}
/// <summary>
/// Tries to find out the row column count of a given internal matrix data structure.
/// </summary>
public static
void
GetRowColumnCount(
Complex[][] data,
out int rows,
out int columns
)
{
rows = data.Length;
columns = (rows == 0) ? 0 : data[0].Length;
}
#endregion
#region Sub-matrices operation
/// <summary>
/// Copies a specified column of this matrix to a new vector.
/// </summary>
public
ComplexVector
GetColumnVector(
int columnIndex
)
{
if(columnIndex < 0 || columnIndex >= _columnCount)
{
throw new ArgumentOutOfRangeException("columnIndex");
}
Complex[] newData = new Complex[_rowCount];
for(int i = 0; i < _rowCount; i++)
{
newData[i] = _data[i][columnIndex];
}
return new ComplexVector(newData);
}
/// <summary>
/// Copies a specified row of this matrix to a new vector.
/// </summary>
public
ComplexVector
GetRowVector(
int rowIndex
)
{
if(rowIndex < 0 || rowIndex >= _rowCount)
{
throw new ArgumentOutOfRangeException("rowIndexs");
}
Complex[] newData = new Complex[_columnCount];
_data[rowIndex].CopyTo(newData, 0);
return new ComplexVector(newData);
}
/// <summary>
/// Copies a column vector to a specified column of this matrix.
/// </summary>
public
void
SetColumnVector(
IVector<Complex> columnVector,
int columnIndex
)
{
if(null == columnVector)
{
throw new ArgumentNullException("columnVector");
}
if(columnIndex < 0 || columnIndex >= _columnCount)
{
throw new ArgumentOutOfRangeException("columnIndex");
}
if(columnVector.Length != _rowCount)
{
throw new ArgumentOutOfRangeException("columnVector");
}
for(int i = 0; i < _rowCount; i++)
{
_data[i][columnIndex] = columnVector[i];
}
ResetOnDemandComputations();
}
/// <summary>
/// Copies a row vector to a specified row of this matrix.
/// </summary>
public
void
SetRowVector(
IVector<Complex> rowVector,
int rowIndex
)
{
if(null == rowVector)
{
throw new ArgumentNullException("rowVector");
}
if(rowIndex < 0 || rowIndex >= _rowCount)
{
throw new ArgumentOutOfRangeException("rowIndexs");
}
if(rowVector.Length != _columnCount)
{
throw new ArgumentOutOfRangeException("rowVector");
}
_data[rowIndex] = rowVector.CopyToArray();
ResetOnDemandComputations();
}
/// <summary>
/// Gets a submatrix.
/// </summary>
/// <param name="i0">First row index.</param>
/// <param name="i1">Last row index (inclusive).</param>
/// <param name="j0">First column index.</param>
/// <param name="j1">Last column index (inclusive).</param>
/// <returns>A(i0:i1,j0:j1)</returns>
/// <exception cref="System.IndexOutOfRangeException">Submatrix indices</exception>
public
ComplexMatrix
GetMatrix(
int i0,
int i1,
int j0,
int j1
)
{
Complex[][] newData = CreateMatrixData(i1 - i0 + 1, j1 - j0 + 1);
try
{
for(int i = i0; i <= i1; i++)
{
for(int j = j0; j <= j1; j++)
{
newData[i - i0][j - j0] = _data[i][j];
}
}
}
catch(IndexOutOfRangeException e)
{
throw new IndexOutOfRangeException(Properties.LocalStrings.ArgumentMatrixIndexOutOfRange, e);
}
return new ComplexMatrix(newData);
}
/// <summary>
/// Gets a submatrix.
/// </summary>
/// <param name="r">Array of row indices.</param>
/// <param name="c">Array of column indices.</param>
/// <returns>A(r(:),c(:))</returns>
/// <exception cref="System.IndexOutOfRangeException">Submatrix indices.</exception>
public
ComplexMatrix
GetMatrix(
int[] r,
int[] c
)
{
Complex[][] newData = CreateMatrixData(r.Length, c.Length);
try
{
for(int i = 0; i < r.Length; i++)
{
for(int j = 0; j < c.Length; j++)
{
newData[i][j] = _data[r[i]][c[j]];
}
}
}
catch(IndexOutOfRangeException e)
{
throw new IndexOutOfRangeException(Properties.LocalStrings.ArgumentMatrixIndexOutOfRange, e);
}
return new ComplexMatrix(newData);
}
/// <summary>
/// Get a submatrix.
/// </summary>
/// <param name="i0">First row index.</param>
/// <param name="i1">Last row index (inclusive).</param>
/// <param name="c">Array of column indices.</param>
/// <returns>A(i0:i1,c(:))</returns>
/// <exception cref="System.IndexOutOfRangeException">Submatrix indices.</exception>
public
ComplexMatrix
GetMatrix(
int i0,
int i1,
int[] c
)
{
Complex[][] newData = CreateMatrixData(i1 - i0 + 1, c.Length);
try
{
for(int i = i0; i <= i1; i++)
{
for(int j = 0; j < c.Length; j++)
{
newData[i - i0][j] = _data[i][c[j]];
}
}
}
catch(IndexOutOfRangeException e)
{
throw new IndexOutOfRangeException(Properties.LocalStrings.ArgumentMatrixIndexOutOfRange, e);
}
return new ComplexMatrix(newData);
}
/// <summary>
/// Get a submatrix.
/// </summary>
/// <param name="r">Array of row indices.</param>
/// <param name="j0">First column index.</param>
/// <param name="j1">Last column index (inclusive).</param>
/// <returns>A(r(:),j0:j1)</returns>
/// <exception cref="System.IndexOutOfRangeException">Submatrix indices.</exception>
public
ComplexMatrix
GetMatrix(
int[] r,
int j0,
int j1
)
{
Complex[][] newData = CreateMatrixData(r.Length, j1 - j0 + 1);
try