-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathGaussElimination.cpp
64 lines (60 loc) · 955 Bytes
/
GaussElimination.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
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define LD long double
#define gc getchar_unlocked
#define pc putchar_unlocked
#define MOD 1000000007
#define MAXN 100005
#define bitcount _builtin_popcount
#define INF 2000000000
#define EPS 1e-9
template<typename T>T absll(T X)
{
if(X<0)
return -1*X;
else
return X;
}
int T,N;
double A[5][5],B[4],coeff[4];
double ct,cv;
void gauss_eliminate(double A[5][5],double *x,int n)
{
for(int e=0;e<4;e++)
{
for(int i=e;i<4;i++)
{
if(absll(A[i][e])>EPS)
{
if(i!=e)
{
for(int j=0;j<=4;j++)
{
swap(A[i][j],A[e][j]);
}
}
break;
}
}
for(int i=0;i<4;i++)
{
if(i==e)
{
continue;
}
double co=-A[i][e]/A[e][e];
for(int j=0;j<=4;j++)
{
A[i][j]+=A[e][j]*co;
}
}
}
for(int i=0;i<4;i++)
{
coeff[i]=A[i][4]/A[i][i];
}
}