实验一练习1使用whowhos查看变量内容a=2.5a=2.5000b=[12;34]b=1234c='a'c=ad=sin(a*b*pi/180)d=0.04360.08720.13050.1736e=a+ce=99.5000whoYourvariablesare:abcdewhosNameSizeBytesClassAttributesa1x18doubleb2x232doublec1x12chard2x232doublee1x18double2绘制柱状图x=[12345];y=sin(x)y=0.84150.90930.1411-0.7568-0.9589plot(y,'DisplayName','y','YDataSource','y');figure(gcf)hist(y);figure(gcf);x=[12345];y=sin(x)y=0.84150.90930.1411-0.7568-0.9589hist(y);figure(gcf);自我练习x=[13579]y=2*xplot(y)实验二练习1使用全下标方式获取a矩阵中第二列子矩阵块a=[123;456;789]b=a(:,2)a=b=1232456578982使用logspace函数创建0-4*pi行向量有二十个元素,查看元素分布情况。c=logspace(0,4*pi,20)c=1.0e+12*Columns1through70.00000.00000.00000.00000.00000.00000.0000Columns8through140.00000.00000.00000.00000.00000.00010.0004Columns15through200.00180.00830.03820.17520.80353.68443验证关系式A=[1/300;01/40;001/7]B=inv(A)*inv(inv(A)-eye(3))*6*AZUO=A\(B*A)YOU=6*A+B*AA=0.33330000.25000000.1429B=3.00000002.00000001.0000ZUO=3.00000002.00000001.0000YOU=3.00000002.00000001.00004將矩正的乘除运算改为数组的点除运算A=[123;456;789]B=[111;222;333]A*Bc1=A.*Bd1=A/Bd2=A./BA=B=123111456222789333ans=c1=14141412332323281012505050212427Warning:Matrixissingulartoworkingprecision.InmatlabP322at5d1=NaNNaNNaNNaNNaNNaNNaNNaNNad2=1.00002.00003.00002.00002.50003.00002.33332.66673.00005使用数组编辑窗口查看变量a,b,c6使用setfield命令进行上述修改student(1)=struct('name','Rose','Id','20030102','score',[95,93,84,72,88])student=name:'Rose'Id:'20030102'score:[9593847288]student=setfield(student,{1},'score','[95,73,84,72,88]')student=name:'Rose'Id:'20030102'score:'[95,73,84,72,88]'7使用图形和文字显示average的各元胞内容student(1)=struct('name','John','Td','20030115','scores',[85,96,74,82,68])student=name:'John'Td:'20030115'scores:[8596748268]student(2)=struct('name','Rose','Td','20030102','scores',[95,93,84,72,88])student=1x2structarraywithfields:nameTdscoresstudent(3)=struct('name','Billy','Td','20030117','scores',[72,83,78,80,83])student=1x3structarraywithfields:nameTdscoresall_scores=cat(1,student.scores)all_scores=859674826895938472887283788083average_scores=mean(all_scores)average_scores=84.000090.666778.666778.000079.6667方法一average={'平均成绩',average_scores}average='平均成绩'[1x5double]方法二average(1)={'平均成绩'}average='平均成绩'average(2)={average_scores}average='平均成绩'[1x5double]方法三average{1}='平均成绩';average{2}=average_scoresaverage='平均成绩'[1x5double]自我练习1使用LU和QR分解线性方程A=[2-302;1521;3-11-1;4122]B=[8;2;7;12]X=A\B[L,U]=lu(A)X=U\(L\B)[Q,R]=qr(A)X=R\(Q\B)A=B=2-3028152123-11-17412212X=L=3.00000.5000-0.73681.000000.00000.25001.000000-1.00000.7500-0.36840.50001.00001.00001.0000000U=X=4.00001.00002.00002.00003.000004.75001.50000.50000.0000000.10531.3684-1.0000000-3.00001.0000Q=-0.36510.50000.67080.4082-0.1826-0.83330.5217-0.0000-0.54770.16670.0745-0.8165-0.7303-0.1667-0.52170.4082R=X=-5.47720-2.3735-1.82573.00000-6.0000-1.8333-0.3333-0.0000000.07450.7454-1.00000002.44951.0000Untitled3A=B=2-3028152123-11-17412212X=L=3.00000.5000-0.73681.000000.00000.25001.000000-1.00000.7500-0.36840.50001.00001.00001.0000000U=X=4.00001.00002.00002.00003.000004.75001.50000.50000.0000000.10531.3684-1.0000000-3.00001.0000Q=R=-0.36510.50000.67080.4082-5.47720-2.3735-1.8257-0.1826-0.83330.5217-0.00000-6.0000-1.8333-0.3333-0.54770.16670.0745-0.81650000.07450.7454-0.7303-0.1667-0.52170.40820002.4495X=3.0000-0.0000-1.00001.00002按表达式得出三阶,五阶拟合表达式和曲线x=0:100;y=[642-710]y0=polyval(y,x);p3=polyfit(x,y0,3);p5=polyfit(x,y0,5);y3=polyval(p3,x);y5=polyval(p5,x);plot(x,y0,'o')holdonplot(x,y3,'r')plot(x,y5,'g')实验三练习1用y替换x,查看结果及其数据类型f=sym('sin(x)')f=sin(x)x=0:10;y=subs(f,x)y=Columns1through700.84150.90930.1411-0.7568-0.9589-0.2794Columns8through110.65700.98940.4121-0.5440z=subs(f,y)z=Columns1through700.74560.78910.1407-0.6866-0.8186-0.2758Columns8through110.61070.83570.4006-0.51762将y1用sym函数转换为符号对象,并用dfer四种格式表示f=sym('sin(x)')x=0:10;y=subs(f,x)whosz=subs(f,y)whosy1=sym('sin(5)')y=double(y1)d=sym(y,'d')f=sym(y,'f')e=sym(y,'e')r=sym(y,'r')f=sin(x)y=Columns1through700.84150.90930.1411-0.7568-0.9589-0.2794Columns8through110.65700.98940.4121-0.5440NameSizeBytesClassAttributesA4x4128doubleB4x132doubleL4x4128doubleQ4x4128doubleR4x4128doubleU4x4128doubleX4x132doublef1x1112symf11x1112symf21x1112symf31x1112symx1x1188doubley1x1188doublez=Columns1through700.74560.78910.1407-0.6866-0.8186-0.2758Columns8through110.61070.83570.4006-0.5176NameSizeBytesClassAttributesA4x4128doubleB4x132doubleL4x4128doubleQ4x4128doubleR4x4128doubleU4x4128doubleX4x132doublef1x1112symf11x1112symf21x1112symf31x1112symx1x1188doubley1x1188doublez1x1188doubley1=sin(5)y=-0.9589d=-0.95892427466313845396683746002964f=-8637222012098867/9007199254740992e=-8637222012098867/9007199254740992r=-8637222012098867/90071992547409923使用expandcollectsimplify函数进行,,,,f=sym('x^2+3*x+2')f1=simplify(f)f2=expand(f1)f3=collect(f2)f=x^2+3*x+2f1=(x+1)*(x+2)f2=x^2+3*x+2f3=x^2+3*x+24将f转换为以t为符号变量的符号表达式,f=poly2sym([132])f=x^2+3*x+2h=poly2sym([132],sym('t'))h=t^2+3*t+25对符号举证A进行求特征值,对角阵等运算A=sym('[x^2;2*xcos(2*t)]')A=[x,x^2][2*x,cos(2*t)]diag(A)ans=xcos(2*t)6对符号举证A求极限和积分int(A)ans=[x^2/2,x^3/3][