1、最新MATLAB程序设计与应用第二版刘卫国实验部分MATLAB程序设计与应用第二版刘卫国实验部分 实验一1.(1)z1=2*sin(85*pi/180)/(1+exp(2)(2) x=2,1+2i;-0.45,5; z2=(1/2)*log(x+sqrt(1+x*x) (3) a=-3.0:0.1:3.0; z3=(exp(0.3*a)-exp(-0.3*a)/2).*sin(a+0.3)+log(0.3+a)/2) (4)t=0:0.5:2.5; z4=(t.*t).*(t=0&t=1&t=2&t A=12,34,-4;34,7,87;3,65,7; B=1,3,-1;2,0,3;3,-2,
2、7; A+6*B (2) A*B (3) A3 (4) A/B (5) A,B3.(1) A=1,2,3,4,5;6,7,8,9,10;11,12,13,14,15;16,17,18,19,20;21,22,23,24,25; B=3,0,16;17,-6,9;0,23,-4;9,7,0;4,13,11; C=A*B (2) D=C(3:end,2:end) (3)Name value classA doubleB doubleC doubleD 520 397;705 557; double4.(1) X=100:999; length(find(rem(X,21) (2) y=ahHGJj
3、skjJjsdsaSa; M=y(find(y=a)实验二实验三1 x=input(请输入x的值)if x=0&x=90&x=80&x=70&x=60&x=0&x3Num=input(输入员工的工号:);Time=input(该工号员工的工作时数:);salary=input(该员工底薪:);if Time=120 salary=salary*(1+0.15);elseif Time60&Time=3) break; endendn-14.程序:f(1)=1;max=0;f(2)=0;min=0;f(3)=1;c=0;zhengshu=0;fushu=0;zero=0;for n=4:100f
4、(n)=f(n-1)-2*f(n-2)+f(n-3);endfor m=1:100 if(f(m)max) max=f(m); end if(f(m)0) zhengshu=zhengshu+1;endif(f(m)0) zhengshu=zhengshu+1;endif(f(m)0) fushu=fushu+1;endif(f(m)=0) zero=zero+1;enddisp(最大值)maxdisp(最小值)mindisp(和)cdisp(正数的个数)zhengshudisp(负数的个数)fushudisp(零的个数)zero实验五1,函数文件:文件名:Yunsuan程序:function
5、z,d,s,c=yunsuan(a,b)z=exp(a+b*i);d=log(a+b*i);s=sin(a+b*i);c=cos(a+b*i);disp(复数,num2str(a),+,num2str(b),i的指数为:,num2str(z),,对数为:,num2str(d),,正弦为:,num2str(s),,余弦为:,num2str(c)函数调用:程序:clearx=input(请输入复数实部的值);y=input(请输入复数虚部的值);x,y=yunsuan(x,y);2函数文件:文件名:zhu程序:functionp,q,w=zhu(p,q,w)A=p*cos(w),-p,-sin(w
6、),0;p*sin(w),0,cos(w),0;0,q,-sin(w),0;0,0,-cos(w),1;B=0;9.8*p;0;9.8*q;X=AB函数调用:程序:clearm1=input(m1=);m2=input(m2=);th=input(theta=);theta=pi*th/180;m1,m2,theta=zhu(m1,m2,theta);4函数文件:文件名:hanshu程序:functiony=hanshu(x)y=1/(x-2).2-0.1)+1./(x-3).4+0.01);实验六1、程序:、x=0:0.02*pi:2*pi;y=(0.5+3*sin(x)./(1+x.*x)
7、.*cos(x)plot(x,y)2、(1)程序:x=(0:0.02*pi:2*pi);y1=x.*x;y2=cos(2*x);y3=y1.*y2;plot(x,y1,y-),hold onplot(x,y2,c-),hold onplot(x,y3,k-),hold off(2)程序:x=(0:0.02*pi:2*pi);y1=x.*x;y2=cos(2*x);y3=y1.*y2;subplot(2,2,1)stairs(x,y1);plot(x,y1,r-),hold onsubplot(2,2,2) stairs(x,y2);plot(x,y2,b-),hold onsubplot(2,
8、2,3)stairs(x,y3);plot(x,y3,k-),hold off(3)(1)绘制条形图程序:x=(0:0.2*pi:2*pi);y1=x.*x;y2=cos(2*x);y3=y1.*y2;subplot(2,2,1)stairs(x,y1);bar(x,y1)subplot(2,2,2)stairs(x,y2);bar(x,y1)subplot(2,2,3)stairs(x,y3);bar(x,y3)(2)绘制梯形图程序:x=(0:0.05*pi:2*pi);y1=x.*x;y2=cos(2*x);y3=y1.*y2;subplot(2,2,1)stairs(x,y1);subp
9、lot(2,2,2)stairs(x,y2);subplot(2,2,3)stairs(x,y3);(4)杆图:程序:x=(0:0.05*pi:2*pi);y1=x.*x;y2=cos(2*x);y3=y1.*y2;subplot(2,2,1)stem(x,y1);subplot(2,2,2)stem(x,y2);subplot(2,2,3)stem(x,y3);(5)填充图 程序: x=(0:0.05*pi:2*pi);y1=x.*x;y2=cos(2*x);y3=y1.*y2;subplot(2,2,1)fill(x,y1,r);subplot(2,2,2)fill(x,y2,b);subplot(2,2,3)fill(x,y3,g);3、:程序:x=linspace(-5,5,1000);y=;for x0=x if x00.5)/30000 %满足条件的百分比2、程序:p=100*rand(100,5);MAXOBJECT,
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1