数值分析原理课程实验——(高斯)Gauss列主元消去法

高斯(Gauss)列主元消去法

方法概要

数值分析原理课程实验——(高斯)Gauss列主元消去法_第1张图片

待求问题

数值分析原理课程实验——(高斯)Gauss列主元消去法_第2张图片

数值分析原理课程实验——(高斯)Gauss列主元消去法_第3张图片
数值分析原理课程实验——(高斯)Gauss列主元消去法_第4张图片

程序流程

数值分析原理课程实验——(高斯)Gauss列主元消去法_第5张图片

程序代码

/*Matlab函数
function Result = Gauss(n, A, b)
    for k = 1:n-1
        max = abs(A(k, k));
        p = k;
        for j = k+1:n
            if(abs(A(j, k)) > max)
                max = abs(A(j, k));
                p = j;
            end
        end
        if(A(p, k) == 0)
            Result = 'Singular matrix!';
            return;
        end
        if(p ~= k)
           A([k p], :) = A([p k], :);
           b([k p], :) = b([p k], :);
        end
        for i = k+1:n
            Mik = A(i, k)/A(k, k);
            for j = k:n
                A(i, j) = A(i, j) - A(k, j)*Mik;
            end
            b(i) = b(i) - b(k)*Mik;
        end
    end
    if(A(n, n) == 0)
        Result = 'Singular matrix!';
        return;
    end
    Result = zeros(n, 1);
    Result(n, 1) = b(n)/A(n, n);
    for k = n-1:-1:1
        Sum = 0;
        for j = k+1:n
            Sum = Sum + A(k, j)*Result(j, 1);
        end
        Result(k, 1) = (b(k) - Sum)/A(k, k);
    end
end*/

/*C语言程序
#include 
#include 
#include 

#define N 10

int n;
double a[N][N], b[N], x[N];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= n; j++) scanf("%lf", &a[i][j]);
    for (int i = 1; i <= n; i++) scanf("%lf", &b[i]);
    for (int k = 1; k < n; k++) {
        int p = k;
        double maxabs = fabs(a[k][k]);
        for (int j = k + 1; j <= n; j++)
            if (fabs(a[j][k]) - maxabs > 0) {
                p = j;
                maxabs = fabs(a[j][k]);
            }
        if (a[p][k] == 0) {
            printf("Singular");
            return 0;
        }
        if (p != k) {
            double tmp;
            for (int j = 1; j <= n; j++) {
                tmp = a[p][j];
                a[p][j] = a[k][j];
                a[k][j] = tmp;
            }
            tmp = b[p];
            b[p] = b[k];
            b[k] = tmp;
        }
        for (int i = k + 1; i <= n; i++) {
            double m_ik = a[i][k] / a[k][k];
            for (int j = k + 1; j <= n; j++) a[i][j] -= a[k][j] * m_ik;
            b[i] -= b[k] * m_ik;
        }
    }
    if (a[n][n] == 0) {
        printf("Singular");
        return 0;
    }
    x[n] = b[n] / a[n][n];
    for (int k = n - 1; k >= 1; k--) {
        double sigma = 0.0;
        for (int j = k + 1; j <= n; j++) sigma += a[k][j] * x[j];
        x[k] = (b[k] - sigma) / a[k][k];
    }
    for (int i = 1; i <= n; i++) printf("%lf\t", x[i]);
    return 0;
}*/

运行结果

数值分析原理课程实验——(高斯)Gauss列主元消去法_第6张图片

数值分析原理课程实验——(高斯)Gauss列主元消去法_第7张图片

牛顿(Newton)迭代法,原文链接:

https://blog.csdn.net/KissMoon_/article/details/116277622

拉格朗日(Lagrange)插值,原文链接:

https://blog.csdn.net/KissMoon_/article/details/116278449

四阶龙格-库塔(Runge-Kutta)方法,原文链接:

https://blog.csdn.net/KissMoon_/article/details/116278567

Newton/Gauss/Lagrange/Runge-Kutta实验内容+方法指导+Matlab脚本+Matlab函数+Matlab运行报告+C程序+实验报告,一键下载:

https://download.csdn.net/download/KissMoon_/18244419

数值分析原理课程实验——(高斯)Gauss列主元消去法_第8张图片

你可能感兴趣的:(数值分析原理,算法,matlab,c语言,线性代数,抽象代数)