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+a2(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';endprice=p(2)n=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)tryn;catchprice='erroe'end3n=[1,5,56,4,3,476,45,6,3,76,45,6,4,3,6,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的值:');fori=1:ny1=y1+1/i^2;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的值:');ifn=5&n=0disp(A([n],:));elseifn0disp(lasterr);elsedisp(A([6],:));disp(lasterr);end7(1)f=[];forn=1:40f(n)=n+10*log(n^2+5);endy=f(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))8y=0;m=input('输入m的值:');n=input('输入n值:');fori=1:ny=y+i^m;endy************************************************************functions=shi8_1(n,m)s=0;fori=1:ns=s+i^m;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.^23s=fix(100*rand(1,20)*9/10+10)y=sum(s)/20j=0;fori=1:20ifs(i)y&rem(s(i),2)==0j=j+1;A(j)=s(i);elsecontinue;endendA4y1=0;y2=0;n=input('请输入n的值:');fori=1:ny1=y1+-(-1)^i/(2*i-1);y2=y2+1/4^i;endy1y2unit4实验指导1(1)x=-10:0.05:10;y=x-x.^3./6;plot(x,y)(2)x=-10:0.5:10;ezplot('x^2+2*y^2-64',[-8,8]);gridon;2t=-pi:pi/10:pi;y=1./(1+exp(-t));subplot(2,2,1);bar(t,y);title('条形图(t,y)');axis([-pi,pi,0,1]);subplot(2,2,2);stairs(t,y,'b');title('阶梯图(t,y)');axis([-pi,pi,0,1]);subplot(2,2,3);stem(t,y,'k');title('杆图(t,y)');axis([-pi,pi,0,1]);subplot(2,2,4);loglog(t,y,'y');title('对数坐标图(t,y)');3(1)t=0:pi/50:2*pi;r=5.*cos(t)+4;polar(t,r);title('\rho=5*cos\theta+4');(2)t=-pi/3:pi/50:pi/3;r=5.*((sin(t)).^2)./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;5[x,y,z]=sphere(20);surf(x,y,z);axisoff;shadinginterp;m=moviein(20);fori=1:20axis([-i,i,-i,i,-i,i])m(:,i)=getframe;endmovie(m,4);思考练习2(1)x=-5:0.1:5;y=(1./(2*pi)).*exp((-(x.^2))/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);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)')(2)a=-pi/6:0.01:pi/6;b=3.*asin(a).*cos(a)./((sin(a)).^3+(cos(a)).^3);polar(a,b);6(1)[u,v]=meshgrid(-4:0.1:4);x=3.*u.*sin(v);y=2.*u.*cos(v);z=4.*u.^2;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.^2+y.^2);subplot(1,2,1);mesh(x,y,z);subplot(1,2,2);surf(x,y,z);unit5实验指导1A=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=interp1(c,t,e,'spline')P1=polyfit(a,s,5);P2=polyfit(c,t,5);S2=polyval(P1,e)T2=polyval(P2,e)(2)n=[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,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=P1+conv(P2,P3)X=roots(P)A=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];p=polyval(P,A)思考练习4A=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/300005p=[45,74,54,55,14;78,98,45,74,12;87,98,85,52,65][M,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:101;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=A\pA=[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=A\pcond(A)2(1)x1=fzero(@funx1,-1)functionfx=funx1(x)fx=x^41+x^3+1;(2)x2=fzero(@funx2,0.5)functionfx=funx2(x)fx=x-sin(x)/x;(3)options=optimset('Display','off');x=fsolve(@fun3,[1,1,1]',options)q=fun3(x)functionq=fun3(p)x=p(1);y=p(2);z=p(3);q(1)=sin(x)+y^2+log(z)-7;q(2)=3*x+2^y-z^3+1;q(3)=x+y+z-5;3(1)t0=0;tf=5;y0=1;[t,y]=ode23(@fun4,[t0,tf],y0);t'y'functionyp=fun4(t,y)yp=-(1.2+sin(10*t))*y;(2)t0=0;tf=5;y0=1;[t,y]=ode23(@fun5,[t0,tf],y0);t'y'functionyp=fun5(t,y)yp=cos(t)-y/(1+t