Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c语言中带后代码的高斯消去法_C_Linear Algebra - Fatal编程技术网

c语言中带后代码的高斯消去法

c语言中带后代码的高斯消去法,c,linear-algebra,C,Linear Algebra,有人能提供一些帮助吗。我完全无法做到这一点。我试图做一些编码,但根本没有工作。无论如何,我已经包括了代码。无论如何,它是不完整和错误的 #include<stdio.h> #include<math.h> main() { int rows, columns, iter, i,j,k; printf("enter the number of rows and columns:"); scanf("%d, %d",&rows, &columns)

有人能提供一些帮助吗。我完全无法做到这一点。我试图做一些编码,但根本没有工作。无论如何,我已经包括了代码。无论如何,它是不完整和错误的

#include<stdio.h>
#include<math.h>
main()
{
  int rows, columns, iter, i,j,k;
  printf("enter the number of rows and columns:");
  scanf("%d, %d",&rows, &columns);
  double a[rows][columns], b[rows][1],x[rows][1];
  printf("enter the elements of A matrix:");
   for(i=0;i<rows;i++)
  {
    for(j=0;j<columns;j++)
    scanf("%lf",&a[i][j]);
  }
   printf("\n enter the elements of B matrix:");
  for(i=0,i<rows;i++)
  scanf("%lf",&b[i][0]);

  printf("\n");
  for (iter=1; iter<rows; iter++)
  {
    for(i=iter;i<rows;i++)

      b[i][0] = b[i][0]- a[k][iter-1]*(b[i-1][0]/a[iter-1][iter-1]);


      for(j=iter-1,k=iter;j<columns;j++)

        a[i][j] = a[i][j]-a[i-1][j]*(a[k][iter-1]/a[iter-1][iter-1]);

    }


  printf("the elements of the matrix A are now:");

  for(i=0;i<rows; i++)
  { 
    for(j=0; j<columns; j++)  
      printf("%lf",a[i][j]);
  }
  return(0);
}
#包括
#包括
main()
{
int行、列、iter、i、j、k;
printf(“输入行数和列数:”);
scanf(“%d,%d”,行和列);
双a[行][列]、b[行][1]、x[行][1];
printf(“输入矩阵的元素:”);

对于(i=0;i没有人使用这样的代码,它有严重的数值稳定性问题。使用LU decomp是一种很好的方法,有很多库可供使用。如果必须的话,可以使用数值公式

int rows, columns, iter, i,j,k;
printf("enter the number of rows and columns:");
scanf("%d, %d",&rows, &columns);
double a[i][j], b[i],x[i];

使用i和j来指定数组大小是一个非常可疑的活动,因为i和j尚未初始化。

我注意到的第一件事是这个循环

for(i=0;i<=columns-1;i++) 
{ 
  for(j=0;j<=columns-1;j++) 
  {  
    scanf("%lf",&a[i][j]); 
  } 
}

for(i=0;i在任何人能够提供帮助之前,您需要修复您的代码。使用“代码块”按钮帮助设置格式,以使其可读。我已开始使代码看起来合理的过程,这将向您展示如何完成该过程。然而,目前看来,似乎有太多的“}“字符。我尽了最大努力修改代码。