MATLAB程序设计教程(第二版)课后答案_第1页
MATLAB程序设计教程(第二版)课后答案_第2页
MATLAB程序设计教程(第二版)课后答案_第3页
MATLAB程序设计教程(第二版)课后答案_第4页
MATLAB程序设计教程(第二版)课后答案_第5页
已阅读5页,还剩24页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、MATLAB第二版课后答案unit3-8unit3实验指导);请输入一个三位数:1、n=input('a=fix(n/100);b=fix(n-a*100)/10);c=n-a*100-b*10;d=c*100+b*10+a)2(1');请输入成绩n=input('switchncasenum2cell(90:100)p='A'casenum2cell(80:89)p='B'casenum2cell(70:79)p='C'casenum2cell(60:69)p='D'otherwisep='E&#

2、39;endprice=p请输入成绩)(2n=input('');ifn>=90&n<=100p='A'elseifn>=80&n<=89p='B'elseifn>=70&n<=79p='C'elseifn>=60&n<=69p='D'elsep='E'endprice=p)3(n;trycatchprice='erroe'end3n=1,5,56,4,3,476,45,6,3,76,45,6,4,3,6

3、,4,23,76,908,6;a=n(1);b=n(1);form=2:20ifn(m)>aa=n(m);elseifn(m)<bb=n(m);endendmax=amin=b法2n=1,5,56,4,3,476,45,6,3,76,45,6,4,3,6,4,23,76,908,6;min=min(n)max=max(n)4b=-3.0:0.1:3.0;forn=1:61a=b(n);y(n)=(exp(0.3*a)-exp(-0.3*a)/2*sin(a+0.3)+log(0.3+a)/2);endy5y1=0;y2=1;n=input('请输入n的值:');fo

4、ri=1:ny1=y1+1/iA2;y2=y2*(4*i*i)/(2*i-1)*(2*i+1);endy1y26A=1,1,1,1,1,1;2,2,2,2,2,2;3,3,3,3,3,3;4,4,4,4,4,4;5,5,5,5,5,5;6,6,6,6,6,6;n=input('请输入n的值:');if n<=5&n>=0disp(A(n,:);elseif n<0 disp(lasterr); else disp(A(6,:);disp(lasterr); end 7(1)f=口;for n=1:40f(n尸n+10*log(nA2+5);endy=f

5、(40)/(f(30)+f(20)(2)f=口;a=0;forn=1:40f(n)=a+n*(n+1);a=f(n);endy=f(40)/(f(30)+f(20)y=0;:');输入m的值m=input('');值:输入n=input('nfori=1:ny=y+iAm;endy*functions=shi8_1(n,m)s=0;fori=1:ns=s+iAm;end*shi8_1(100,1)+shi8_1(50,2)+shi8_1(10,1/2)思考练习2N=1,2,3,4,5;2.*NN./21./N1./N.A23s=fix(100*rand(1,20

6、)*9/10+10)y=sum(s)/20j=0;fo门=1:20ifs(i)<y&rem(s(i),2)=0endj=j+1;A(j)=s(i);elsecontinue;endA4y1=0;y2=0;n=input('请输入n的值:);fori=1:ny1=y1+-(-1)Ai/(2*i-1);y2=y2+1/4Ai;endyiy2unit4实验指导(11)x=-10:0.05:10;y=x-x.A3./6;plot(x,y)(2)x=-10:0.5:10;ezplot('xA2+2*yA2-64',-8,8);gridon;2t=-pi:pi/10:

7、pi;y=1./(1+exp(-t);subplot(2,2,1);bar(t,y);axis(-pi,pi,0,1);(t,y)'); title(' 条形图subplot(2,2,2);stairs(t,y,'b');(t,y)');阶梯图title('axis(-pi,pi,0,1);subplot(2,2,3);stem(t,y,'k');(t,y)');title('杆图axis(-pi,pi,0,1);subplot(2,2,4);loglog(t,y,'y');(t,y)');

8、title('对数坐标图3(1)t=0:pi/50:2*pi;r=5.*cos(t)+4;polar(t,r);title('rho=5*costheta+4');(2)t=-pi/3:pi/50:pi/3;r=5.*(sin(t).A2)./cos(t);polar(t,r);4(1)t=0:pi/50:2*pi;x=exp(-t./20).*cos(t);y=exp(-t./20).*sin(t);z=t;plot3(x,y,z);gridon;(2)x,y=meshgrid(-5:5);z=zeros(11)+5;mesh(x,y,z);shadinginterp

9、;x,y,z=sphere(20);surf(x,y,z);axisoff;shadinginterp;m=moviein(20);fo门=1:20axis(-i,i,-i,i,-i,i)m(:,i)=getframe;endmovie(m,4);思考练习)(21x=-5:0.1:5;y=(1./(2*pi).*exp(-(x.A2)/2);plot(x,y);(2)t=-2*pi:0.1:2*pi;x=t.*sin(t);y=t.*cos(t);plot(x,y);gridon;3t=0:pi/1000:pi;x=sin(3.*t).*cos(t);y1=sin(3.*t).*sin(t);

10、y2=2.*x-0.5;plot(x,y1,'k',x,y2);holdon;k=find(abs(y1-y2)<1e-2);x1=x(k);y3=2.*x1-0.5;plot(x1,y3,'rp');4x=-2:0.01:2;y=sin(1./x);subplot(2,1,1);plot(x,y);subplot(2,1,2);fplot('sin(1./x)',-2,2,1e-4);5(1)i=-4*pi:0.1:10;j=12./sqrt(i);polar(i,j);title('rho=12/sqrt(theta)'

11、)(2)a=-pi/6:0.01:pi/6;b=3.*asin(a).*cos(a)./(sin(a).A3+(cos(a).A3);polar(a,b);6(1)u,v=meshgrid(-4:0.1:4);x=3.*u.*sin(v);y=2.*u.*cos(v);z=4.*ud2;subplot(2,1,1);mesh(x,y,z);subplot(2,1,2);surf(x,y,z);(2)x,y=meshgrid(-3:0.2:3);z=-5./(1+x.A2+y.A2);subplot(1,2,1);mesh(x,y,z);subplot(1,2,2);surf(x,y,z);un

12、it5实验指导A=randn(10,5)x=mean(A)y=std(A)Max=max(max(A)Min=min(min(A)Sumhang=sum(A,2)SumA=sum(Sumhang)B=sort(A);C=sort(B,2,'descend');C2(1)a=0:15:90;b=a./180.*pi;s=sin(b)c=0:15:75;d=c./180.*pi;t=tan(d)');e=input('请输入想计算的值:S=sin(e/180*pi)T=tan(e/180*pi)S1=interp1(a,s,e,'spline')T1

13、=interp1(c,t,e,'spline')P1=polyfit(a,s,5);P2=polyfit(c,t,5);S2=polyval(P1,e)T2=polyval(P2,e)(2n=1,9,16,25,36,49,64,81,100;N=sqrt(n);x=input('jisuanzhi:');interp1(n,N,x,'cubic')3N=64;T=5;t=linspace(0,T,N);h=exp(-t);dt=t(2)-t(1);f=1/dt;X=fft(t);F=X(1:N/2+1);f=f*(0:N/2)/N;plot(f

14、,abs(F),'-*')4P=2,-3,0,5,13;Q=1,5,8;p=polyder(P)q=polyder(P,Q)a,b=polyder(P,Q)5P1=1,2,4,0,5;P2=0,1,2;P3=1,2,3;p=polyval(P ,A)P=P1+conv(P2,P3)X=roots(P)A=-1,1.2,-1.4;0.75,2,3.5;0,5,2.5;思考练习A=rand(1,30000);a=mean(A)b=std(A)Max=max(A)Min=min(A)n=0;fori=1:30000if(A(i)>0.5)n=n+1;endendny=n/300

15、005p=45,74,54,55,14;78,98,45,74,12;87,98,85,52,65M,S=max(p)N,H=min(p)junzhi=mean(p,1)fangcha=std(p,1,1)zong=sum(p,2);Max,wei=max(zong)Min,wei=min(zong)zcj,xsxh=sort(zong,'descend')6x=1:10:101;y=0,1.0414,1.3222,1.4914,1.6128,1.7076,1.7853,1.8513,1.9085,1.9590,2.0043;p,s=polyfit(x,y,5)a=1:5:10

16、1;y1=polyval(p,a);plot(x,y,':o',a,y1,'-*')unit6实验指导1A=1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6;p=0.95,0.67,0.52'x=ApA=1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6;p=0.95,0.67,0.53'x=Ap cond(A)2 ( 1)x1=fzero(funx1,-1)function fx=funx1(x)fx=xA41+xA3+1;(2)x2=fzero(funx2,0.5)function fx=funx2(

17、x)fx=x-sin(x)/x;(3)options=optimset('Display','off);x=fsolve(fun3,1,1,1',options)functionq=fun3(p)x=p(1);y=p(2);z=p(3);q(1)=sin(x)+yA2+log(z)-7;q(2)=3*x+2Ay-zA3+1;q(3)=x+y+z-5;3(1)t0=0;tf=5;y0=1;t,y=ode23(fun4,t0,tf,y0);t'yfunctionyp=fun4(t,y)yp=-(1.2+sin(10*t)*y;(2)t0=0;tf=5;y0=

18、1;t,y=ode23(fun5,t0,tf,y0);t'y'yp=cos(t)-y/(1+tA2);x=fminbnd(mymin,0,2);-mymin(x)functionfx=mymin(x)fx=-(1+xA2)/(1+xA4);5options=optimset('Display','off');x,fval=fmincon(fun6,0,0,0,a,b,lb,ub)-fvalfunctionf=fun6(x)f=-(sqrt(x(1)+(400-x(1)*1.1+(sqrt(x(2)+(400-x(1)*1.1-x(2)*1.1+s

19、qrt(3)+(400-x(1)*1.1-x(2)*1.1-x(3)*1.1+sqrt(x(x4);思考练习1(1)A=2,3,5;3,7,4;1,-7,1;B=10,3,5'C1=inv(A)*BC2=ABL,U=lu(A);x=U(LB)(2)A=6,5,-2,5;9,-1,4,-1;3,4,2,-2;3,-9,0,2;B=-4,13,1,11'C1=inv(A)*BC2=ABL,U=lu(A);x=U(LB)2(1)x1=fzero(funx1,1.5)functionfx=funx1(x)fx=3*x+sin(x)-exp(x);(2)x1=fzero(funx2,1)

20、functionfx=funx2(x)fx=x-1/x+5;(3)options=optimset('Display','off);x=fsolve(fun3,3,0',options)q=fun3(x)functionq=fun3(p)x=p(1);y=p(2);q(1)=xA2+yA2-9;q(2)=x+y-1;3(1)t0=0;tf=5;y0=0,1;t,y=ode45(vdpol,t0,tf,y0);t,yydot(2)=y(1);functionydot=vdpol(t,y);ydot(1)=(2-3*y(2)-2*t*y(1)./(1+tA2);yd

21、ot=ydot'(2)t0=0;tf=5;y0=1;0;2;t,y=ode45(vdpoll,t0,tf,y0);t,yfunctionydot=vdpoll(t,y);ydot(1)=cos(t)-y(3)./(3+sin(t)+5*y(1).*cos(2*t)/(t+1)A2)-y(2);ydot(2)=y(1);ydot(3)=y(2);ydot=ydot'4x=fminbnd(mymin,0,pi);-mymin(x)functionfx=mymin(x)fx=-sin(x)-cos(x.A2);5x,y1=fminbnd(mymax,0,1.5);-yifunctio

22、nfx=mymax(x);fx=-(9*x+4*x.A3-12*x.A2);unit7实验指导1(1)formatlongfx=inline('sin(x)./x');I,n=quadl(fx,0,2,1e-10)(2)formatlongfx=inline('1./(x-0.3)A2+0.01)-1./(x-0.9)A2+0.04)-6');I,n=quad(fx,0,1,1e-10)2(1)globalki;ki=0;I=dblquad(fxy,0,1,0,1)ki(2)f=inline('abs(cos(x+y)','x',

23、V);I=dblquad(f,0,pi,0,pi)3X=0.3:021.5;F=0.3895,0.6598,0.9147,1.1611,1.3971,1.6212,1.8325;trapz(X,F)4p=0:pi/5:2*pi;for n=1:3DX=diff(sin(p),n)end5f=inline('sin(x)./(x+cos(2.*x)');g=inline('(cos(x).*(x+cos(2*x)-sin(x).*(1-2.*sin(2*x)/(x+cos(2.*x).A2');x=-pi:0.01:pi;p=polyfit(x,f(x),5);d

24、p=polyder(p);在假设点的函数dp求dpx=polyval(dp,x);值直接dx=diff(f(x,3.01)/对f(x)求数值导数在假设点的导数g的导函f%求函数0.01;gx=g(x);数作图plot(x,dpx,x,dx,'.',x,gx,'-');思考练习2formatlongfx=inline('1./(1+x.A2)');I,n=quad(fx,-Inf,Inf,1e-10)I,n=quadl(fx,-Inf,Inf,1e-10)x=-100000:100000;y=1./(1+x.A2);trapz(x,y)format

25、short3(1)formatlongfx=inline('log(1+x)./(1+x.A2)');I,n=quad(fx,0,1,1e-10)formatlongfx=inline('sqrt(cos(t.A2)+4*sin(2*t).A2)+1)');I,n=quad(fx,0,2*pi,1e-10)4f=inline('4.*x.*z.*exp(-z.A2.*y-x.A2)');I=triplequad(f,0,pi,0,pi,0,1)5f=inline('sin(x)');g=inline('cos(x)'

26、;);x=0:0.01:2*pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x);dx=diff(f(x,2*pi+0.01)/0.01;gx=g(x);plot(x,dpx,x,dx,'.',x,gx,'-')unit8实验指导1symsxy;s=xA4-yA4;factor(s)factor(5135)2symsx;f=(x-2)/(xA2-4);limit(f,x,2)symx;f=(sqrt(pi)-sqrt(acos(x)/sqrt(x+1);limit(f,x,-1,'right'

27、;)3symx;f=sin(1/x);diff(f,'x')diff(f,'x',2)symx;f=(1-cos(2*x)/x;diff(f,'x')diff(f,'x',2)4symx;f=sqrt(exp(x)+1);int(f,'x')symsxy;f=x/(x+y);int(f,'y')symx;f=exp(x)*(1+exp(x)A2;int(f,'x',0,log(2)symx;f=x*log(x);int(f,'x',1,exp(1)5symx;s=sy

28、msum(-1)A(x+1)/x,1,Inf)symy;z=symsum(yA(2*y-1)/(2*y-1),1,Inf)6symx;f1=(exp(x)+exp(-x)/2;f2=sqrt(xA3-2*x+1);taylor(f1,x,5,0)taylor(f2,x,6,0)7symsxya;x=solve('xA3+a*x+1=0','x')x=solve('sin(x)+2*cos(x)-sqrt(x)=0','x')xy=solve('log(x/y)=9','exp(x+y)=3','x',V)8symsn;x,y=dsolve('x*(D2y)+(1-n)*(Dy)+y=0','y(0)=0','Dy(0)=0','x')思考练习2symsxB1B2abs1=2*(cos(x)A2)-(sin(x)A2;s2=sin(B1)*cos(B2)-cos(B1)*sin(B2);s3=sqrt(a+sqrt

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论