北航数值分析上机作业 二 (报告+所有程序大全)_第1页
北航数值分析上机作业 二 (报告+所有程序大全)_第2页
北航数值分析上机作业 二 (报告+所有程序大全)_第3页
北航数值分析上机作业 二 (报告+所有程序大全)_第4页
北航数值分析上机作业 二 (报告+所有程序大全)_第5页
已阅读5页,还剩21页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、数值分析上机作业2qr分解求特征值题目:双步位移qr分解法求a的全部特征值,对每一个实特征值求特征向量。已知1. 算法设计方案总体算法与老师的讲义和课本一致,在这里对自己的设计和改进做说明。算法的关键在于对于被运算的矩阵a的左下角理论为0的元素不再计算。1) a拟上三角化对于,记,则,这样去掉了系数,便于计算。设对a到的拟上三角化进行到到第k步,后半段不为0的部分是,则,只需要计算矩阵的右上角,右下角,和左下角即可,计算过程中按照行向量左乘矩阵以及列向量右乘矩阵的运算方法进行,左下角矩阵只有最右列有非零元素,可以简化运算。2) qr分解对于,记,则,这样去掉了系数,便于计算。设对a到的qr分解

2、进行到到第k步,。后半段不为0的部分是,则,这样只需要计算矩阵的右上角和右下角矩阵。计算矩阵的右上角和右下角矩阵时,计算过程中按照行向量左乘矩阵以及列向量右乘矩阵的运算方法进行。3) 求特向量的方法对进行选主元的高斯消去法,化成上三角阵,进行带入求解,对于第k行,如果出现,并且的情况,直接令为1。特向量完成求解后再进行归一化。2. 拟上三角的a1) 12位有效数字的形式-8.82751675883e-001-9.93313649183e-002-1.10334928599e+000-7.60044358564e-0011.54910107991e-001-1.94659186287e+000-

3、8.78243638293e-002-9.25588938718e-0016.03259944053e-0011.51886095647e-001-2.34787836242e+0002.37237010494e+0001.81929082221e+0003.23780410155e-0012.20579844032e-0012.10269266255e+0001.81613808610e-0011.27883908999e+000-6.38057812440e-001-4-0010.00000000000e+0001.72827459997e+000-1.17146

4、764279e+000-1.24383926270e+000-6.39975834174e-001-2.00283307904e+0002.92494720612e-001-6.41283006840e-0019.78399762128e-0022.55776357416e-0010.00000000000e+0000.00000000000e+000-1.29166953413e+000-1.11160351340e+0001+000-1.30735603002e+0001.80369917775e-001-4.24638535837e-0017.988955239

5、30e-0021.60881992807e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0001.56012629853e+0008.12504939751e-0014.42175683292e-001-3.58861612814e-0024.69174231367e-001-2.73659505009e-001-7.35933465775e-0020.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-7.70777375519e-001-

6、1.58305142574e+000-3.04284317680e-0012.52871244603e-001-6.70992540145e-0012.54461992908e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-7.46345345694e-001-2.70836515702e-002-9.48652189368e-0011.19587108150e-0011.92926561795e-0020.00000000000e+0000.00000

7、000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-7.70180137436e-001-4.69762399062e-0014.98825946801e-0011-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0007.01316709211e-00

8、11.58218068848e-0013.86259461423e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0004.84380760278e-0013.99277799518e-0012) 3位小数位的形式-0.883-0.099-1.103-0.7600.155-1.947-0.088-0.9260.6030.152-2.3482.3721.81

9、90.3240.2212.1030.1821.279-0.638-0.4150.0001.728-1.171-1.244-0.640-2.0030.292-0.6410.0980.2560.0000.000-1.292-1.1121.171-1.3070.180-0.4250.0800.1610.0000.0000.0001.5600.8130.442-0.0360.469-0.274-0.0740.0000.0000.0000.000-0.771-1.583-0.3040.253-0.6710.2540.0000.0000.0000.0000.000-0.746-0.027-0.9490.1

