迭代法

雅可比迭代法和高斯赛德尔迭代法

萝らか妹 提交于 2019-11-28 02:13:15
刚学 Jacobi算法和Gauss_Siedel算法不久,觉的对以后学习会有帮助,所以记下来,希望感兴趣的朋友共勉! 雅克比迭代 #include < iostream > #include " math.h " using namespace std; #define n 3 double a[n][n] = {{ 5 , 2 , 1 },{ - 1 , 4 , 2 },{ 2 , - 3 , 10 }}, x[n] = { - 3 , 2 , 1 }, b[n] = { - 12 , 20 , 3 }, c[n]; int i = 0 ,j,k = 0 ,counter = 15 ; int main() { int k = 0 ,i = 0 ; double num1,E; float y[n]; do { E = 0 ; for (j = 0 ;j < n;j ++ ) { c[j] = x[j]; } num1 = 0 ; for (j = 0 ;j < n;j ++ ) { if (j != i) num1 = num1 + a[i][j] * x[j]; } for (j = 0 ;j < n;j ++ ) { c[j] = x[j]; } y[i] = (b[i] - num1) / a[i][i]; if (i < n) { i ++ ; } else { for