【算法】 C/C++实现直接法解线性方程组

这里就不解释线性代数的数学解法原理什么的了,可以参考下我看过的这篇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 +

  • 7
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值