10、200.0190.0000.0000.0000.0000.0000.000-0.770-0.4700.4990.1140.0000.0000.0000.0000.0000.0000.0000.7010.1580.3860.0000.0000.0000.0000.0000.0000.0000.0000.4840.3993. a(n-1)进行qr分解得到q,r,以及rq1) 12位有效数字的e型输出:拟上三角a,qr之后的q:-3.51926257953e-001-9.36027728736e-0010.00000000000e+0000.00000000000e+0000.00000000000

11、e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-7.39595535350e-001-3.31120858752e+000-8.81052055469e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0002.40254545121e-001-4.4

12、8034907538e+000-5+000-5.37180680644e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-1.43125202505e-0012.66904781503e+0006.54274505882e+0001.19520089248e+0009.89223546862e-0010.00000000000e+0000.00000000000e+0000.0000000000

13、0e+0000.00000000000e+0000.00000000000e+000-1.96077644897e-0013.65652310377e+0008.96338324661e+0003.85510755662e-0012.70771861608e+0005.32361069026e-001-0.00000000000e+000-0.00000000000e+000-0.00000000000e+000-0.00000000000e+000-5.63148539010e-0011.05017869060e+0012.57434557752e+0011.10721351706e+000

14、4.11588263550e+0009.26346777492e-001-6.05976150575e-0010.00000000000e+0000.00000000000e+0000.00000000000e+000-3-0015.87640573131e+0001.44050714811e+0016.19555121015e-0012.30309341878e+0003.78744079911e-002-7.93763324139e-0019.93339662512e-0010.00000000000e+0000.00000000000e+000-9.181777

15、90891e-0021.71224940381e+0004.19730634392e+0001.80524105226e-0016.71068424056e-0011.10357309328e-002-1.60433215213e+0002.40658785801e+0005.41008800606e-0010.00000000000e+000-1.56690148242e-0012.92201157088e+0007.16284536362e+0003.08070496692e-0011+0001.88328484197e-002-2.73784712766e+00

16、02.07736354786e+0002.51193105972e-001-7.22159133673e-001-8.85680693195e-0021.65164770259e+0004.04875093812e+0001.74134809446e-0016.47317276562e-0011.06451429335e-002-1.54754996986e+0001+000-2.51782156703e-0016.91726958888e-001拟上三角a,qr之后的r:2.50834274492e+000-2+000-1.31460907

17、079e+000-3.55878749384e-002-2.60985785039e-001-1.28312184709e+000-1.39087861061e-001-8.71289797216e-0013.84936790297e-0013.35380289967e-0010.00000000000e+000-1.96160327785e+0002.40752372763e-0017.05471457282e-0015.95720431828e-0015.52697877468e-001-3.26820992441e-001-5.76949866836e-0022.87112933019e

18、-001-8.89512875419e-0020.00000000000e+0000.00000000000e+0002.40453460199e+0001.70675809633e+000-4.23956670409e-0013.40533230581e+000-1.05001765585e-0011.46225710273e+000-6.68448746928e-001-4.02764620966e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0001.57712208072e+0006.39953513396e-0013.4

19、6812787243e-001-5.70178664977e-0024.01478805443e-001-2.22247617631e-001-6.31705923644e-0020.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-1.44784699777e+000-1.41572400774e+000-2.80613904467e-001-2.81791052189e-001-4.61143488185e-0021.99662907996e-0010.00000000000e+0000.00000

20、000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0001.23164145154e+0001.61970100342e-0011.96263827550e-0015.35003562176e-001-1.50927342477e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-7.75344191421e-001-3.46451450882e-0

21、014.31222680350e-0011.23464369624e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0001.29631294061e+000-4.28805331834e-0012.73733415816e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.0000000

22、0000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-6.70739644065e-001-4.84232012188e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0007.16832392632e-002拟上三角a,qr之后的rq:1.163

