已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1)用高斯列主元消元法求解下面的方程组#include #include #include using namespace std;int main()/double a45=1,-1,1,-4,2, 5,-4,3,12,4, 2, 1,1,11,3, 2,-1,7,-1,0;/int i,j,k;int Line,Row;double temp45;/中间量Row=4;Line=5;/Inintial/Result/double X5;cout最初的矩阵为:endl;for(i=0;i4;i+)for(j=0;j5;j+)coutaij ;coutendl;coutendl;/for(k=0;kRow-1;k+)/for(i=k+1;iRow;i+)/tempik=aik/akk;for(j=k;jLine;j+)aij-=tempik*akj;/cout经过消元后的增广矩阵为:endl;for(i=0;i4;i+)for(j=0;j5;j+)coutaij ;coutendl;cout=0;i-)/double temp_new;temp_new=0;for(j=i+1;j=Row-1;j+)aiRow-=aij*ajRow;aiRow/=aii;/Print;cout最后的解为:endl;for(i=0;iRow;i+)/coutXi+1=aiRowendl;/return 0;1.2 列主元方法#include #include #include using namespace std;void Print(double a5)int i,j;for(i=0;i4;i+)for(j=0;j5;j+)coutaij ;coutendl;coutendl;int main()/double a45=1,-1,1,-4,2, 5,-4,3,12,4, 2, 1,1,11,3, 2,-1,7,-1,0;/double b45=0.3e-15,int i,j,k,n;int Line,Row;double temp45;/中间量Row=4;Line=5;/Inintial/cout最初的矩阵为:endl;Print(a);/the main process is underint kk;/flagsdouble max; /bool flag=false;double t;/the temp of change;for(k=0;kRow-1;k+)/search the max_num/flag=false;max=akk;kk=k;for(i=k;imax)max=aik;kk=i;/flag=true;/change the linefor(j=0;jLine;j+)t=akj;akj=akkj;akkj=t;cout第k+1次换行结果:endl;Print(a);coutendl;cout第k+1次消元结果:endl;/消元的过程for(i=k+1;iRow;i+)/tempik=aik/akk;for(j=k;j=0;i-) / double temp_new; temp_new=0; for(j=i+1;j=n;j+) ain+1-=aij*ajn+1; ain+1/=aii;/cout经过消元后的增广矩阵为:endl;Print(a);/Print;cout最后的解为:endl;for(i=0;iRow;i+)/coutXi+1=aiRowendl;/return 0;2)分别用列主元消元法与不选主元消元法求解,分析对结果的影响#include #include #include using namespace std;void Print(double b5)int i,j;for(i=0;i4;i+)for(j=0;j5;j+)coutbij ;coutendl;coutendl;int main()double b45=0.3e-15,59.14,3,1,59.17, 5.291,-6.130,-1,2,46.78,11.2,9,5,2,1,1,2,1,1,2; int i,j,k,n;int Line,Row;double temp45;/中间量Row=4;Line=5;/Inintial/cout最初的矩阵为:endl;Print(b);/the main process is underint kk;/flagsdouble max; /bool flag=false;double t;/the temp of change;for(k=0;kRow-1;k+)/search the max_num/flag=false;max=bkk;kk=k;for(i=k;imax)max=bik;kk=i;/flag=true;/change the linefor(j=0;jLine;j+)t=bkj;bkj=bkkj;bkkj=t;cout第k+1次换行结果:endl;Print(b);coutendl;cout第k+1次消元结果:endl;/消元的过程for(i=k+1;iRow;i+)/tempik=bik/bkk;for(j=k;j=0;i-) / double temp_new; temp_new=0; for(j=i+1;j=n;j+) bin+1-=bij*bjn+1; bin+1/=bii;/cout经过消元后的增广矩阵为:endl;Print(b);/Print;cout最后的解为:endl;for(i=0;iRow;i+)/coutXi+1=biRowendl;/return 0;2、 用迭代法求解 (迭代法收敛速度实验)注意修改不同的A 、B的数组3、 /雅可比迭代法/* auther luozhengxiao*/#include #include #include using namespace std;/void Print(double x)for(int i=0;i3;i+)coutsetprecision(8)fixedxiendl;int main()/double B13=-3,2,4; double B23=100,-200,345; double A33=6,2,-1, 1,4,-2,-3,1,4; double x3,x_old3,temp;int i,j,k;for(i=0;i3;i+)cout请输入第i+1个数:;coutt xixi;/x_oldi=xi;int n;coutn;/for(k=0;kn;k+
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工程项目资料档案管理制度
- 保险合同合作框架协议模板
- 企业财务风险识别与管控
- 中学英语单元测试卷设计模板
- 2023综合管理部年度工作计划
- 学前儿童运动能力科学培养方案
- 物流企业员工安全培训课件
- 职业教育课程设计与教学方法指南
- 部编版小学读写教学案例汇编
- 物业日常保洁服务操作标准方案
- 青少年非自杀性自伤的护理
- 数字孪生水利信息化建设方案
- 《嵌入式实验与实践教程-基于STM32与Proteus》课件-第三章
- 《嵌入式实验与实践教程-基于STM32与Proteus》课件-第四章
- 2025四川泸州纳溪城乡建设发展集团有限公司招聘补充考试参考试题及答案解析
- 《管理学》(第二版)课件全套 高教版马工程 第0-16章 绪论 - 组织变革与创新
- 2025年卫生高级职称面审答辩(中医内科)在线题库(副高面审)练习题及答案
- 2025年医学人文试题题库及答案
- 无人机管理平台建设方案
- 统编版(2024)八年级上册历史第一、二单元综合评估测试卷(含答案)
- 制造企业成本管理办法
评论
0/150
提交评论