方程组直接三角分解法
- 格式:ppt
- 大小:442.00 KB
- 文档页数:20
甘肃政法学院本科学年论文(设计)题目浅议线性方程组的几种求解方法学号:姓名:指导教师:成绩:__________________完成时间: 2012 年 11 月目录第一章引言 (1)第二章线性方程组的几种解法 (1)2.1 斯消元法 (1)2.1.1 消元过程 (1)2.1.2 回代过程 (2)2.1.3 解的判断 (2)2.2 克莱姆法则 (3)2.3 LU分解法 (4)2.4 追赶法 (6)第三章结束语 (8)致谢 (8)参考文献 (9)摘要:线性方程组是线性代数的核心内容之一,其解法研究是代数学中经典且重要的研究课题.下面将综述几种不同类型的线性方程组的解法,如消元法、克莱姆法则、直接三角形法、、追赶法,并以具体例子介绍不同解法的应用技巧. 在这些解法中,高斯消元法方法,具有表达式清晰,使用范围广的特点.另外,这些方法有利于快速有效地解决线性方程组的求解问题,为解线性方程组提供一个简易平台,促进了理论与实际的结合。
关键词:线性方程组;解法;应用Several methods of solving linear equation groupAbstract: The system of linear equations is one of linear algebra core contents, its solution research is in the algebra the classics also the important research topic. This article summarized several kind of different type system of linear equations solution, like the elimination, the Cramer principle, the generalized inverse matrix law, the direct triangle law, the square root method, pursue the law, and by concrete example introduction different solution application skill. In these solutions, the generalized inverse matrix method, has the expression to be clear, use scope broad characteristic. Moreover, these methods favor effectively solve the system of linear equations solution problem fast, provides a simple platform for the solution system of linear equations, promoted the theory and the actual union.Key word: Linear equations; Solution ; Example第一章 引言线性方程组理论是高等数学中十分重要的内容,而线性方程组的解法是利用线性方程组理论解决问题的关键.下面将介绍线性方程组的消元法、追赶法、直接三角形法等求解方法,为求解线性方程组提供一个平台。
三角分解法解线性方程组#include<iostream.h>#include<iomanip.h>#include<stdlib.h>//----------------------------------------------全局变量定义区 const int Number=15; //方程最大个数doublea[Number][Number],b[Number],copy_a[Number][Number],copy_b[Number]; // 系数行列式int A_y[Number]; //a[][]中随着横坐标增加列坐标的排列顺序,如a[0][0],a[1][2],a[2][1]...则A_y[]={0,2,1...}; int lenth,copy_lenth;//方程的个数char * x; //未知量a,b,c的载体int i,j;//----------------------------------------------函数声明区 voidinput(); //输入方程组void print_menu(); //打印主菜单int Doolittle_check(double a[][Number],double b[Number]); //判断是否行列式>0,若是,调整为顺序主子式全>0void xiaoqu_u_l(); //将行列式Doolittle分解 void calculate_u_l(); //计算Doolittle结果 void exchange(int m,int i); //交换A_y[m],A_y[i] void exchange_lie(int j); //交换a[][j]与b[]; void exchange_hang(int m,int n);//分别交换a[][]和b[]中的m与n两行 void exchange_a_lie(int m,int n); //交换a[][]中的m和n列 void exchange_x(int m,int n); //交换x[]中的x[m]和x[n] //函数定义区void print_menu(){system("cls");cout<<"------------方程系数和常数矩阵表示如下:\n"; for(intj=0;j<lenth;j++)cout<<"系数"<<j+1<<" ";cout<<"\t常数";cout<<endl;for(int i=0;i<lenth;i++){for(j=0;j<lenth;j++)cout<<setw(8)<<setiosflags(ios::left)<<a[i][j];cout<<"\t"<<b[i]<<endl; }}void input(){int i,j;cout<<"方程的个数:";cin>>lenth;if(lenth>Number){cout<<"It is too big.\n";return;}x=new char[lenth];for(i=0;i<lenth;i++)x[i]='a'+i;//输入方程矩阵//提示如何输入cout<<"====================================================\n";cout<<"请在每个方程里输入"<<lenth<<"系数和一个常数:\n"; //输入每个方程for(i=0;i<lenth;i++){cout<<"输入方程"<<i+1<<":";for(j=0;j<lenth;j++)cin>>a[i][j];cin>>b[i];}}void Doolittle() //Doolittle消去法计算方程组 {double temp_a[Number][Number],temp_b[Number];int i,j,flag;for(i=0;i<lenth;i++)for(j=0;j<lenth;j++)temp_a[i][j]=a[i][j]; flag=Doolittle_check(temp_a,temp_b);if(flag==0) cout<<"\n行列式为零.无法用Doolittle求解."; xiaoqu_u_l();calculate_u_l();cout<<"用Doolittle方法求得结果如下:\n";for(i=0;i<lenth;i++) //输出结果{for(j=0;x[j]!='a'+i&&j<lenth;j++);cout<<x[j]<<"="<<b[j]<<endl;}}void calculate_u_l() //计算Doolittle结果{ int i,j;double sum_ax=0; for(i=0;i<lenth;i++){for(j=0,sum_ax=0;j<i;j++)sum_ax+=a[i][j]*b[j];b[i]=b[i]-sum_ax;}for(i=lenth-1;i>=0;i--){for(j=i+1,sum_ax=0;j<lenth;j++)sum_ax+=a[i][j]*b[j];b[i]=(b[i]-sum_ax)/a[i][i]; }}void xiaoqu_u_l() //将行列式按Doolittle分解{ int i,j,n,k;double temp; for(i=1,j=0;i<lenth;i++)a[i][j]=a[i][j]/a[0][0]; for(n=1;n<lenth;n++){ //求第n+1层的上三角矩阵部分即Ufor(j=n;j<lenth;j++){ for(k=0,temp=0;k<n;k++)temp+=a[n][k]*a[k][j];a[n][j]-=temp;}for(i=n+1;i<lenth;i++) //求第n+1层的下三角矩阵部分即L{ for(k=0,temp=0;k<n;k++)temp+=a[i][k]*a[k][n];a[i][n]=(a[i][n]-temp)/a[n][n];}}}int Doolittle_check(double temp_a[][Number],double temp_b[Number]) //若行列式不为零,将系数矩阵调整为顺序主子式大于零{int i,j,k,maxi;double lik,temp;for(k=0;k<lenth-1;k++){j=k;for(maxi=i=k;i<lenth;i++)if(temp_a[i][j]>temp_a[maxi][j]) maxi=i;if(maxi!=k){ exchange_hang(k,maxi);for(j=0;j<lenth;j++){ temp=temp_a[k][j];temp_a[k][j]=temp_a[maxi][j];temp_a[maxi][j]=temp;}}for(i=k+1;i<lenth;i++){lik=temp_a[i][k]/temp_a[k][k];for(j=k;j<lenth;j++)temp_a[i][j]=temp_a[i][j]-temp_a[k][j]*lik;temp_b[i]=temp_b[i]-temp_b[k]*lik;}}if(temp_a[lenth-1][lenth-1]==0) return 0;return 1;}void exchange_hang(int m,int n) //交换a[][]中和b[]两行 { int j; double temp;for(j=0;j<lenth;j++){ temp=a[m][j];a[m][j]=a[n][j];a[n][j]=temp;}temp=b[m];b[m]=b[n];b[n]=temp;}void exchange(int m,int i) //交换A_y[m],A_y[i] { int temp;temp=A_y[m];A_y[m]=A_y[i];A_y[i]=temp;}void exchange_lie(int j) //交换未知量b[]和第i列 { double temp;int i; for(i=0;i<lenth;i++){ temp=a[i][j];a[i][j]=b[i];b[i]=temp;}}void exchange_a_lie(int m,int n) //交换a[]中的两列{ double temp;int i; for(i=0;i<lenth;i++) { temp=a[i][m];a[i][m]=a[i][n];a[i][n]=temp;}}void exchange_x(int m,int n) //交换未知量x[m]与x[n] { char temp;temp=x[m];x[m]=x[n];x[n]=temp;}//主函数void main(){int flag=1;input(); //输入方程while(flag){print_menu(); //打印主菜单cout<<"用Doolittle方法求得结果如下:\n";for(i=0;i<lenth;i++) //输出结果{for(j=0;x[j]!='a'+i&&j<lenth;j++);cout<<x[j]<<"="<<b[j]<<endl;}}}。
用矩阵的直接三角分解法解方程组矩阵的直接三角分解法(LU分解法)是解线性方程组的一种常用方法。
该方法通过将系数矩阵分解为一个下三角矩阵和一个上三角矩阵的乘积,从而简化方程组的求解过程。
下面我们就来详细分步骤地介绍一下这种方法的求解过程。
第一步,将原线性方程组表示为矩阵形式,即将系数矩阵、未知量矩阵和常数矩阵分别表示为A、X和B。
我们的目标是找到一个下三角矩阵L和一个上三角矩阵U,使得方程组可以表示为LUx = B的形式。
第二步,通过高斯消元法将系数矩阵A化为上三角矩阵U。
具体地,我们将系数矩阵A变换为U的过程可以分解为一系列的初等矩阵变换,例如交换两行、乘以一个非零常数和将某一行加上另一行的若干倍等等。
这些初等矩阵变换可以表示为一个矩阵M的乘积,即A =M1M2...MnU。
从而,我们得到了上三角矩阵U。
第三步,同样通过一系列初等矩阵变换将U转化为下三角矩阵L。
这些初等矩阵变换可以表示为一个矩阵N的乘积,即U = NL1L2...Lm。
从而,我们得到了下三角矩阵L。
第四步,将方程组表示为LUx = B的形式。
具体地,我们将A, X 和B分解为L, U和x的乘积,即A = LU,X = UL,B = Ux。
从而,原方程组可以表示为LUx = B,即L(Ux) = B。
第五步,解方程组L(Ux) = B。
由于L是下三角矩阵,因此可以通过前代法求解得到Ux。
具体地,我们先通过Lw = B求解出向量w,然后再通过Ux = w求解出未知量向量x。
总的来说,矩阵的直接三角分解法(LU分解法)是一种常用的解线性方程组的方法。
它将原方程组表示为LUx = B的形式,然后通过前代法和回代法求解得到未知量向量x。
这种方法具有求解速度快、计算量小的优点,因此在实际应用中得到了广泛的应用。
直接三角分解法求解方程组c语言直接三角分解法是一种常用的求解线性方程组的方法,它可以通过高斯消元和矩阵变换来将系数矩阵化为一个上三角矩阵,从而简化求解过程。
以下是使用C语言实现直接三角分解法求解方程组的步骤:1. 定义一个二维数组来表示方程组的系数矩阵和常数向量,例如:```cdouble A[N][N+1];```其中N为方程组的未知数个数加1,因为常数向量也要占用一列。
2. 输入方程组的系数矩阵和常数向量,例如:```cfor(int i=0; i<N; i++){for(int j=0; j<=N; j++){scanf("%lf", &A[i][j]);}```3. 进行高斯消元,将系数矩阵化为上三角形式。
具体实现方法如下:```cfor(int k=0; k<N-1; k++) //k表示当前正在处理第k行{for(int i=k+1; i<N; i++) //i表示当前正在处理第i行{double f = A[i][k] / A[k][k]; //计算倍率因子ffor(int j=k+1; j<=N; j++) //j表示当前正在处理第j列{A[i][j] -= f * A[k][j]; //用倍率因子消元}}}```4. 回代求解未知数。
由于系数矩阵已经化为上三角形式,因此可以从最后一行开始回代求解未知数。
具体实现方法如下:double x[N]; //用来存放未知数的解for(int i=N-1; i>=0; i--) //从最后一行开始回代{x[i] = A[i][N];for(int j=i+1; j<N; j++) //用已求出的未知数更新x[i]{x[i] -= A[i][j] * x[j];}x[i] /= A[i][i]; //除以对角线元素得到x[i]}```5. 输出未知数的解,例如:```cfor(int i=0; i<N-1; i++){printf("x%d = %f\n", i+1, x[i]);}```以上就是使用C语言实现直接三角分解法求解方程组的完整步骤。