23、07441416e+0006.54021266522e+0001.71698760912e+001-1.50944630535e+001-2.16705228879e+001-6.04262699693e+001-3.39980110592e+001-1+001-1.81045579997e+001-1.00161647810e+0011.83611506085e+0006.28316224606e+0007+000-2.22795075154e+000-2.83544695057e+000-1.04594830181e+001-6.0270

24、0244190e+000-1.27420738622e+000-2+000-1.44657481541e+0000.00000000000e+000-2.11852015353e+000-1.32735235180e+0011.73527877647e+0012.28756497487e+0016.52639670964e+0013.63833511946e+0011.34796269561e+0012.07757966695e+0011+0010.00000000000e+0000.00000000000e+000-8.4719951278

25、1e-0012.51803480278e+0002.52544119293e+0004.73600481425e+0002.90818562795e+0001.65542017861e+0002.20518743642e+0001.26449870642e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-1.43224434245e+000-4.67403861531e+000-7.10057435575e+000-3.44531980370e+000-1.24013323626e+000-1.65761440713e+000

26、-6.99183495559e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0006.55677959800e-0011.04277707175e+0001-0015-0012.30840029271e-001-2.46194560930e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0004.69840088

27、488e-0012.71295815438e-0016.43439025273e-0011.42222749450e+0007.69904500551e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0001.28767905894e+0002.88770352479e+0002.38752121986e+0001.81946570709e+0000.00000000000e+0000.00000000000e+0000.00

28、000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-3.62876050354e-0011.81207395928e-001-1.66076063019e-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000-5/p>

29、e-0024.95852290988e-0022) 3位小数形式输出拟上三角a,qr之后的q:-0.352-0.9360.0000.0000.0000.0000.0000.0000.0000.000-0.740-3.311-0.8810.0000.0000.0000.0000.0000.0000.0000.240-4.480-5.139-0.5370.0000.0000.0000.0000.0000.000-0.1432.6696.5431.1950.9890.0000.0000.0000.0000.000-0.1963.6578.9630.3862.7080.532-0.000-0.000-

30、0.000-0.000-0.56310.50225.7431.1074.1160.926-0.6060.0000.0000.000-0.3155.87614.4050.6202.3030.038-0.7940.9930.0000.000-0.0921.7124.1970.1810.6710.011-1.6042.4070.5410.000-0.1572.9227.1630.3081.1450.019-2.7382.0770.251-0.722-0.0891.6524.0490.1740.6470.011-1.5481.174-0.2520.692拟上三角a,qr之后的r:2.508-2.186

31、-1.315-0.036-0.261-1.283-0.139-0.8710.3850.3350.000-1.9620.2410.7050.5960.553-0.327-0.0580.287-0.0890.0000.0002.4051.707-0.4243.405-0.1051.462-0.668-0.4030.0000.0000.0001.5770.6400.347-0.0570.401-0.222-0.0630.0000.0000.0000.000-1.448-1.416-0.281-0.282-0.0460.2000.0000.0000.0000.0000.0001.2320.1620.1

32、960.535-0.1510.0000.0000.0000.0000.0000.000-0.775-0.3460.4310.1230.0000.0000.0000.0000.0000.0000.0001.296-0.4290.2740.0000.0000.0000.0000.0000.0000.0000.000-0.671-0.4840.0000.0000.0000.0000.0000.0000.0000.0000.0000.072拟上三角a,qr之后的rq:1.1636.54017.170-15.094-21.671-60.426-33.998-11.352-18.105-10.0161.8

33、366.2837.172-2.228-2.835-10.459-6.027-1.274-2.186-1.4470.000-2.119-13.27417.35322.87665.26436.38313.48020.77611.5640.0000.000-0.8472.5182.5254.7362.9081.6552.2051.2640.0000.0000.000-1.432-4.674-7.101-3.445-1.240-1.658-0.6990.0000.0000.0000.0000.6561.0430.1130.5160.231-0.2460.0000.0000.0000.0000.0000

