-
Notifications
You must be signed in to change notification settings - Fork 3
/
geom_r4.cpp
67 lines (54 loc) · 1.36 KB
/
geom_r4.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
// geom_r4.cpp
//
#include "geom_r4.hpp" /* picks up base and r3 as well */
#include <iostream>
#include <cmath>
using namespace R4;
using namespace std;
// IN THIS FILE:
// Class Implementations for:
//
// o Classes in the R4:: namespace
//
Column Matrix::SolveAXB(Column B) const
{
int numRows = 4;
AugmentedRow row[4];
row[0] = AugmentedRow(GetRow(0),B.x(0));
row[1] = AugmentedRow(GetRow(1),B.x(1));
row[2] = AugmentedRow(GetRow(2),B.x(2));
row[3] = AugmentedRow(GetRow(3),B.x(3));
//Upper Triangular
for(int i = 0; i < numRows; i++)
{
//Swap Rows
AugmentedRow largest = row[i];
int largestNumber = i;
for(int k = i; k < numRows; k++){
if(abs(row[k].x(i)) > abs(row[i].x(i))){
largest = row[k];
largestNumber = k;
}
}
if(largestNumber != i){
row[largestNumber] = row[i];
row[i] = largest;
}
if(row[i].x(i)!= 0){
row[i] *= 1/row[i].x(i);
for(int j = 1; j < numRows - i; j++)
{
row[i+j] -= (row[i].ScaledBy(row[i+j].x(i)));
}
}
}
//Reduced Echelon
for(int j = numRows-1; j >= 1; j--)
{
for(int i = 0; i <= j-1; i++)
{
row[i] -= (row[j].ScaledBy(row[i].x(j)));
}
}
return Column(row[0].x(4), row[1].x(4), row[2].x(4), row[3].x(4));
}