• 大小: 884KB
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2021-07-20
  • 语言: C/C++
  • 标签:

资源简介

《矩阵与数值分析》上机作业,采用Jacobi迭代法和Gauss-Seidel迭代法求解线性方程组的根。采用C语言编程,程序简单实用,有运行结果,修改方程组系数即可求解不同维数线性方程组的根。

资源截图

代码片段和文件信息

#include
#include
#include
#define JD 0.000001 //迭代终止精度要求
using namespace std;
void Jacobi(); //Jacobi迭代算法函数
void Gauss_Seidel(); //Gauss Seidel迭代算法函数
int abs_F(double a1double b1); //判断前后两步迭代偏差是否小于精度函数
int IF=1; //迭代终止标识符
void main()
{
cout< cout.precision(15);
Jacobi();
Gauss_Seidel();


}

void Jacobi()
{
double x1=0x2=0x3=0x4=0;
double a=0b=0c=0d=0;
int i=0j=0;
int counter=0;
do
{
a=(1+x2)/2;
b=(x1+x3)/2;
c=(x2+x4)/2;
d=x3/2;

IF=(abs_F(ax1) && abs_F(bx2) && abs_F(cx3) && abs_F(dx4)); //迭代终止条件IF=1;

x1=a;
x2=b;
x3=c;
x4=d;
counter++;
}
while(!IF);

cout<<“*************************************“< cout<<“采用Jacobi迭代法求解满足精度要求(<0.000001)“< cout<<“共需“< cout<<“X1*=“< cout<<“X2*=“< cout<<“X3*=“< cout<<“X4*=“<}

void Gauss_Seidel()
{
double x1=0x2=0x3=0x4=0;
double a=0b=0c=0d=0;
int i=0j=0;
int counter=0;
do
{
a=(1+x2)/2;
b=(a+x3)/2;
c=(b+x4)/2;
d=c/2;

IF=(abs_F(ax1) && abs_F(bx2) && abs_F(cx3) && abs_F(dx4)); //迭代终止条件IF=1;

x1=a;
x2=b;
x3=c;
x4=d;
counter++;

}
while(!IF);

cout<<“*************************************“< cout<<“采用Gauss Seidel迭代法求解“< cout<<“满足精度要求(<0.000001)“< cout<<“共需“< cout<<“X1*=“< cout<<“X2*=“< cout<<“X3*=“< cout<<“X4*=“<}

int abs_F(double a1double b1)
{
double abtemp;
a=a1;
b=b1;
if(a>b)
temp=a-b;
else
temp=b-a;
if(temp>JD)
IF=0;
else
IF=1;
return IF;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     536664  2010-12-30 18:03  Jacobi_Gauss_seidel\Debug\Jacobi_Gauss_seidel.exe

     文件     774460  2010-12-30 18:03  Jacobi_Gauss_seidel\Debug\Jacobi_Gauss_seidel.ilk

     文件     161245  2010-12-30 18:03  Jacobi_Gauss_seidel\Debug\Jacobi_Gauss_seidel.obj

     文件      43520  2010-12-12 12:33  Jacobi_Gauss_seidel\Debug\Jacobi_Gauss_seidel.opt

     文件    2009712  2010-12-30 18:03  Jacobi_Gauss_seidel\Debug\Jacobi_Gauss_seidel.pch

     文件    1106944  2010-12-30 18:03  Jacobi_Gauss_seidel\Debug\Jacobi_Gauss_seidel.pdb

     文件       5908  2010-12-12 12:26  Jacobi_Gauss_seidel\Debug\Jacobi_Gauss_seidel.res

     文件      91136  2010-12-30 18:03  Jacobi_Gauss_seidel\Debug\vc60.idb

     文件     126976  2010-12-30 18:03  Jacobi_Gauss_seidel\Debug\vc60.pdb

     文件       1983  2010-12-12 12:25  Jacobi_Gauss_seidel\Jacobi_Gauss_seidel.clw

     文件       1835  2010-12-30 16:56  Jacobi_Gauss_seidel\Jacobi_Gauss_seidel.cpp

     文件       3557  2010-12-30 18:03  Jacobi_Gauss_seidel\Jacobi_Gauss_seidel.dsp

     文件        563  2010-12-30 18:04  Jacobi_Gauss_seidel\Jacobi_Gauss_seidel.dsw

     文件       1499  2010-12-12 12:25  Jacobi_Gauss_seidel\Jacobi_Gauss_seidel.h

     文件      58368  2010-12-30 18:04  Jacobi_Gauss_seidel\Jacobi_Gauss_seidel.ncb

     文件      48640  2010-12-30 18:04  Jacobi_Gauss_seidel\Jacobi_Gauss_seidel.opt

     文件        813  2010-12-30 18:03  Jacobi_Gauss_seidel\Jacobi_Gauss_seidel.plg

     文件       9190  2010-12-12 12:25  Jacobi_Gauss_seidel\Jacobi_Gauss_seidel.rc

     文件       2002  2010-12-12 12:25  Jacobi_Gauss_seidel\Jacobi_Gauss_seidelDoc.cpp

     文件       1618  2010-12-12 12:25  Jacobi_Gauss_seidel\Jacobi_Gauss_seidelDoc.h

     文件       2241  2010-12-12 12:25  Jacobi_Gauss_seidel\Jacobi_Gauss_seidelView.cpp

     文件       1926  2010-12-12 12:25  Jacobi_Gauss_seidel\Jacobi_Gauss_seidelView.h

     文件       1510  2010-12-12 12:25  Jacobi_Gauss_seidel\MainFrm.cpp

     文件       1421  2010-12-12 12:25  Jacobi_Gauss_seidel\MainFrm.h

     文件       4295  2010-12-12 12:25  Jacobi_Gauss_seidel\ReadMe.txt

     文件       1078  2010-12-12 12:25  Jacobi_Gauss_seidel\res\Jacobi_Gauss_seidel.ico

     文件        411  2010-12-12 12:25  Jacobi_Gauss_seidel\res\Jacobi_Gauss_seidel.rc2

     文件       1078  2010-12-12 12:25  Jacobi_Gauss_seidel\res\Jacobi_Gauss_seidelDoc.ico

     文件        477  2010-12-12 12:25  Jacobi_Gauss_seidel\Resource.h

     文件        221  2010-12-12 12:25  Jacobi_Gauss_seidel\StdAfx.cpp

............此处省略7个文件信息

评论

共有 条评论