34、.4700.2710.6431.4220.7700.0000.0000.0000.0000.0000.0001.2882.8882.3881.8190.0000.0000.0000.0000.0000.0000.000-0.3630.181-0.1660.0000.0000.0000.0000.0000.0000.0000.000-0.0520.0504. 特征值和特向量1) 12位有效数字e型特征值:实部:3.38303961744e+000-2.32349621021e+000-2.32349621021e+000-1.48403982226e+000-9.80530956290e-001

35、-9.80530956290e-0011.57754855711e+0009.35588907819e-0015.65048899350e-0026.36062787575e-001虚部:0.00000000000e+000-8.93040517720e-0018.93040517720e-0010.00000000000e+000-1-0011-0010.00000000000e+0000.00000000000e+0000.00000000000e+0000.00000000000e+000特向量:-1.05221573436e-0010

36、.00000000000e+0000.00000000000e+000-5.60118116886e-0010.00000000000e+0000.00000000000e+0006.24962559918e-0028.05651548268e-002-2.09017518582e-0011.07037468397e-001-2-0010.00000000000e+0000.00000000000e+0007.79341508753e-0010.00000000000e+0000.00000000000e+000-1.12090045149e-0024.6111346

37、8803e-002-2.00063796685e-0017.12345583256e-002-4.73017877776e-0010.00000000000e+0000.00000000000e+0001.33780114833e-0020.00000000000e+0000.00000000000e+000-2.49666705179e-001-1.50243791979e-0023.89176061817e-0013.90237917138e-001-2.60887478870e-0010.00000000000e+0000.00000000000e+000-2.77409287770e-

38、0010.00000000000e+0000.00000000000e+000-1.31364486150e-001-4.81208346183e-002-2.77939118707e-002-4.46655513756e-002-3.05805625140e-0010.00000000000e+0000.00000000000e+0003.00557587803e-0030.00000000000e+0000.00000000000e+000-3.83541256120e-001-3.53633892069e-001-3.93236547906e-001-7.19034744275e-001

39、-2.58379783221e-0010.00000000000e+0000.00000000000e+000-2.53483409185e-0030.00000000000e+0000.00000000000e+0008-0012.08919077811e-001-1.24703810952e-0011.75815688440e-0018.73379363951e-0020.00000000000e+0000.00000000000e+000-2.06284849136e-0020.00000000000e+0000.00000000000e+000-1.24560

40、352068e-001-1.55745966395e-0016.44810939558e-001-2.26537961544e-0014.05454033853e-0010.00000000000e+0000.00000000000e+000-1.10134829109e-0020.00000000000e+0000.00000000000e+000-6.83561054714e-0028.19670427271e-001-3.02779853108e-0013.76886150502e-0015.09013113720e-0010.00000000000e+0000.00000000000e

41、+000-1.22486166509e-0020.00000000000e+0000.00000000000e+0002.70587401777e-001-3.50982512819e-001-2.91095263314e-0012.95625408505e-0012.40925044562e-0010.00000000000e+0000.00000000000e+0003.23620929756e-0020.00000000000e+0000.00000000000e+0001.00519108146e-0012.88513852782e-0024.09436555812e-0022.255

42、77972559e-0022) 3位小数特征值(上一行为实部,下一行为虚部):3.383-2.323-2.323-1.484-0.981-0.9811.5780.9360.0570.6360.000-0.8930.8930.000-0.1140.1140.0000.0000.0000.000特向量:-0.1050.0000.000-0.5600.0000.0000.0620.081-0.2090.107-0.2180.0000.0000.7790.0000.000-0.0110.046-0.2000.071-0.4730.0000.0000.0130.0000.000-0.250-0.0150

