![[数值算法]求矩阵的最大特征值的幂法_第1页](http://file1.renrendoc.com/fileroot_temp2/2020-6/5/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd9/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd91.gif)
![[数值算法]求矩阵的最大特征值的幂法_第2页](http://file1.renrendoc.com/fileroot_temp2/2020-6/5/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd9/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd92.gif)
![[数值算法]求矩阵的最大特征值的幂法_第3页](http://file1.renrendoc.com/fileroot_temp2/2020-6/5/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd9/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd93.gif)
![[数值算法]求矩阵的最大特征值的幂法_第4页](http://file1.renrendoc.com/fileroot_temp2/2020-6/5/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd9/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd94.gif)
![[数值算法]求矩阵的最大特征值的幂法_第5页](http://file1.renrendoc.com/fileroot_temp2/2020-6/5/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd9/3cd6b4bc-39e8-4a9f-8240-1af3ec1f0fd95.gif)
已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
数值算法求矩阵的最大特征值的幂法.对于工程计算而言,矩阵的特征值和特征向量都是相当重要和常见的数据,这里给出的幂法是一种常见的求解方法,用的是迭代的思想。符号说明:1A为待求的矩阵,2Uk,Vk为迭代用的列向量。3最后的最大特征值maxLamda由最后一次的max(Uk)-求Uk中的绝对值最大的元素的绝对值.所决定。而maxLamda所对应的特征向量由最后一次迭代的Vk所决定.主要的想法就是先选一个不为0的初始向量U0!=0,然后按下面的式子迭代。U0=V0!=0DoUk=AVk-1Vk=Uk/max(Uk)while(abs(max(Uk)-max(Uk-1)=e)/e为精度.好了,就这样,更多的细节请去参考相关的数值算法书籍.在贴出程序之前,先对一部分我新增加的实用函数进行说明:如:void twoDArrMemApply(Type* inArr,int rowNum,int colNum)int i=0;/*iterator vaule*/(*inArr)=(Type*)malloc(sizeof(Type*)*rowNum);for(i=0;irowNum;i+)(*inArr)i=(Type*)malloc(sizeof(Type)*colNum);assertF(*inArr!=NULL,in twoDArrMemApply,inArr at last is nulln);void twoDArrMemFree(Type* inArr,int rowNum)int i=0;/*iterator value*/assertF(*inArr)!=NULL,in 2d arr mem free,in arr is nulln);for(i=0;irowNum;i+)free(*inArr)i);free(*inArr);这两个函数的作用相信大家一看就明白,是实现二维指针的申请内存和释放内存的,这样,以后再主程序里的工作量就会小多了。还有,我在写一些程序段的时候对待外部传进的指针采用如下处理手段(纯C条件下)除非这个函数有特殊的作用,如申请内存,或要读入外部文本内容到二维指针等。 其余的情况,一律不对外部指针进行任何申请或释放内存的处理。对于要保护数据的外部传入指针,则在函数内部再做一个局部指针,在函数结尾释放.对局部指针的操作,也仅限于赋值,而绝对不要用外部传入针指去指向它(即赋一个临时区的地址给外部的指针变量),这当然是错误的。好了,下面是程序段:/*for max lamda resolve*/ Type powerMethodForLamda(Type* matrixA,int size,char* outputFileName) Type maxLamda; Type* listV; Type* listU; FILE* outputFile;/*the outputFile for the data output*/ Type preMax;/*a tween data*/ float e=(float)0.0001;/*the precise controller*/ Type tmpData;/*temp data for program*/ int i=0;/*iterator times*/ int iteratorNum=0;/*iterator number*/ /*assertion*/ assertF(matrixA!=NULL,in powerMethodFor lamda,matrixA is nulln); assertF(outputFileName!=NULL,in readList,listFileName is nulln); /*open file*/ assertF(outputFile=fopen(outputFileName,wb)!=NULL,output file open errorn); /*mem apply*/ listArrMemApply(&listV,size); listArrMemApply(&listU,size); /*initialization*/ for(i=0;i=e); fprintf(outputFile,charactstic vector is:rn); outputListArrFloat(listV,0,size,outputFile); /*End of the Core Program*/ maxLamda=maxAbsValInList(listU,size); fprintf(outputFile,the max lamda is:rn %f.rn,maxLamda); /*mem free*/ free(listV); free(listU); /*close the file*/ fclose(outputFile); return maxLamda; /*相应的辅助函数*/ /* matirxBy2DWith1DCol 一个n*n的矩阵和一个n*1的列向量作乘法*/ void matirxBy2DWith1DCol(Type* matrixA,Type* matrixListIn,Type* matrixListAns,int rowNum,int mNum) /*variable declare*/ int i,k;/*iterator number*/ Type sum; /*assertion*/ assertF(matrixA!=NULL,in twoMatrixBy matrixA is nulln); assertF(matrixListIn!=NULL,in twoMatrixBy matrixB is nulln); assertF(matrixListAns!=NULL,in twoMatrixBy matrixAns is nulln); /*core program*/ for(i=0;irowNum;i+) sum=0; for(k=0;kmNum;k+) sum+=matrixAik*matrixListInk; matrixListAnsi=sum; /*求一个一维向量中绝对值的最大值*/ Type maxAbsValInList(Type* inList,int len) int i;/*iterator num*/ Type maxData; assertF(inList!=NULL,in maxValInList,inList is NULLn); maxData=(Type)fabs(inList0); for(i=1;imaxData)maxData=(Type)fabs(inListi); return maxData; /*test program*/ /*maxLamda resolve test program*/ #include Global.h #include Ulti.h #include Matrix.h #include MyAssert.h #include #include #include #include char *inFileName=inputData.txt; /* input data specification row,col; /Arr a11,a12,.; , , , , , , , , an1,an2,.; */ char *outFileName=outputData.txt; #define DEBUG 1 void main(int argc,char* argv) FILE *inputFile;/*input file*/ FILE *outputFile;/*output file*/ double startTime,endTime,tweenTime;/*time callopsed info*/ int rowNum,colNum; Type* wArr; Type maxLamda; int n;/*arr deminision for squre matrix*/ /*default input file open*/ if(argc1)strcpy(inFileName,argv1); assertF(inputFile=fopen(inFileName,rb)!=NULL,input file error); printf(input file open successn); /*default outpout file open*/ if(argc2)strcpy(outFileName,argv2); assertF(outputFile=fopen(outFileName,wb)!=NULL,output file error); printf(output file open successn); /*This function,automatically fullfill the task of apply the mem for the 2d pointers. Perfect,right? :)*/ read2DArrFloat(&wArr,&rowNum,&colNum,inputData2.txt); #if DEBUG printf(n*start of test program*n); printf(now is runnig,please wait.n); startTime=(double)clock()/(double)CLOCKS_PER_SEC; /*Core program code*/ /*argu prepare*/ assertF(colNum=rowNum,in test colNum!=rowNum); n=rowNum;/*get the size of square matrix*/ maxLamda=powerMethodForLamda(wArr,n,output2.txt); printf(the max lamda is:%f.rn,maxLamda); fprintf(outputFile,the max lamda is:%f.rn,maxLamda); /*End of Core program*/ endTime=(double)clock()/(double)CLOCKS_PER_SEC; tweenTime=endTime-startTime;/*Get the time collapsed*/ /*Time collapsed output*/ printf(the collapsed time in this algorithm implement is:%fn,tweenTime); fprintf(outputFile,the collapsed time in this algorithm implement is:%frn,tweenTime); printf(n*end of test program*n); #endif twoDArrMemFree(&wArr,rowNum); printf(program end successfully,n you have to preess any key to clean the buffer area to output,otherwise,you wiil not get the total answer.n); getchar();/*Screen Delay Control*/ return; 测试结果:输入:3,3;2,3,2;10,3,4;3,6,1;输出:iteratorTime maxUk0 4.000000 0 9.000000 0 11.444445 0 10.922329 0 11.014222 0 10.997417 0 11.000469 0 10.999914 0 11.000015 0 10.999997 charactstic vector is:0.500000,1.000000,0.750000;the max lamda is: 10.999997.PS:最近在数模班里,也的确看到了别的专业一些对程序和算法在理解上比较强能力的人,虽然他们可以告诉你解决了某个问题,但你看一眼他写的程序,充斥在你眼里的,都是大量的“蛮力”算法,像10个层甚至更高层的for循环比比皆是,基本上就是针对这个问题的特型算
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- (完整版)数学北师大六年级下册期末重点小学真题答案
- 上海求真中学八年级上册期末数学模拟试卷含详细答案
- 深圳沙井上南学校八年级上册期末数学模拟试卷及答案
- 七年级英语动词时态练习题带答案
- 患者跌倒坠床的应急预案试题及答案
- 工业机器人系统操作员技术及理论知识竞赛试题库附含答案
- 2024年企业人力资源管理师三级试题及答案
- 2025年国际汉语教师证书CTCSOL笔试真题及答案解析教学理论与实践案例实战
- 2025年绥化海伦市公务员招聘考试备考试题附答案解析
- 2025年工程监理工程师职业资格考试试题及答案解析
- 白酒分销商合同协议书
- 卫星通信技术的前沿发展及其在物联网中的应用-洞察阐释
- 《医学中心肺癌诊疗》(讲课课件)
- 物流公司法人代表个人简介范文
- 规模灵活资源广域接入的新型配电系统分层分群架构与规划技术研究
- 2025年恒丰银行烟台分行招聘笔试参考题库含答案解析
- 中外建筑史课件
- 2024年度商业保理合同:保理公司与出口商之间的商业保理协议3篇
- 宣传网络安全文明上网
- 泡沫混凝土路基填筑施工方案
- 青岛 二年级 数学 上册 第4单元《8的乘法口诀》教学课件
评论
0/150
提交评论