-
Notifications
You must be signed in to change notification settings - Fork 5
/
matrix.cpp
55 lines (41 loc) · 1.25 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// Created by user on 08.10.2018.
//
#include "matrix.h"
#include <cmath>
#include <iostream>
double *vectorAdd(double *first, double *second, unsigned long vectorSize) {
double *result = new double[vectorSize];
for (int idx = 0; idx < vectorSize; idx++) {
result[idx] = first[idx] + second[idx];
}
return result;
}
double *vectorMultiply(double *vector, unsigned long vectorSize, double constantValue) {
double *result = new double[vectorSize];
for (int idx = 0; idx < vectorSize; idx++) {
result[idx] = vector[idx] * constantValue;
}
return result;
}
double *vectorMultiplyComponentWise(double *first, double *second, unsigned long vectorSize) {
double *result = new double[vectorSize];
for (int idx = 0; idx < vectorSize; idx++) {
result[idx] = first[idx] * second[idx];
}
return result;
}
double vectorSum(double *vector, unsigned long vectorSize) {
double result = 0.0;
for (int idx = 0; idx < vectorSize; idx++) {
result += vector[idx];
}
return result;
}
double norm(double *vector, unsigned long vectorSize) {
double result = 0.0;
for (int idx = 0; idx < vectorSize; ++idx) {
result += pow(vector[idx], 2);
}
return sqrt(result);
}