1、.MATLAB仿真及电子信息应用第二单元1. a=zeros(2)a =0 00 0 a(1,2)=2a =0 20 02. a=1 0 -2 3;b=0 1 2 1; a+bans =1 1 0 4 a.*bans =0 0 -4 3 /-4+3 =-1 dot(a,b)ans =-13. a=randn(4)a =0.8156 1.1908 -1.6041 -0.80510.7119 -1.2025 0.2573 0.52871.2902 -0.0198 -1.0565 0.21930.6686 -0.1567 1.4151 -0.9219 sum(diag(a).ans =-2.3652
2、 reshape(a,2,8)ans =0.8156 1.2902 1.1908 -0.0198 -1.6041 -1.0565 -0.8051 0.21930.7119 0.6686 -1.2025 -0.1567 0.2573 1.4151 0.5287 -0.92194. a=rand(3,5)a =0.9501 0.4860 0.4565 0.4447 0.92180.2311 0.8913 0.0185 0.6154 0.73820.6068 0.7621 0.8214 0.7919 0.1763 a(:,4)=a(:,4)+0.2a =0.9501 0.4860 0.4565 0.
3、6447 0.92180.2311 0.8913 0.0185 0.8154 0.73820.6068 0.7621 0.8214 0.9919 0.1763 lt(a,0.5)ans =0 1 1 0 01 0 1 0 00 0 0 0 15. a=randn(3,2);b=randn(3,2); cat(1,a,b) /按列方向ans =0.7310 0.67710.5779 0.56890.0403 -0.2556-0.3775 -0.2340-0.2959 0.1184-1.4751 0.3148. cat(2,a,b) /按行方向ans =0.7310 0.6771 -0.3775
4、-0.23400.5779 0.5689 -0.2959 0.11840.0403 -0.2556 -1.4751 0.31486. Hello everyoneans =Hello everyone7. str1=MATLAB ;str2 =is strong;str3=str1,str2str3 =MATLAB is strong8.(1)直接法 a=Function Variable;y=f(x) x;6 1:5a = Function Variable y=f(x) x 6 1x5 double(2)函数法 a=cell(3,2);a1,1=Function;a1,2=Variable
5、; a2,1=y=f(x);a2,2=x; a3,1=6;a3,2=1:5; aa = Function Variable y=f(x) x 6 1x5 double9. student1.Name=Mary;student1.Age=Eighteen;student1.Score=502;student1.Class=1;student1student1 = .Name: MaryAge: EighteenScore: 502Class: 1 student2.Name=Mike;student2.Age=Nighteen; student2.Score=498;student2.Class
6、=2; student2student2 = Name: MikeAge: NighteenScore: 498Class: 2 student3.Name=Joe;student3.Age=Eighteen; student3.Score=520;student3.Class=3;student3student3 = Name: JoeAge: EighteenScore: 520Class: 3第三单元3-1clear allclcp=5 4 1 2 1;roots(p) %求根y=polyval(p,5) %求在 5处函数的函数值3-2clear allclcp=2 0 -2 5;x=1
7、 2 4;-1 0 3;5 2 1;f=polyder(p) %多项式求导polyvalm(p,x)3-3clear allclcf=factor(sym(2*x4-5*x3+4*x2-5*x+2)3-4clear all.clcf1=sym(x2+1)(x-2);f2=sym(2*x2+1);f=expand(f1*f2)3-5clear allclcsyms x y;f=log(1+x);g=2*sin(y);compose(f,g)compose(g,f)3-6clear allclcsyms x ;finverse(cos(1+x)3-7(1) (2)clear allclcsyms
8、x y k;f1=(1/2x)+(-1)x/x2);f2=1/(1+k2) 1/(2*k+1)s1=symsum(f1,1,inf)s2=symsum(f2,1,inf)(3) (4) (5) (6) clear allclcsyms x ;f1=(1+2x)(1/x);f2=(x2)*exp(1/x2);f3=log(tan(x)/sin(x);f4=(x/(2*x+1)(x-1);limit(f1,inf)limit(f2,0)limit(f3,x,0,right)limit(f4,inf)(7) (8)clear allclcsyms x y z a b;f1=1/(1+x2);f2=(
9、x2+y2+z2);.int(f1,x,a,b)int(int(int(f2,z,sqrt(x*y),x*y),y,sqrt(x),x),x,0,1)3-8clear allclcsyms x;f=x*exp(x) log(sin(x);1/(1+x2) x(3/2);diff(f,2)3-9(1)clear allclcf=sym(x3-2*x+5);solve(f)(2)clear allclcsyms x1 x2 x3;f1=2*x1-5*x2+3;f2=5*x1-2*x2+18;x1 x2=solve(f1,f2)(3)方法一:clear allclcsyms x1 x2 x3;f1=
10、3*x1+11*x2-2*x3-8;f2=1*x1+1*x2-2*x3+4;f3=x1-x2+x3-3;x1 x2 x3=solve(f1,f2,f3)方法二:clear allclcA=3 11 -2;1 1 -2;1 -1 1;B=8;-4;3;x=AB(4)clear allclcsyms x1 x2 x3;f1=2*x1-x2-exp(-x1);f2=x1-2*x2-exp(-x2);x1 x2=solve(f1,f2)3-10.clear allclcdsolve(D2y+2*Dy+2*y=0,y(0)=0,Dy(0)=1)3-11clear allclcx y=dsolve(Dx=y,Dy=(-1)*x,x(0)=1,y(0)=2)