File tree Expand file tree Collapse file tree 4 files changed +69
-10
lines changed Expand file tree Collapse file tree 4 files changed +69
-10
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Linq ;
4
+ using System . Text ;
5
+ using System . Threading . Tasks ;
6
+
7
+ namespace MathExtended . Exceptions
8
+ {
9
+ /// <summary>
10
+ /// Возникает при попытке операции
11
+ /// над вектор строками/столбцами разных размеров
12
+ /// </summary>
13
+ public class VectorsDifferentSizeException : Exception
14
+ {
15
+ private string _message = "Vector row/column of different sizes" ;
16
+
17
+ /// <summary>
18
+ /// Сообщение исключения
19
+ /// </summary>
20
+ public override string Message => _message ;
21
+ }
22
+ }
Original file line number Diff line number Diff line change 190
190
<Reference Include =" System.Xml" />
191
191
</ItemGroup >
192
192
<ItemGroup >
193
+ <Compile Include =" Exceptions\VectorsDifferentSizeException.cs" />
193
194
<Compile Include =" Matrices\Structures\CellsCollections\BaseCellsCollection.cs" />
194
195
<Compile Include =" Matrices\BaseMatrix.cs" />
195
196
<Compile Include =" Matrices\Structures\CellsCollections\BaseReadOnlyCellsCollection.cs" />
Original file line number Diff line number Diff line change @@ -118,11 +118,40 @@ public static implicit operator Column<T>(T[] array)
118
118
}
119
119
}
120
120
121
+ /// <summary>
122
+ /// Умножает столбец на строку
123
+ /// </summary>
124
+ /// <param name="column">Столбец</param>
125
+ /// <param name="row">Строка</param>
126
+ /// <returns><see cref="Matrix{T}"/> результат умножения</returns>
127
+ public static Matrix < T > operator * ( Column < T > column , Row < T > row )
128
+ {
129
+ if ( column . Size != row . Size )
130
+ {
131
+ throw new VectorsDifferentSizeException ( ) ;
132
+ }
133
+ else
134
+ {
135
+ Matrix < T > matrix = new Matrix < T > ( row . Size , column . Size ) ;
136
+
137
+ for ( int i = 0 ; i < row . Size ; i ++ )
138
+ {
139
+ for ( int j = 0 ; j < column . Size ; j ++ )
140
+ {
141
+ matrix [ i , j ] = ( T ) Operator . Multiply ( row [ j ] , column [ i ] ) ;
142
+ }
143
+ }
144
+
145
+ return matrix ;
146
+ }
147
+ }
148
+
149
+
121
150
/// <summary>
122
151
/// Явно приводит <see cref="ReadOnlyColumn{T}"/> к <see cref="Column{T}"/>
123
152
/// Делая пригодным для записи
124
153
/// </summary>
125
- /// <param name="readOnlyColumn">Привидимый столбец</param>
154
+ /// <param name="readOnlyColumn">Приводимый столбец</param>
126
155
public static explicit operator Column < T > ( ReadOnlyColumn < T > readOnlyColumn )
127
156
{
128
157
Column < T > column = new Column < T > ( readOnlyColumn . Size ) ;
Original file line number Diff line number Diff line change @@ -111,26 +111,33 @@ public static implicit operator Row<T>(T[] array)
111
111
}
112
112
113
113
/// <summary>
114
- /// Умножает строку на столбец
114
+ /// Умножает строку на стотбец, получая число
115
115
/// </summary>
116
116
/// <param name="row">Строка</param>
117
117
/// <param name="column">Столбец</param>
118
- /// <returns><see cref="Matrix{T} "/> результат умножения </returns>
119
- public static Matrix < T > operator * ( Row < T > row , Column < T > column )
118
+ /// <returns><typeparamref name="T "/> число </returns>
119
+ public static T operator * ( Row < T > row , Column < T > column )
120
120
{
121
- Matrix < T > matrix = new Matrix < T > ( row . Size , column . Size ) ;
122
-
123
- for ( int i = 0 ; i < row . Size ; i ++ )
121
+ if ( row . Size != column . Size )
122
+ {
123
+ throw new VectorsDifferentSizeException ( ) ;
124
+ }
125
+ else
124
126
{
125
- for ( int j = 0 ; j < column . Size ; j ++ )
127
+ dynamic num = 0 ;
128
+
129
+ for ( int i = 0 ; i < row . Size ; i ++ )
126
130
{
127
- matrix [ i , j ] = ( T ) Operator . Multiply ( row [ i ] , column [ j ] ) ;
131
+ num + = ( T ) Operator . Multiply ( row [ i ] , column [ i ] ) ;
128
132
}
133
+
134
+ return num ;
129
135
}
130
136
131
- return matrix ;
137
+
132
138
}
133
139
140
+
134
141
/// <summary>
135
142
/// Приводит <see cref="ReadOnlyRow{T}"/> к <see cref="Row{T}"/>
136
143
/// делая возможной запись
You can’t perform that action at this time.
0 commit comments