MATLAB程序设计与应用第二版刘卫国实验部分

  • 格式:doc
  • 大小:62.50 KB
  • 文档页数:10

实验一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.*t-1).*(t>=1&t<2)+(t.*t-2.*t+1).*(t>=2&t<3) 2.(1)>> A=[12,34,-4;34,7,87;3,65,7];>> B=[1,3,-1;2,0,3;3,-2,7];>> A+6*B(2)>> A*B(3)>> A^3(4)>> A/B(5)>> [A,B]3.(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 <5×5double> doubleB <5×3double> doubleC <5×3double> doubleD [520 397;705 557;…] double4.(1)>> X=100:999;>> length(find(~rem(X,21)))(2)>> y='ahHGJjskjJjsdsaSa';>> M=y(find(y<='z'&y>='a'))实验二实验三1 x=input('请输入x的值')if x<0&x~=-3y=x^2+x-6;elseif x>=0&x<5&x~=2&x~=3y=x^2-5*x+6;elsey=x^2-x-1;endy2(1)x=input('请输入成绩')if x>=90&x<=100disp('等级为A')elseif x>=80&x<=89disp('等级为B')elseif x>=70&x<=79disp('等级为C')elseif x>=60&x<=69disp('等级为D')elseif x>=0&x<=59disp('等级为E')elsedisp('成绩有误')end(2)x=input('请输入成绩')switch(x)case{90,100}disp('等级为A')case{80,89}disp('等级为B')case{70,79}disp('等级为C')case{60,69}disp('等级为D')case{0,59}disp('等级为E')otherwisedisp('成绩错误')end>>3Num=input('输入员工的工号:');Time=input('该工号员工的工作时数:');salary=input('该员工底薪:');if Time>=120salary=salary*(1+0.15);elseif Time<=60salary=salary-700;elseif Time>60&Time<120salary=Time*84;endsalary=salary实验四1:程序:n=input('输入n:');for a=1:n;b(a)=1/(a^2);endpi=sqrt(6*sum(b))2:.程序: sum=0;for n=1:200;b(n)=1/(2*n-1);sum=sum+b(n);if(sum>=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(n)=f(n-1)-2*f(n-2)+f(n-3);endfor m=1:100if(f(m)>max)max=f(m);endif(f(m)<min)min=f(m);endc=sum(f);if(f>0)zhengshu=zhengshu+1;endif(f(m)<0)fushu=fushu+1;endif(f(m)==0)zero=zero+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[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程序:function[p,q,w]=zhu(p,q,w)A=[p*cos(w),-p,-sin(w),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=A\B函数调用:程序:clearm1=input('m1=');m2=input('m2=');th=input('theta=');theta=pi*th/180;[m1,m2,theta]=zhu(m1,m2,theta);4函数文件:文件名:hanshu程序:function[y]=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)).*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,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);subplot(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=xif x0<=0y=[y,(x0+sqrt(pi))./exp(2)];elsey=[y,0.5*log(x0+sqrt(1+x0.*x0))];endendplot(x,y)4、程序:a=input('请输入a的值')b=input('请输入b的值')n=input('请输入n的值')theta=0:0.01:2*pi;rho=a.*sin(b+n.*theta)polar(theta,rho)5、程序:x=-linspace(-5,5,21);y=linspace(0,10,31);[x,y]=meshgrid(x,y)z=cos(x).*cos(y).*exp(-0.25*sqrt(x.^2+y.^2))subplot(1,2,1);title('surf(x,y,z)');surf(x,y,z);subplot(1,2,2);title('surfc(x,y,z)');surfc(x,y,z);实验八1、程序:x=rand(1,30000);EX=mean(x) %返回向量x的算术平均值S=std(x) %返回向量x的标准方差MAX=max(x) %返回向量x的最大元素MIN=min(x) %返回向量x的最小元素p=sum(x>0.5)/30000 %满足条件的百分比2、程序:p=100*rand(100,5);[MAXOBJECT,U]=max(p) %求每门课的最高分,U记录最大元素的行号[MAXOBJECT,V]=min(p) %求每门课的最低分,V记录最小元素的行号EX=mean(p) %每门课的平均分S=std(p) %每门课的标准方差SUM_1=sum(p,2) ; %求每名学生的总成绩[MAXSUM,W]=max(SUM) %求五门课总分的最高分,W记录最高分学生的序号[MINSUM,Y]=min(SUM) %求五门课总分的最低分,Y记录最低分学生的序号[zcj,xsxh]=sort(SUM_1);zcj(end:-1:1);xsxh(end:-1:1);实验九2、程序:I1=quad('sqrt(cos(t.^2)+4*sin(2*t).^2+1)',0,2*pi) I2=quad('(log(1+x))./(1+x.*x)',0,1)3、程序:A=[6,5,-2,5;9,-1,4,-1;3,4,2,-2;3,-9,0,2]b=[-4;13;1;11]x=inv(A)*b实验十1、程序:x=sym('6');y=sym('5');z=(x+1)/(sqrt(3+x)-sqrt(y))2、分解因式(1)程序:syms x y;A=x^4-y^4;factor(A)(2)程序:factor(sym('5135'))3、化简表达式(1)程序:syms beta1 beta2y=sin(beta1)*cos(beta2)-cos(beta1)*sin(beta2) simple(y)(2)程序:syms xy=(4*x^2+8*x+3)/(2*x+1)simple(y)5、用符号方法求下列极限或导数(1)程序:syms xf=(x*(exp(sin(x))+1)-2*(exp(tan(x))-1))/(sin(x)) limit(f)(2)程序:syms xy=(sqrt(pi)-sqrt(acos(x)))/(sqrt(x+1));limit(f,x,-1,'right')(3)程序:syms xy=(1-cos(2*x))/x;y1=diff(y)y2=diff(y,x,2)6、用符号方法求下列积分(1)程序:syms xf=1/(1+x^4+x^8)int(f)(2)程序:syms xf=1/(((asin(x))^2)*sqrt(1-x^2))int(f)(3)程序:syms xf=(x^2+1)/(x^4+1)int(f,x,0,inf)(4)程序:syms xf=exp(x)*(1+exp(x))^2y=int(f,x,0,log(2))double(y)。