您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 实验一-MATLAB语言基础实验
实验一MATLAB语言基础实验一、matlab的基本操作(1)键入常数矩阵输入命令a=[123]a=123a=[1;2;3]a=123b=[125]b=125b=[125];b=[125];c=a*bc=12524103615c=a*b'???Errorusing==mtimesInnermatrixdimensionsmustagree.a=[123;456;780]a=412344565780a^2ans=630361566681427395469分析实验结果可以知道a=[123]表示行矩阵a=[1;2;3]表示列矩阵b=[125]显示行矩阵b=[125];不显示行矩阵但录入a’表示a矩阵的转置c=a*b矩阵的乘法(需满足矩阵乘法的条件)“;”表示换行a^2表示a矩阵的平方a^0.5表示a开根号(2)作循环命令程序makesum=0;fori=1:1:100makesum=makesum+i;endmakesummakesum=5050从1加到100,每步的间隔为1(1+2+3+……+100)(3)分别执行下列命令a=[123;456;780]a=123456780poly(a)poly求多项式的系数(由已知根求多项式的系数)ans=1.0000-6.0000-72.0000-27.0000rank(a)rank求矩阵的秩ans=3det(a)det矩阵的行列式ans=27.0000trace(a)trace矩阵的迹ans=6inv(a)inv求矩阵的逆ans=-1.77780.8889-0.11111.5556-0.77780.2222-0.11110.2222-0.1111eig(a)eig求矩阵的特征值ans=12.1229-0.3884-5.73457.1.2MATLAB语言的数值运算1.基本矩阵运算(1)创建数值矩阵a=[123;456;789]a=123456789a(3,2)显示a矩阵的第三行第二列ans=8a(:,1)显示a矩阵的第一列ans=147t=0:10;u=0:0.1:10;tt=012345678910uu=Columns1through700.10000.20000.30000.40000.50000.6000Columns8through140.70000.80000.90001.00001.10001.20001.3000Columns15through211.40001.50001.60001.70001.80001.90002.0000Columns22through282.10002.20002.30002.40002.50002.60002.7000Columns29through352.80002.90003.00003.10003.20003.30003.4000Columns36through423.50003.60003.70003.80003.90004.00004.1000Columns43through494.20004.30004.40004.50004.60004.70004.8000Columns50through564.90005.00005.10005.20005.30005.40005.5000Columns57through635.60005.70005.80005.90006.00006.10006.2000Columns64through706.30006.40006.50006.60006.70006.80006.9000Columns71through777.00007.10007.20007.30007.40007.50007.6000Columns78through847.70007.80007.90008.00008.10008.20008.3000Columns85through918.40008.50008.60008.70008.80008.90009.0000Columns92through989.10009.20009.30009.40009.50009.60009.7000Columns99through101以0.1为间隔从0到10a(:,3)=[2;3;4];aa=122453784b=[11+2i;3+4i3];将第三列改为234bb=1.00001.0000+2.0000i3.0000+4.0000i3.0000产生复数矩阵a=ones(3,3);b=zeros(2,2);c=eye(4);magic(4);aa=111111111产生一个全为1的矩阵bb=0000将矩阵置0cc=1000010000100001置成单位矩阵magic(4)ans=16231351110897612414151产生一个矩阵他的行和列对角线和相同a=[010;001;-6-11-6];b=[12;34;56];c=[110;011];v1=c*av1=011-6-11-5v2=a*bv2=3456-69-92v3=c*a*bv3=810-64-86v4=b*cv4=1323745116v5=c*bv5=46810a^2ans=001-6-11-6366025a^(1/2)ans=0.0000+0.4894i-0.0000-0.5588i-0.0000-0.0482i0.0000+0.2891i0.0000+1.0195i-0.0000-0.2696i0.0000+1.6179i0.0000+3.2553i0.0000+2.6374iai=a+b*cai=142375-100a1=a+b*ca1=142375-100a2=c*b-a(1:2,1:2)a2=45810a(1:2)取第一列的前两个数a3=a(1:2,2:3)+c*ba3=56811ar=a/b???Errorusing==mrdivideMatrixdimensionsmustagree.ar=c/aar=-0.8333-1.0000-0.16671.00001.00000al=a\bal=-5.6667-8.66671.00002.00003.00004.0000a'ans=00-610-1101-6矩阵的转置inv(a)ans=-1.8333-1.0000-0.16671.00000001.00000diag(a)ans=00-6求矩阵a的主对角线并以列的形式表现出来tril(a)ans=000000-6-11-6产生X矩阵的下三角矩阵inv(a)ans=-1.8333-1.0000-0.16671.00000001.00000poly(a)ans=1.00006.000011.00006.0000rank(a)ans=3det(a)ans=-6trace(a)ans=-6eig(a)ans=-1.0000-2.0000-3.0000(2)MATLAB语言的点运算1练习点乘与点除a1=[12;34];a2=0.2*a1;[a1a2]ans=1.00002.00000.20000.40003.00004.00000.60000.8000把a1,a2按矩阵排列[a1.*a2a1./a2]ans=0.20000.80005.00005.00001.80003.20005.00005.0000点乘是矩阵中每个数象乘,点除是矩阵中每个数相除2)由点运算完成标量函数运算与作图t=0:2*pi/180:2*pi从0数到2π以2π/180为间隔t=Columns1through600.03490.06980.10470.13960.1745Columns7through120.20940.24430.27930.31420.34910.3840Columns13through180.41890.45380.48870.52360.55850.5934Columns19through240.62830.66320.69810.73300.76790.8029Columns25through300.83780.87270.90760.94250.97741.0123Columns31through361.04721.08211.11701.15191.18681.2217Columns37through421.25661.29151.32651.36141.39631.4312Columns43through481.46611.50101.53591.57081.60571.6406Columns49through541.67551.71041.74531.78021.81511.8500Columns55through601.88501.91991.95481.98972.02462.0595Columns61through662.09442.12932.16422.19912.23402.2689Columns67through722.30382.33872.37362.40862.44352.4784Columns73through782.51332.54822.58312.61802.65292.6878Columns79through842.72272.75762.79252.82742.86232.8972Columns85through902.93222.96713.00203.03693.07183.1067Columns91through963.14163.17653.21143.24633.28123.3161Columns97through1023.35103.38593.42083.45583.49073.5256Columns103through1083.56053.59543.63033.66523.70013.7350Columns109through1143.76993.80483.83973.87463.90953.9444Columns115through1203.97944.01434.04924.08414.11904.1539Columns121through1264.18884.22374.25864.29354.32844.3633Columns127through1324.39824.43314.46804.50294.53794.5728Columns133through1384.60774.64264.67754.71244.74734.7822Columns139through1444.81714.85204.88694.92184.95674.9916Columns145through1505.02655.06155.09645.13135.16625.2011Columns151through1565.23605.27095.30585.34075.37565.4105Columns157through1625.44545.48035.51525.55015.58515.6200Columns163through1685.65495.68985.72475.75965.79455.8294Columns169through1745.86435.89925.93415.96906.00396.0388Columns175through1806.07376.10876.14366.17856.21346.2483Column1816.2832y1=sin(t)y1=Columns1through600.03490.06980.10450.13920.1736Columns7through120.20790.24190.27560.30900.34
本文标题:实验一-MATLAB语言基础实验
链接地址:https://www.777doc.com/doc-5700565 .html