-
Notifications
You must be signed in to change notification settings - Fork 0
/
Matrix.cpp
35 lines (32 loc) · 1.37 KB
/
Matrix.cpp
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
//---------------------------------------------------------------------------
#pragma hdrstop
#include "matrix.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
//---------------------------------------------------------------------------
// óìíîæåíèå ìàòðèöû íà ÷èñëî
Matrix<Float> operator*(Float op1, Matrix<Float> op2){
Matrix<Float> temp(op2.rows, op2.cols);
for(unsigned int i=0; i<op2.rows; i++)
for(unsigned int j=0; j<op2.cols; j++)
temp.A[i][j] = op1 * op2.A[i][j];
return temp;
}
//---------------------------------------------------------------------------
// ïåðåìíîæåíèå ñ ñîçâðàò ðåçóëüòàòà â ìàòðèöó N x 1
void Multiply_Matrix(Matrix<Float> *op1, Float op2[], Float *result[]){
for(unsigned int i=0; i<op1->rows; i++){
*result[i] = 0;
for(unsigned int k=0; k<op1->cols; k++)
(*result[i]) += op1->A[i][k] * op2[k];
}
}
//---------------------------------------------------------------------------
// êîïèðîâàíèå îäíîé ìàòðèöû â äðóãóþ
bool Copy_Matrix(Matrix<char> *from,Matrix<Float> *to){
if(from->Rows!=to->Rows || from->Cols!=to->Cols) {err( 0, "Ïðèñâàèâàíèå ìàòðèöû: ìàòðèöû èìåþò ðàçíûé ðàçìåð" ); return false;}
for(unsigned int i=0; i<from->Rows; i++)
for(unsigned int j=0; j<from->Cols; j++)
(*to)[i][j] = (Float)(*from)[i][j];
return true;
}