Matlab实训8-线性代数问题的求解

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

实训九线性代数问题求解•矩阵•线性方程组的直接解法•线性方程组的迭代法•线性方程组的符号解法•稀疏矩阵技术•特征值与特征向量9.1矩阵9.1.1特殊矩阵的输入•数值矩阵的输入–零矩阵、幺矩阵及单位矩阵生成nn方阵:A=zeros(n),B=ones(n),C=eye(n)生成mn矩阵:A=zeros(m,n),B=ones(m,n),C=eye(m,n)生成和矩阵B同样位数的矩阵:A=zeros(size(B))–随机元素矩阵若矩阵随机元素满足[0,1]区间上的均匀分布生成nm阶标准均匀分布为随机数矩阵:A=rand(n,m)生成nn阶标准均匀分布为随机数方阵:A=rand(n)–对角元素矩阵已知向量生成对角矩阵:A=diag(V)已知矩阵提取对角元素列向量:V=diag(A)生成主对角线上第k条对角线为V的矩阵:A=diag(V,k)•例:diag()函数的不同调用格式C=[123];V=diag(C)%生成对角矩阵V=100020003V1=diag(V)'%将列向量通过转置变换成行向量V1=123C=[123];V=diag(C,2)%主对角线上第k条对角线为C的矩阵V=0010000020000030000000000生成三对角矩阵:V=diag([1234])+diag([234],1)+diag([543],-1)V=1200523004340034–Hilbert矩阵及逆Hilbert矩阵生成n阶的Hilbert矩阵:A=hilb(n)求取逆Hilbert矩阵:B=invhilb(n)–Hankel(汉克)矩阵其中:第一列的各个元素定义为C向量,最后一行各个元素定义为R。H为对称阵。H1=hankel(C)由Hankel矩阵反对角线上元素相等得出一下三角阵均为零的Hankel矩阵–Vandermonde(范德蒙)矩阵–伴随矩阵其中:P(s)为首项系数为1的多项式。•符号矩阵的输入数值矩阵A转换成符号矩阵:B=sym(A)例:A=hilb(3)A=1.00000.50000.33330.50000.33330.25000.33330.25000.2000B=sym(A)B=[1,1/2,1/3][1/2,1/3,1/4][1/3,1/4,1/5]9.1.2矩阵基本概念与性质•行列式格式:d=det(A)例:求行列式A=[162313;511108;97612;414151];det(A)ans=0•例:tic,A=sym(hilb(20));det(A),tocans=1/2377454716768534509091644243427616440175419837753486493033185331234419759310644585187585766816573773440565759867265558971765638419710793303386582324149811241023554489166154717809635257797836800000000000000000000000000000000000elapsed_time=2.3140高阶的Hilbert矩阵是接近奇异的矩阵。•矩阵的迹格式:t=trace(A)•矩阵的秩格式:r=rank(A)%用默认的精度求数值秩r=rank(A,)%给定精度下求数值秩矩阵的秩也表示该矩阵中行列式不等于0的子式的最大阶次。可证行秩和列秩(线性无关的)应相等。•例A=[162313;511108;97612;414151];rank(A)ans=3该矩阵的秩为3,小于矩阵的阶次,故为非满秩矩阵。•例H=hilb(20);rank(H)%数值方法ans=13H=sym(hilb(20));rank(H)%解析方法,原矩阵为非奇异矩阵ans=20•矩阵范数•矩阵的范数定义:格式:N=norm(A)%求解默认的2范数N=norm(A,选项)%选项可为1,2,inf等•例:求一向量、矩阵的范数a=[162313];[norm(a),norm(a,2),norm(a,1),norm(a,Inf)]ans=2.092844953645635e+0012.092844953645635e+0013.400000000000000e+0011.600000000000000e+001A=[162313;511108;97612;414151];[norm(A),norm(A,2),norm(A,1),norm(A,Inf)]ans=34343434符号运算工具箱未提供norm()函数,需先用double()函数转换成双精度数值矩阵,再调用norm()函数。•特征多项式格式:C=poly(A)例:A=[162313;511108;97612;414151];poly(A)%直接求取ans=1.000000000000000e+000-3.399999999999999e+001-7.999999999999986e+0012.719999999999999e+003-2.819840539024018e-012A=sym(A);poly(A)%运用符号工具箱ans=x^4-34*x^3-80*x^2+2720*x•矩阵多项式的求解•符号多项式与数值多项式的转换格式:f=poly2sym(P)或f=poly2sym(P,x)格式:P=sym2poly(f)•例:P=[123456];%先由系数按降幂顺序排列表示多项式f=poly2sym(P,'v')%以v为算子表示多项式f=v^5+2*v^4+3*v^3+4*v^2+5*v+6P=sym2poly(f)P=123456•矩阵的逆矩阵格式:C=inv(A)例:formatlong;H=hilb(4);H1=inv(H)H1=1.0e+003*0.01600000000000-0.119999999999990.23999999999998-0.13999999999999-0.119999999999991.19999999999990-2.699999999999761.679999999999840.23999999999998-2.699999999999766.47999999999940-4.19999999999961-0.139999999999991.67999999999984-4.199999999999612.79999999999974检验:H*H1ans=1.000000000000010.00000000000023-0.000000000000450.000000000000230.000000000000011.00000000000011-0.000000000000110.000000000000110.0000000000000101.0000000000001100.000000000000000.00000000000011-0.000000000000111.00000000000011计算误差范数:norm(H*inv(H)-eye(size(H)))ans=6.235798190375727e-013H2=invhilb(4);norm(H*H2-eye(size(H)))ans=5.684341886080802e-014H=hilb(10);H1=inv(H);norm(H*H1-eye(size(H)))ans=0.00264500826202H2=invhilb(10);norm(H*H2-eye(size(H)))ans=1.612897415528547e-005H=hilb(13);H1=inv(H);norm(H*H1-eye(size(H)))Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=2.339949e-018.ans=53.23696008570294H2=invhilb(13);norm(H*H2-eye(size(H)))ans=11.37062973181391对接近于奇异矩阵,高阶一般不建议用inv(),可用符号工具箱。H=sym(hilb(7));inv(H)ans=[49,-1176,8820,-29400,48510,-38808,12012][-1176,37632,-317520,1128960,-1940400,1596672,-504504][8820,-317520,2857680,-10584000,18711000,-15717240,5045040][-29400,1128960,-10584000,40320000,-72765000,62092800,-20180160][48510,-1940400,18711000,-72765000,133402500,-115259760,37837800][-38808,1596672,-15717240,62092800,-115259760,100590336,-33297264][12012,-504504,5045040,-20180160,37837800,-33297264,11099088]H=sym(hilb(30));norm(double(H*inv(H)-eye(size(H))))ans=0•例:奇异阵求逆A=[162313;511108;97612;414151];formatlong;B=inv(A)Warning:Matrixisclosetosingularorbadlyscaled.Resultsmaybeinaccurate.RCOND=1.306145e-017.B=1.0e+014*0.938249922368852.81474976710656-2.81474976710656-0.938249922368852.814749767106568.44424930131968-8.44424930131968-2.81474976710656-2.81474976710656-8.444249301319688.444249301319682.81474976710656-0.93824992236885-2.814749767106562.814749767106560.93824992236885norm(A*B-eye(size(A)))%检验ans=1.64081513306419A=sym(A);inv(A)%奇异矩阵不存在一个相应的逆矩阵,用符号工具箱的函数也不行???Errorusing==sym/invError,(ininverse)singularmatrix同样适用于含有变量的矩阵求逆。例:symsa1a2a3a4;C=[a1a2;a3a4];inv(C)ans=[-a4/(-a1*a4+a2*a3),a2/(-a1*a4+a2*a3)][a3/(-a1*a4+a2*a3),-a1/(-a1*a4+a2*a3)]•矩阵的相似变换与正交矩阵其中:A为一方阵,B矩阵非奇异。相似变换后,X矩阵的秩、迹、行列式与特征值等均不发生变化,其值与A矩阵完全一致。对于一类特殊的相似变换满足如下条件,称为正交基矩阵。例:A=[5,9,8,3;0,3,2,4;2,3,5,9;3,4,5,8];Q=orth(A)Q=-0.61970.7738-0.0262-0.1286-0.2548-0.15510.94900.1017-0.5198-0.5298-0.1563-0.6517-0.5300-0.3106-0.27250.7406norm(Q'*Q-eye(4))ans=4.6395e-016norm(Q*Q'-eye(4))ans=4.9270e-01

1 / 94
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功