这里就不解释线性代数的数学解法原理什么的了,可以参考下我看过的这篇CSDN文章:
http://blog.csdn.net/kang___xi/article/details/51475268
这篇文章的代码部分好像有点问题,我在其基础之上做了一些修改,并且可以把最终结果算出输出在控制台上。
【1】代码
/*======================================================
# Author: Sugary
# Filetype: C/C++ source code
# Environment: Window 8.1
# Tool: CodeBlocks
# Date: 2017/3/7
# Descprition: Solve the AX=b by the Guass Elimination!
========================================================*/
#include<stdio.h>
#include<math.h>
#define ROW 100
#define COL 100
void get_coefficient(double[][COL], int, int);
void get_vector(double[], int);
void create_Ab(double[][COL], double[], int, int);
void show_matrix(double[][COL], int, int);
void guass_elimination(double *[ROW], int, int);
void exchange_row(double *[ROW], int, int, int);
void show_solution(double *[ROW], int, int);
void back_substitution(double *[ROW], int, int);
void back_substitution(double *[ROW], int, int, int);
int main()
{
double Receptacle[ROW][COL]; // store the matrix A
double Vector[ROW]; // store the vector b
double *Ab_pointer[ROW]; // store every row of augment matrix (A,b)
int row, col; // store the row/col of the matrix;
int i;
printf("Enter the coefficient matrix's size (less than %d * %d): ", ROW, COL - 1);
while (scanf("%d%d", &row, &col) == 2)
{
get_coefficient(Receptacle, row, col); // get the value of matrix A
get_vector(Vector, row); // get the value of vector b
create_Ab(Receptacle, Vector, row, col);// create the augment matrix (A,b)
printf("\nThe linear equations in the form of augmented matrix as follow:\n");
show_matrix(Receptacle, row, col +
/*======================================================
# Author: Sugary
# Filetype: C/C++ source code
# Environment: Window 8.1
# Tool: CodeBlocks
# Date: 2017/3/7
# Descprition: Solve the AX=b by the Guass Elimination!
========================================================*/
#include<stdio.h>
#include<math.h>
#define ROW 100
#define COL 100
void get_coefficient(double[][COL], int, int);
void get_vector(double[], int);
void create_Ab(double[][COL], double[], int, int);
void show_matrix(double[][COL], int, int);
void guass_elimination(double *[ROW], int, int);
void exchange_row(double *[ROW], int, int, int);
void show_solution(double *[ROW], int, int);
void back_substitution(double *[ROW], int, int);
void back_substitution(double *[ROW], int, int, int);
int main()
{
double Receptacle[ROW][COL]; // store the matrix A
double Vector[ROW]; // store the vector b
double *Ab_pointer[ROW]; // store every row of augment matrix (A,b)
int row, col; // store the row/col of the matrix;
int i;
printf("Enter the coefficient matrix's size (less than %d * %d): ", ROW, COL - 1);
while (scanf("%d%d", &row, &col) == 2)
{
get_coefficient(Receptacle, row, col); // get the value of matrix A
get_vector(Vector, row); // get the value of vector b
create_Ab(Receptacle, Vector, row, col);// create the augment matrix (A,b)
printf("\nThe linear equations in the form of augmented matrix as follow:\n");
show_matrix(Receptacle, row, col +