-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapost_statical.h
69 lines (49 loc) · 1.74 KB
/
apost_statical.h
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
# Copyright (c) 2016 The Caroline authors. All rights reserved.
# Use of this source file is governed by a MIT license that can be found in the
# LICENSE file.
# Author: Glazachev Vladimir <[email protected]>
#ifndef APOST_STATICAL_H
#define APOST_STATICAL_H
#include "interval.h"
#include "matrix.h"
namespace interval {
// Computes the final error.
Value ComputeError(const Matrix<ArbInterval>& A,
const Matrix<ArbInterval>& dA) {
size_t n = A.nrow();
size_t m = A.ncol();
ArbInterval result = 0;
for (size_t i = 0; i < n; ++i) {
for (size_t j = 0; j < m; ++j) {
ArbInterval dval = dA.at(i, j);
dval.abs();
ArbInterval err(A.at(i, j).error());
result += dval * err;
}
}
Value error = result.val() + result.error();
return error;
}
void GaussInverse(Matrix<ArbInterval> A, Matrix<ArbInterval>& dA) {
size_t n = A.nrow();
size_t m = A.ncol();
for (int i = n - 2; i >= 0; --i) {
for (size_t j = n - 1; j >= i + 1; --j) {
ArbInterval dot = 0;
for (size_t k = i + 1; k < m; ++k)
dot += dA.at(j, k) * A.at(i, k);
dA.at(j, i) -= dot;
for (size_t k = i + 1; k < m; ++k) {
dA.at(i, k) -= dA.at(j, k) * A.at(j, i);
}
for (size_t k = i + 1; k < m; ++k) {
A.at(j, k) += A.at(j, i) * A.at(i, k);
}
dA.at(i, i) -= dA.at(j, i) * A.at(j, i) / A.at(i, i);
dA.at(j, i) /= A.at(i, i);
A.at(j, i) *= A.at(i, i);
}
}
}
} // namespace interval
#endif // APOST_STATICAL