1、if abs(s(m)m=i;c=A(m,j);A(m,j)=A(k,j);A(k,j)=c;for j=k:for r=1:sum=sum+A(k,r)*A(r,j);u(k,j)=A(k,j)-sum;A(k,j)=u(k,j);for i=1:l(i,i)=1;for i=(k+1):sum=sum+A(i,r)*u(r,k);l(i,k)=(A(i,k)-sum)/u(k,k); A(i,k)=l(i,k);求A 的列主元素三角分解:A=1 1 1 1 1;1 2 3 4 5;1 3 6 10 15;1 4 10 20 35;1 5 15 35 70;L,U=myfun(A)结果:L
2、=1.00000.50000.75000.2500-1.0000U =1.00001.00001.00001.00001.00004.000014.000034.000069.0000-2.0000-8.0000-20.5000-0.5000-2.3750-0.2500(2)求矩阵的逆矩阵 A-1: inv(A)结果为:ans =5-1010-5130-3519-446-27617(3)检验结果:E=diag(1 1 1 1 1)AE2:程序:function d=myfun(a,b,c,d,n) for i=2:l(i)=a(i)/b(i-1); a(i)=l(i);u(i)=b(i)-c(
3、i-1)*a(i); b(i)=u(i);y(i)=d(i)-a(i)*d(i-1); d(i)=y(i);end x(n)=d(n)/b(n);d(n)=x(n);for i=(n-1):-1:x(i)=(d(i)-c(i)*d(i+1)/b(i); d(i)=x(i);求各段电流量程序:for i=2:8a(i)=-2;b=2 5 5 5 5 5 5 5;c=-2 -2 -2 -2 -2 -2 -2; V=220;R=27;d=V/R 0 0 0 0 0 0 0; n=8;I=myfun(a,b,c,d,n)运行程序得:I =8.14784.07372.03651.01750.50730.
4、25060.11940.04773:(1)求矩阵A 和向量 b 的 matlab 程序:function A b=myfun(n) for i=1:X(i)=1+0.1*i;A(i,j)=X(i)(j-1);n b(i)=sum(A(i,:); end求 n=5 时 A1,b1 及 A1 的 2-条件数程序运行结果如下: n=5;A1,b1=myfun(n) A1 =1.10001.21001.33101.46411.20001.44001.72802.07361.30001.69002.19702.85611.40001.96002.74403.84161.50002.25003.37505
5、.0625b1 =6.10517.44169.043110.945613.1875cond2=cond(A1,2) cond2 =5.3615e+005求 n=10 时 A2,b2 及 A2 的 2-条件数程序运行结果如下: n=10;1.61051.77161.94872.14362.35792.48832.98603.58324.29985.15983.71294.82686.27498.157310.60455.37827.529510.541414.757920.66107.593811.390617.085925.628938.44341.60002.56004.09606.5536
6、10.485816.777226.843542.949768.71951.70002.89004.91308.352114.198624.137641.033969.7576118.58791.80003.24005.832010.497618.895734.012261.2220110.1996198.35931.90003.61006.859013.032124.761047.045989.3872169.8356322.68772.00008.000016.000032.000064.0000128.0000256.0000512.0000b2 =1.0e+003 *0.01590.02600.04260.06980.11330.18160.28660.44510.68011.0230A2,b2=myfun(n) A2 =cond2=cond(A2,2) cond2 =8.6823e+011求 n=20 时 A3,b3 及 A3 的 2-条件数程序运行结果如下: n=20;A3,b3=myfun(n) A3 =1.0e+009 *Columns 1 through 100.00000.000
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1