24小时热门版块排行榜    

CyRhmU.jpeg
查看: 308  |  回复: 2
当前主题已经存档。

carveny

金虫 (小有名气)

[交流] [求助]求解三对角线方程组的C语言的源码

求解三对角线方程组的C语言的源码

很急,谢谢。

[ Last edited by csfn on 2008-12-29 at 20:12 ]
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

carveny

金虫 (小有名气)

555,没有人吗
2楼2008-02-29 21:48:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

liverangel

木虫 (著名写手)

★ ★ ★ ★ ★ ★ ★ ★ ★ ★
carveny(金币+10,VIP+0):谢谢,太感谢了!
#include "iostream.h"
#include "math.h"

void tridag(double a[],double b[], double c[],double r[], double u[], int n)
{
    const int nmax = 100;
    double gam[100];
    if (b[1] == 0.0)
        {
                return;
        }
    double bet = b[1];
    u[1] = r[1] / bet;
    for (int j = 2; j<=n; j++)
        {
        gam[j] = c[j - 1] / bet;
        bet = b[j] - a[j] * gam[j];
        if (bet == 0.0)
                {
                        return;
                }
        u[j] = (r[j] - a[j] * u[j - 1]) / bet;
    }
    for (j = n - 1; j>=1; j--)
        {
        u[j] = u[j] - gam[j + 1] * u[j + 1];
    }
}

void main()
{
    //program d1r3
    //driver program for routine tridag
    int i,j,l,n = 3;
    double a[4], b[4], c[4], r[4], u[4], a1[4][4], x[4];
    //输入已知的方程组的系数矩阵
    a1[1][1] = 1; a1[1][2] = 2; a1[1][3] = 0;
    a1[2][1] = 2; a1[2][2] = 2; a1[2][3] = 3;
    a1[3][1] = 0; a1[3][2] = 3; a1[3][3] = 3;
    //输入已知的方程组的右端向量
    r[1] = 1;
    r[2] = 2;
    r[3] = 3;
    cout<     cout<<"已知的方程组的右端向量"<         cout.width(10);
    cout<         cout.width(10);
    cout<         cout.width(10);
    cout<     for (i = 2; i<=n; i++)
        {
        a = a1[i - 1];
    }
    for (i = 1; i<=n - 1; i++)
        {
        c = a1[i + 1];
        }
    for (i = 1; i<=n; i++)
        {
        b = a1;
    }
    tridag(a, b, c, r, u, n);
    cout<     cout<<"计算出的方程组的解"<         cout.width(10);
    cout<         cout.width(10);
    cout<         cout.width(10);
    cout<     //将计算出的解乘以系数矩阵,以验证计算结果正确
    for (l = 1; l<=n; l++)
        {
        x[l] = 0.0;
        for (j = 1; j<=n; j++)
                {
            x[l] = x[l] + a1[l][j] * u[j];
        }
    }
    cout<     cout<<"计算出的解乘以系数矩阵的结果"<         cout.width(10);
    cout<         cout.width(10);
    cout<         cout.width(10);
    cout<        
}
在明天到来之前不要放弃,想想你今天能干些什么?
3楼2008-03-01 01:52:37
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 carveny 的主题更新
普通表情 高级回复(可上传附件)
信息提示
请填处理意见