This repository has been archived by the owner on Dec 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.cpp
72 lines (61 loc) · 1.48 KB
/
math.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "common.h"
void multVectByA(double *in, double *out) // multiplication of a given vector by the matrix A
{
int i, j;
for (i = 0; i < N; i++)
{
out[i] = diOrig[i] * in[i];
for (j = ig[i]; j < ig[i + 1]; j++)
{
out[i] += ggl[j] * in[jg[j]];
out[jg[j]] += ggu[j] * in[i];
}
}
}
double multVectByVect(double *vect1, double *vect2) // scalar multiplication of two vectors
{
int i;
double result = 0;
for (i = 0; i < N; i++)
result += vect1[i] * vect2[i];
return result;
}
double sum(int i, int j) // sum of L and U products (for factorization)
{
int k, l, flag;
double result = 0.0;
if (i > j)
{
for (k = ig[j]; k < ig[j + 1]; k++)
{
flag = 0;
for (l = ig[i]; l < ig[i + 1] && flag == 0; l++)
{
if (jg[l] == jg[k])
{
result += U[k] * L[l];
flag = 1;
}
}
}
}
else if (i < j)
{
for (l = ig[i]; l < ig[i + 1]; l++)
{
flag = 0;
for (k = ig[j]; k < ig[j + 1] && flag == 0; k++)
{
if (jg[l] == jg[k])
{
result += U[k] * L[l];
flag = 1;
}
}
}
}
else
for (k = ig[i]; k < ig[i + 1]; k++)
result += U[k] * L[k];
return result;
}