我有一个矩阵
,我应该使用高斯-赛德尔(Gauss-Seidel)和耦合梯度方法编写代码,并采用矩阵结构。
Ax = e
,其中A
是矩阵,e
是值为1的向量
我不知道如何使用耦合梯度方法编写代码,我的高斯-塞德尔算法没有主要部分,我将所有这些都加进去
//part of gauss-seidel method
const int N = 128; //size of array
const int no_of_iter = 128; //iterations
int main() {
double result[N]; //array for result
double result_pom[N]; //temporary result array
double sum = 0.0;
int x, y;
for (int i = 0; i < no_of_iter; i++) {
for (y = 0; y < N; y++) {
result_pom[y] = result[y]; //set values of result to result_pom
}
for (x = 0; x < N; x++) {
sum = 0.0;
//for functions where I add (x,y) el
result[x] = 0.25 * (1 - sum); //because 4 is dominant el of matrix and
//1 is value of vector e
}
}
}