43、.3890.390-0.2610.0000.000-0.2770.0000.000-0.131-0.048-0.028-0.045-0.3060.0000.0000.0030.0000.000-0.384-0.354-0.393-0.719-0.2580.0000.000-0.0030.0000.0000.8160.209-0.1250.1760.0870.0000.000-0.0210.0000.000-0.125-0.1560.645-0.2270.4050.0000.000-0.0110.0000.000-0.0680.820-0.3030.3770.5090.0000.000-0.01

44、20.0000.0000.271-0.351-0.2910.2960.2410.0000.0000.0320.0000.0000.1010.0290.0410.0235. 源程序1) 主函数#include#include#define size 10#define deta 0.0001#define maxstep 1000 /*注意这里的最大步数指m qr 分解并且qaq 的一次过程,有效的控制运算时间#define a(a,b) *(double *)a+(a)*(size)+b) /a 的宏定义,以方便操作二维数组#define a_reg(a,b) *(double *)a_reg

45、+(a)*(size)+b) /a 的宏定义,以方便操作二维数组#define m(a,b) *(double *)m+(a)*(size)+b) /a 的宏定义,以方便操作二维数组#define l(a,b) *(double *)l+(a)*(size)+b) /l u 的宏定义,以方便操作二维数组#define u(a,b) *(double *)u+(a)*(size)+b)#define v(a,b) *(double *)v+(a)*(size)+b) /存储特向量/#define u(a,b) *(double *)u+(a)*(3)+b)int main()double asi

46、zesize=0;double a_regsizesize=0;double lsizesize=0;double usizesize=0;double msizesize=0;double vsizesize=0;double realsize=0; /特征值的实部虚部double imagsize=0;double real_temp=0;double imag_temp=0;double sum_temp=0;double s,t;file *fd;int ii,jj,kk,m,counter=0;kk=0;s=0;t=0;m=0;counter=0; /计数器for(ii=0;iisi

47、ze;ii+) for(jj=0;jjsize;jj+) if(ii=jj)a(ii,jj)=1.5*cos(ii+1.2*jj+2.2);elsea(ii,jj)=sin(0.5*ii+0.2*jj+0.7); for(ii=0;iisize;ii+)for(jj=0;jjsize;jj+)a_reg(ii,jj)=a(ii,jj);m(ii,jj)=a(ii,jj);liketriangle(double *)a); /拟上三角化fd = fopen(tmptmp.txt, w);fprintf(fd,拟上三角的a:n);for(ii=0;iisize;ii+)for(jj=0;jjsiz

48、e;jj+)fprintf(fd,%.3f,a(ii,jj);fprintf(fd,n);fprintf(fd,n);for(ii=0;iisize;ii+)for(jj=0;jjsize;jj+)/a_reg(ii,jj)=a(ii,jj);m(ii,jj)=a(ii,jj);qr_only(double *)m);for(ii=0;iisize;ii+)for(jj=0;jj0)&(counter2if(a(m-1),(m-2)=0)realm-1=a(m-1),(m-1);m=m-1;/continue;else if(a(m-1),(m-2)!=0)&(a(m-2),(m-3)=0)i

49、f(eig2dim(double *)a, m,&real_temp,&imag_temp)=1)/realm-1=real_temp+imag_temp;realm-2=real_temp-imag_temp;elserealm-1=real_temp;realm-2=real_temp;imagm-1=imag_temp;imagm-2=-imag_temp;m=m-2;/continue;elsecounter+;s=a(size-1,size-1)+a(size-2,size-2); /根据右下角元素求出s tt=a(size-1,size-1)*a(size-2,size-2)-a(size-1,size-2)*a(size-2,size-1);m_out(double *)a,(double *)m,size,s,t,m); /求出mqr(double *)m,(double *)a,m);/qr分解m并且得到新的a/ 生成特向量for(kk=0;kksize;kk+)if(imagkkdeta)continue;else;for(ii=0;iisize;ii+)a_reg(ii,ii)=a_reg(ii,ii)-realkk;lu(d

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论