MATLAB程序设计教程(第二版)课后答案
MATLAB程序设计教程(第二版)课后答案(可编辑修改word版)

MATLAB 第二版课后答案unit3-8 unit3实验指导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('请输入成绩');switch ncase num2cell(90:100)p='A';case num2cell(80:89)p='B';case num2cell(70:79)p='C';case num2cell(60:69)p='D';otherwisep='E';endprice=p(2)n=input('请输入成绩');if n>=90&n<=100p='A';elseif n>=80&n<=89p='B';elseif n>=70&n<=79p='C';elseif n>=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];b=n(1);for m=2:20if n(m)>aa=n(m);elseif n(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];for n=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 的值:');for i=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 的值:');if n<=5&n>=0disp(A([n],:));elseif n<0disp(lasterr);else disp(A([6],:));disp(lasterr);end7(1)f=[];f(n)=n+10*log(n^2+5);endy=f(40)/(f(30)+f(20))(2)f=[];a=0;for n=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 值:');for i=1:ny=y+i^m;endy************************************************************ function s=shi8_1(n,m)s=0;for i=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;for i=1:20if s(i)<y&rem(s(i),2)==0j=j+1;A(j)=s(i);else continue;endendA4y1=0;y2=0;n=input('请输入n 的值:'); for i=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]); grid on;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);grid on;(2)[x,y]=meshgrid(-5:5);z=zeros(11)+5;mesh(x,y,z);shading interp;5[x,y,z]=sphere(20);surf(x,y,z);axis off;shading interp;m=moviein(20);for i=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);grid on;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);hold on;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('ji suan zhi : ');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;for i=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)function fx=funx1(x)fx=x^41+x^3+1;(2)x2=fzero(@funx2,0.5)function fx=funx2(x)fx=x-sin(x)/x;(3)options=optimset('Display','off');x=fsolve(@fun3,[1,1,1]',options)q=fun3(x)function q=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'function yp=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'function yp=fun5(t,y)yp=cos(t)-y/(1+t^2);4x=fminbnd(@mymin,0,2);-mymin(x)function fx=mymin(x)fx=-(1+x.^2)/(1+x.^4);5options=optimset('Display','off');[x,fval]=fmincon(@fun6,[0,0,0],[],[],a,b,lb,ub)-fvalfunction f=fun6(x)f=-(sqrt(x(1))+(400-x(1))*1.1+(sqrt(x(2))+(400-x(1))*1.1-x(2))*1.1+sqrt(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=A\B[L,U]=lu(A);x=U\(L\B)(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=A\B[L,U]=lu(A);x=U\(L\B)2(1)x1=fzero(@funx1,1.5)function fx=funx1(x)fx=3*x+sin(x)-exp(x);(2)x1=fzero(@funx2,1)function fx=funx2(x)fx=x-1/x+5;(3)options=optimset('Display','off');x=fsolve(@fun3,[3,0]',options)q=fun3(x)function q=fun3(p)x=p(1);y=p(2);q(1)=x^2+y^2-9;q(2)=x+y-1;3(1)t0=0;tf=5;y0=[0,1];[t,y]=ode45(@vdpol,[t0,tf],y0);[t,y]function ydot=vdpol(t,y);ydot(1)=(2-3*y(2)-2*t*y(1))./(1+t^2);ydot(2)=y(1);ydot=ydot';(2)t0=0;tf=5;y0=[1;0;2];[t,y]=ode45(@vdpoll,[t0,tf],y0);[t,y]function ydot=vdpoll(t,y);ydot(1)=cos(t)-y(3)./(3+sin(t))+5*y(1).*cos(2*t)/((t+1).^2)-y(2); ydot(2)=y(1);ydot(3)=y(2);ydot=ydot';4x=fminbnd(@mymin,0,pi);-mymin(x)function fx=mymin(x)fx=-sin(x)-cos(x.^2);5[x,y1]=fminbnd(@mymax,0,1.5);-y1function fx=mymax(x);fx=-(9*x+4*x.^3-12*x.^2);unit7实验指导1(1)format longfx=inline('sin(x)./x');[I,n]=quadl(fx,0,2,1e-10)(2)format longfx=inline('1./((x-0.3).^2+0.01)-1./((x-0.9).^2+0.04)-6');[I,n]=quad(fx,0,1,1e-10)2(1)global ki;ki=0;I=dblquad(@fxy,0,1,0,1)ki(2)f=inline('abs(cos(x+y))','x','y');I=dblquad(f,0,pi,0,pi)3X=0.3:0.2:1.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:3nDX=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)).^2');x=-pi:0.01:pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x); %求dp 在假设点的函数值dx=diff(f([x,3.01]))/0.01; %直接对f(x)求数值导数gx=g(x); %求函数f 的导函数g 在假设点的导数plot(x,dpx,x,dx,'.',x,gx,'-'); %作图思考练习2format longfx=inline('1./(1+x.^2)');[I,n]=quad(fx,-Inf,Inf,1e-10)[I,n]=quadl(fx,-Inf,Inf,1e-10)x=-100000:100000;y=1./(1+x.^2);trapz(x,y)format short3(1)format longfx=inline('log(1+x)./(1+x.^2)');[I,n]=quad(fx,0,1,1e-10)(2)format longfx=inline('sqrt(cos(t.^2)+4*sin((2*t).^2)+1)'); [I,n]=quad(fx,0,2*pi,1e-10)4f=inline('4.*x.*z.*exp(-z.^2.*y-x.^2)');I=triplequad(f,0,pi,0,pi,0,1)5f=inline('sin(x)');g=inline('cos(x)');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实验指导1syms x y;s=x^4-y^4;factor(s)factor(5135)2syms x;f=(x-2)/(x^2-4);limit(f,x,2)sym x;f=(sqrt(pi)-sqrt(acos(x)))/sqrt(x+1);limit(f,x,-1,'right')3sym x;f=sin(1/x);diff(f,'x')diff(f,'x',2)sym x;f=(1-cos(2*x))/x;diff(f,'x')diff(f,'x',2)4sym x;f=sqrt(exp(x)+1);int(f,'x')syms x y;f=x/(x+y);int(f,'y')sym x;f=exp(x)*(1+exp(x))^2;int(f,'x',0,log(2))sym x;f=x*log(x);int(f,'x',1,exp(1))5sym x;s=symsum((-1)^(x+1)/x,1,Inf)sym y;z=symsum(y^(2*y-1)/(2*y-1),1,Inf)6sym x;f1=(exp(x)+exp(-x))/2;f2=sqrt(x^3-2*x+1);taylor(f1,x,5,0)taylor(f2,x,6,0)7syms x y a;x=solve('x^3+a*x+1=0','x')x=solve('sin(x)+2*cos(x)-sqrt(x)=0','x')[x y]=solve('log(x/y)=9','exp(x+y)=3','x','y')8syms n;[x,y]=dsolve('x*(D2y)+(1-n)*(Dy)+y=0','y(0)=0','Dy(0)=0','x') 思考练习2syms x B1 B2 a bs1=2*((cos(x))^2)-(sin(x))^2;s2=sin(B1)*cos(B2)-cos(B1)*sin(B2);s3=sqrt((a+sqrt(a^2-b))/2)+sqrt((a-sqrt(a^2-b))/2); s4=(4*x^2+8*x+3)/(2*x+1);h1=simplify(s1)h2=simplify(s2)h3=simplify(s3)h4=simplify(s4)3syms x a;f=abs(x)/x;limit(f,x,0,'left')f=(x+a/x)^x;limit(f,x,inf)4syms x y mf=sqrt(x+sqrt(x+sqrt(x)));m=diff(f,'x')diff(m,'x')syms x y;f=x+y-sqrt(x^2+y^2);z1=diff(f,x)z2=diff(f,y)5syms x y;f=x+y-sqrt(x^2+y^2);z1=diff(f,x)z2=diff(f,y)sym x;f=1/(asin(x)^2*(1-x^2)^(1/2));int(f)6syms xf=1/(1+x);int(f,0,4)sym x;f=x^3*sin(x)^2/(x^6+2*x^4+1);int(f,-1,1)sym x;f=x^3*sin(x)^2/(x^6+2*x^4+1);int(f,-1,1)7syms ns=symsum(1/4^n,1,inf)sym n;s=symsum(((n+1)/n)^(1/2),1,inf)eval(y)8syms xf=tan(x);taylor(f,x,3,0)syms xf=sin(x)^2;taylor(f,x,5,0)9syms xx=solve('log(1+x)-5/(1+sin(x))=2','x')syms x y z[x y z]=solve('4*x^2/(4*x^2+1)=y','4*y^2/(4*y^2+1)=z','4*z^2/(4*z^2+1)=x','x','y','z') 10[x ,y]=dsolve('Dx=3*x+4*y','Dy=5*x-7*y','x(0)=0','y(0)=1','t')。
matlab程序设计与应用第二版习题答案

matlab程序设计与应用第二版习题答案Matlab程序设计与应用第二版习题答案Matlab是一种强大的数学软件,广泛应用于科学计算、数据分析和工程设计等领域。
《Matlab程序设计与应用》是一本经典的教材,对于学习和掌握Matlab编程语言具有重要的意义。
本文将为大家提供《Matlab程序设计与应用第二版》中部分习题的答案,帮助读者更好地理解和应用Matlab。
第一章:Matlab基础1.1 基本操作1. a = 3; b = 4; c = sqrt(a^2 + b^2); disp(c);2. x = linspace(-pi, pi, 100); y = sin(x); plot(x, y);3. A = [1 2 3; 4 5 6; 7 8 9]; B = [9 8 7; 6 5 4; 3 2 1]; C = A + B; disp(C);1.2 控制结构1. for i = 1:10disp(i);end2. n = 0; sum = 0; while sum < 100n = n + 1;sum = sum + n;enddisp(n);3. x = 5; if x > 0disp('x is positive');elseif x < 0disp('x is negative');elsedisp('x is zero');end第二章:向量和矩阵运算2.1 向量运算1. A = [1 2 3]; B = [4 5 6]; C = A .* B; disp(C);2. A = [1 2 3]; B = [4 5 6]; C = A ./ B; disp(C);3. A = [1 2 3]; B = [4 5 6]; C = dot(A, B); disp(C);2.2 矩阵运算1. A = [1 2 3; 4 5 6]; B = [7 8; 9 10; 11 12]; C = A * B; disp(C);2. A = [1 2 3; 4 5 6]; B = [7 8; 9 10; 11 12]; C = B * A; disp(C);3. A = [1 2 3; 4 5 6]; B = [7 8; 9 10; 11 12]; C = A .* B; disp(C); 第三章:函数和脚本文件3.1 函数1. function y = myfunc(x)y = x^2 + 3*x + 2;end2. function [y1, y2] = myfunc(x1, x2)y1 = x1^2 + 3*x1 + 2;y2 = x2^2 + 3*x2 + 2;end3. function [y1, y2] = myfunc(x)y1 = x^2 + 3*x + 2;y2 = sin(x);end3.2 脚本文件1. x = linspace(0, 2*pi, 100); y = sin(x); plot(x, y);2. x = linspace(-10, 10, 100); y = x.^2 + 3*x + 2; plot(x, y);3. x = linspace(0, 2*pi, 100); y1 = sin(x); y2 = cos(x); plot(x, y1, x, y2);通过以上习题的答案,读者可以对Matlab程序设计的基本语法和常用函数有一个初步的了解。
MATLAB 程序设计教程第二版实验答案包括第七章

第二章:1.(1) w=sqrt(2)*(1+0.34245*10^(-6))w =1.4142(2) a=3.5;b=5;c=-9.8;x=(2*pi*a+(b+c)/(pi+a*b*c)-exp(2))/(tan(b+c)+a)x =0.9829(3) a=3.32;b=-7.9;y=2*pi*a^2*((1-pi/4)*b-(0.8333-pi/4)*a)y =-128.4271(4) t=[2,1-3i;5,-0.65];>> z=0.5*exp(2*t)*log(t+sqrt(1+t*t))z =1.0e+004 *0.0057 - 0.0007i 0.0049 - 0.0027i1.9884 - 0.3696i 1.7706 - 1.0539i2A=[-1,5,-4;0,7,8;3,61,7];B=[8,3,-1;2,5,3;-3,2,0]; >>(1) A+6*Bans =47 23 -1012 37 26-15 73 7>> A^2-B+eye-18 -216 1823 533 11022 868 526>>(2) A*Bans =14 14 16-10 51 21125 328 180>> A.*Bans =-8 15 40 35 24-9 122 0>> B*Aans =-11 0 -157 228 533 -1 28(3) A/Bans =1.2234 -0.92552.9787 -0.9468 2.3511 -0.9574 4.61703.8723 13.8936>> B\Aans =-0.5106 -8.6170 -1.1277 0.7340 17.5745 1.8085 -0.8830 -21.2128 0.4043>>(4) [A,B]ans =-1 5 -4 8 3 -10 7 8 2 5 33 61 7 -3 2 0>> [A([1,3],:);B^2]ans =-1 5 -43 61 773 37 117 37 13-20 1 9>>3A=[23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9.54,54,3.14];(1) b=find(A>=10&A<=25);>> A(b)ans =2310(2) B=A(1:3,:)B =23.0000 10.0000 -0.7780 041.0000 -45.0000 65.0000 5.000032.0000 5.0000 0 32.0000C=A(:,1:2)C =23.0000 10.000041.0000 -45.000032.0000 5.00006.0000 -9.5400>> D=A(2:4,3:4)D =65.0000 5.0000 0 32.0000 54.0000 3.1400>> E=B*CE =1.0e+003 *0.9141 -0.22391.20802.71231.1330 -0.2103(3) E<Dans =0 10 00 1>> E&Dans =1 10 11 1>> E|Dans =1 11 11 1~E|~Dans =0 01 00 0第三章:2.(1)c=input('请输入成绩');if(c>=90&c<=100)disp 'A' ;elseif(c>=80)disp 'B';elseif(c>=70)disp 'C';elseif(c>60)disp 'D';elsedisp 'E';end请输入成绩55Ec=input('please enter:'); switch fix(c/10)case {9,10}disp('A');case {8}disp('B');case {7}disp('C');case {6}disp('D');case {0,1,2,3,4,5} disp('E');end>> asplease enter:55E>> asplease enter:67D(2)while(1)c=input('请输入成绩');if(c>=90&c<=100)disp 'A' ;elseif(c<90&c>=80)disp 'B';elseif(c<80&c>=70)disp 'C';elseif(c<70&c>=60)disp 'D';elseif(c<60&c>=0)disp 'E';elsedisp 'wrong'endend>> third请输入成绩113wrong请输入成绩-47wrong请输入成绩45E请输入成绩89B请输入成绩78C3.a=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20] b=max(a)c=min(a)b=0c=0for i=1:20if a(i)>bb=a(i);endif a(i)<cc=a(i);endendbc6.A=rand(5,6)n=input('请输入矩阵:');if n>5n=5A(n,n)elseA(n)End6. a=rand(5,6);n=input('请输入n');if n==1disp(a(1,:))endif n==2disp(a(2,:))endif n==3disp(a(3,:))endif n==4disp(a(4,:))endif n==5disp(a(5,:))endif n>5disp(a(5,:))end第四章:1.(1)x=-12:0.001:12;y=x-x.^3/6;plot(x,y);xlabel('x轴');ylabel('y轴');title('Y=X-X^3/3!');(2)ezplot('x^2+2*y^2-64',[-8,8,-8,8])xlabel('x轴');ylabel('y轴');axis equaltitle('x^2+2y^2=64');4.(1)t=0:pi/100:2*pi;x=exp(-t/20).*cos(t);y=exp(-t/20).*sin(t);z=t;plot3(x,y,z)(2)[x,y]=meshgrid(-5:5);z=ones(11);surf(x,y,z);shading interp;第五章1.(1)A=randn(10,5);a=mean(A)a =0.0013 0.2310 0.0253 0.3588 -0.4197b=std(A)b =0.9034 0.8829 1.1898 0.7832 1.0821(2)max(max(A))ans =2.1832>> min(min(A))ans =-2.1707(3).sum(sum(A))ans =1.9666sum(A,1)ans =0.0128 2.3095 0.2528 3.5884 -4.1969(4).sort(A)ans =-1.6656 -0.8323 -1.5937 -1.2025 -2.1707-1.1465 -0.5883 -1.4410 -0.3999 -1.6041-0.4326 -0.1867 -1.3362 -0.1567 -1.0565-0.0376 -0.1364 -0.6918 -0.0198 -0.92190.1253 -0.0956 0.2944 0.6686 -0.80510.1746 0.0593 0.5711 0.6900 -0.05920.2877 0.1139 0.7143 0.7119 0.21930.3273 0.7258 0.8580 0.8156 0.25731.1892 1.0668 1.2540 1.1908 0.52871.19092.1832 1.6236 1.2902 1.4151>> sort(ans,2,'descend')ans =-0.8323 -1.2025 -1.5937 -1.6656 -2.1707-0.3999 -0.5883 -1.1465 -1.4410 -1.6041-0.1567 -0.1867 -0.4326 -1.0565 -1.3362-0.0198 -0.0376 -0.1364 -0.6918 -0.92190.6686 0.2944 0.1253 -0.0956 -0.80510.6900 0.5711 0.1746 0.0593 -0.05920.7143 0.7119 0.2877 0.2193 0.11390.8580 0.8156 0.7258 0.3273 0.25731.2540 1.1908 1.1892 1.0668 0.52872.1832 1.6236 1.4151 1.2902 1.19092.(2)n=1:10;a=n.*n;interp1(n,a,2.2,'cubic')ans =4.8133第七章(1)g=inline('sin(x)./x');>> [s,n]=quad(g,0,2)s =1.6054n =18(2)g=inline('1./((x-0.3).*(x-0.3)+0.01)-1./((x-0.9).*(x-0.9)+0.04)-6'); >> [s,n]=quad(g,0,1)s =11.7006n =145。
最新Matlab程序设计教程[第二版]刘卫国课后参考答案及解析资料
![最新Matlab程序设计教程[第二版]刘卫国课后参考答案及解析资料](https://img.taocdn.com/s3/m/ff4491220b4e767f5acfce3b.png)
第二章1 求下列表达式的值。
(1)w=sqrt(2)*(1+0.34245*10^(-6))(2)a=3.5;b=5;c=-9.8;x=(2*pi*a+(b+c)/(pi+a*b*c)-exp(2))/tan(b+c)+a(3)a=3.32;b=-7.9;y=2*pi*a^(2)*[(1-pi/4)*b-(0.8333-pi/4)*a](4)t=[2,1-3*i;5,-0.65];z=1/2*exp(2*t)*log(t+sqrt(1+t^(2)))2 求下列表达式A=[-1,5,-4;0,7,8;3,61,7];B=[8,3,-1;2,5,3;-3,2,0];(1)A+6*B A^2-B+eye(2)A*B A.*B B.*A(3)A/B B\A(4)[A,B] [A([1,3],:);B^2]3 根据已知,完成下列操作(1)A=[23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9.54,54,3.14]; K=find(A>10&A<25);A(K)(2)A=[23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9.54,54,3.14]; B=A(1:3,:) C=A(:,1:2) D=A(2:4,3:4) E=B*C(3)E<D E&D E|D ~E|~D第三章1 从键盘输入一个3位数,将它反向输出,如输入639,出数936。
f=input('输入一个数:','s');f(end :-1:1)2 用if语句score=input('请输入成绩:');if score>=90&&score<=100disp('A');elseif score>=80&&score<=89disp('B');elseif score>=70&&score<=79disp('C');elseif score>=60&&score<=69;disp('D');elseif score<60&&score>=0;disp('E');elsedisp('出错');end用switch语句score=input('请输入成绩:');switch fix(score/10)case {9,10}disp('A');case {8}disp('B');case {7}disp('C');case {6}disp('D');case {0,1,2,3,4,5}disp('E');otherwisedisp('出错');end第四章1题1) X=0:10;Y=x-x.^3/6;P lot(x,y)2) t=0:0.01:2*pi;x=8.*cos(t);y=4*sqrt(2).*sin(t);plot(x,y)2题M文件:t=-pi:pi/10:pi;y=1./(1+exp(-t));subplot(2,2,1);bar(t,y,'b');title('bar(t,y,''b'')');axis([-5,5,-3,3]); subplot(2,2,2);stairs(t,y,'k');title('stairs (t,y,''k'')');axis([-5,5,-3,3]); subplot(2,2,3);stem(t,y,'m');title('stem (t,y,''m'')');axis([-5,5,-3,3]); subplot(2,2,4);loglog(t,y,'g');title('loglog(t,y,''g'')');axis([-5,5,-3,3]);3题1)t=0:pi/100:2*pi;y=5*cos(t)+4;polar(t,y,'-*')2)t=-pi/3:pi/100:pi/3;r=5*sin(t).^2./cos(t);polar(t,r,'-*')4题1)t=0:pi/100:2*pi;x=exp(-t/20).*cos(t);y=exp(-t/20).*sin(t);z=t;plot3(x,y,z)第五章:1题A=randn(10,5)1) X=mean(A)Y=std(A,0,1)2) max(max(A))min(min(A))3) B=sum(A,2)sum(B)4) sort(A);sort(A,2,'descend')2题1)t=0:15:90;x1=[0,0.2588,0.5000,0.7071,0.8660,0.9659,1.0000];a1=0:1:90;y1=interp1(t,x1,a1,'spline')x2=[0,0.2679,0.5774,1.0000,1.7320,3.7320,NaN]; a2=0:1:75;y2= interp1(t,x2,a2,'spline')p1=polyfit(t,x1,5);z1=polyval(p1,a1)p2=polyfit(t,x2,5);z2=polyval(p2,a2)4题P=[2,-3,5,13];Q=[1,5,8];p=polyder(P)p1=polyder(P,Q)[p,q]= polyder(P,Q)5题P1=[1,2,4,0,5];P2=[1,0];P3=[1,2,3];1) P4=conv(P2,P3)P4=[0,1,2,3,0];P=P1+P42) x=roots(P)3) A=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];Y=polyval(P,A)4) Z=polyvalm(P,A)第8章1.分解因式. (2)factor(sym(‘5135’))(1)syms A x y;A=x^4-y^4;factor(A)2.求函数的极限(1)syms x; (2)syms x;limit((x-2)/(x^2-4),x,2)f=(sqrt(pi)-sqrt(acos(x)))/sqrt(x+1);limit(f,x,-1,'right')3.求函数的符号导数。
matlab程序设计(第二版)课后作业答案

一、实验结果:1、利用函数eye,ones,zeros,rand,randn 函数分别产生首先编写脚本函数如下:a1=eye(3)a2=eye(15,8)b1=ones(3)b2=ones(15,8)c1=zeros(3)c2=zeros(15,8)d1=2*rand(3,3)-1d2=2*randn(3,3)+1r1=2*rand(15,8)-1r2=2*randn(15,8)+12、使用函数diag和reshape函数:编写脚本:a1=[8 -7 2];a2=diag(a1);a3=fliplr(a2);a4=[5 3];a5=diag(a4,-1);a6=fliplr(a5);a=a3+a6a1=reshape(a,1,9)b1=[4 5 7];b2=diag(b1);b3=fliplr(b2);b4=[2 0 8];b5=diag(b4);b=b3+b5b6=reshape(b,1,9)3、直接在工作空间里输入:a=5-round(100*rand(50,2))/104、脚本文件:a=[-pi:2*pi/360:pi];y1=sin(a)y2=cos(a)5.、编写脚本:A=rand(10)b=A>0.6[i,j,v]=find(b)c=sum(v)6、编写脚本:A=randn(10)b=-0.5<A<0.5[i,j,v]=find(b);c=sum(v)7、编写实现表中功能的语句:if and(a<1,b<=0.5)语句1elseif and(a<1,b>0.5)语句2elseif and(a>=1,b<=0.5)语句3elseif and(a>=1,b>0.5)语句4elsedisp('error')end8、编写脚本如下:A=2*rand(3)b=A>1c=A.*b;[i,j,v]=find(c);v9、编写脚本函数:A=101*rand(100,3)b=A>100;c=A.*b;[i,j,d]=find(c);d10、为节约空间,用5*5的矩阵来模拟100*100的矩阵:编写脚本函数如下:A=[0 2 0 3 0;0 0 0 0 0;0 8 0 5 0;0 4 0 5 0;0 4 0 2 0]b=any(A);[i,j,v]=find(1-b);A(:,j)=[];B=A';c=any(B);[i,j,v]=find(1-c);B(:,j)=[];A=B'一、实验结果:1、输入脚本函数:x=0:pi/50:2*pi;k=[1 26 51 76 101];x(k)=[];figure(1)subplot(2,2,1)plot(x,sin(x)),grid onsubplot(2,2,2)plot(x,cos(x)),grid onsubplot(2,2,3)plot(x,tan(x)),grid onsubplot(2,2,4)plot(x,cot(x)),grid on2、分别利用title函数给图形加上标题,用text函数给坐标系中的建立文本对象,可将字符串放在图形的指定位置,用xlabel、ylabel函数添加x、y轴的标记,用legend 函数给图形加上插图说明。
Matlab_程序的设计教程(第二版)刘卫国_课后参考答案

第二章1 求下列表达式的值。
(1)w=sqrt(2)*(1+0.34245*10^(-6))(2)a=3.5;b=5;c=-9.8;x=(2*pi*a+(b+c)/(pi+a*b*c)-exp(2))/tan(b+c)+a (3)a=3.32;b=-7.9;y=2*pi*a^(2)*[(1-pi/4)*b-(0.8333-pi/4)*a](4)t=[2,1-3*i;5,-0.65];z=1/2*exp(2*t)*log(t+sqrt(1+t^(2)))2 求下列表达式A=[-1,5,-4;0,7,8;3,61,7];B=[8,3,-1;2,5,3;-3,2,0];(1)A+6*B A^2-B+eyeA*B A.*B B.*A(3)A/B B\A(4)[A,B] [A([1,3],:);B^2]3 根据已知,完成下列操作(1)A=[23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9.54,54,3.14];K=find(A>10&A<25);A(K)(2)A=[23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9.54,54,3.14];B=A(1:3,:) C=A(:,1:2) D=A(2:4,3:4) E=B*C(3)E<D E&D E|D ~E|~D第三章1 从键盘输入一个3位数,将它反向输出,如输入639,出数936。
f=input('输入一个数:','s');f(end :-1:1)2 用if语句score=input('请输入成绩:'); if score>=90&&score<=100 disp('A');elseif score>=80&&score<=89disp('B');elseif score>=70&&score<=79disp('C');elseif score>=60&&score<=69;disp('D'); elseif score<60&&score>=0;disp('E');elsedisp('出错');end用switch语句score=input('请输入成绩:'); switch fix(score/10)case {9,10}disp('A');case {8}disp('B');case {7}disp('C');case {6}disp('D');case {0,1,2,3,4,5}disp('E');otherwisedisp('出错');end第四章1题1) X=0:10;Y=x-x.^3/6;Plot(x,y)2) t=0:0.01:2*pi;x=8.*cos(t);y=4*sqrt(2).*sin(t);plot(x,y)2题M文件:t=-pi:pi/10:pi;y=1./(1+exp(-t));subplot(2,2,1);bar(t,y,'b');title('bar(t,y,''b'')');axis([-5,5,-3,3]); subplot(2,2,2);stairs(t,y,'k');title('stairs (t,y,''k'')');axis([-5,5,-3,3]); subplot(2,2,3);stem(t,y,'m');title('stem (t,y,''m'')');axis([-5,5,-3,3]); subplot(2,2,4);loglog(t,y,'g');title('loglog(t,y,''g'')');axis([-5,5,-3,3]);3题1)t=0:pi/100:2*pi;y=5*cos(t)+4;polar(t,y,'-*')2)t=-pi/3:pi/100:pi/3;r=5*sin(t).^2./cos(t);polar(t,r,'-*')4题1)t=0:pi/100:2*pi;x=exp(-t/20).*cos(t);y=exp(-t/20).*sin(t);z=t;plot3(x,y,z)第五章:1题A=randn(10,5)1) X=mean(A)Y=std(A,0,1)2) max(max(A))min(min(A))3) B=sum(A,2)sum(B)4) sort(A);sort(A,2,'descend')2题1)t=0:15:90;x1=[0,0.2588,0.5000,0.7071,0.8660,0.9659,1.0000];a1=0:1:90;y1=interp1(t,x1,a1,'spline')x2=[0,0.2679,0.5774,1.0000,1.7320,3.7320,NaN]; a2=0:1:75;y2= interp1(t,x2,a2,'spline')p1=polyfit(t,x1,5);z1=polyval(p1,a1)p2=polyfit(t,x2,5);z2=polyval(p2,a2)4题P=[2,-3,5,13];Q=[1,5,8];p=polyder(P)p1=polyder(P,Q)[p,q]= polyder(P,Q)5题P1=[1,2,4,0,5];P2=[1,0];P3=[1,2,3];1) P4=conv(P2,P3)P4=[0,1,2,3,0];P=P1+P42) x=roots(P)3) A=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];Y=polyval(P,A)4) Z=polyvalm(P,A)第8章1.分解因式. (2)factor(sym(‘5135’))(1)syms A x y;A=x^4-y^4;factor(A)2.求函数的极限(1)syms x; (2)syms x;limit((x-2)/(x^2-4),x,2)f=(sqrt(pi)-sqrt(acos(x)))/sqrt(x+1);limit(f,x,-1,'right')3.求函数的符号导数。
Matlab程序设计教程[第二版]刘卫国课后参考答案及解析
![Matlab程序设计教程[第二版]刘卫国课后参考答案及解析](https://img.taocdn.com/s3/m/2b09c50ea5e9856a5612605a.png)
第二章1 求下列表达式的值。
(1)w=sqrt(2)*(1+0.34245*10^(-6))(2)a=3.5;b=5;c=-9.8;x=(2*pi*a+(b+c)/(pi+a*b*c)-exp(2))/tan(b+c)+a(3)a=3.32;b=-7.9;y=2*pi*a^(2)*[(1-pi/4)*b-(0.8333-pi/4)*a](4)t=[2,1-3*i;5,-0.65];z=1/2*exp(2*t)*log(t+sqrt(1+t^(2)))2 求下列表达式A=[-1,5,-4;0,7,8;3,61,7];B=[8,3,-1;2,5,3;-3,2,0];(1)A+6*B A^2-B+eye(2)A*B A.*B B.*A(3)A/B B\A(4)[A,B] [A([1,3],:);B^2]3 根据已知,完成下列操作(1)A=[23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9.54,54,3.14]; K=find(A>10&A<25);A(K)(2)A=[23,10,-0.778,0;41,-45,65,5;32,5,0,32;6,-9.54,54,3.14]; B=A(1:3,:) C=A(:,1:2) D=A(2:4,3:4) E=B*C(3)E<D E&D E|D ~E|~D第三章1 从键盘输入一个3位数,将它反向输出,如输入639,出数936。
f=input('输入一个数:','s');f(end :-1:1)2 用if语句score=input('请输入成绩:');if score>=90&&score<=100disp('A');elseif score>=80&&score<=89disp('B');elseif score>=70&&score<=79disp('C');elseif score>=60&&score<=69;disp('D');elseif score<60&&score>=0;disp('E');elsedisp('出错');end用switch语句score=input('请输入成绩:');switch fix(score/10)case {9,10}disp('A');case {8}disp('B');case {7}disp('C');case {6}disp('D');case {0,1,2,3,4,5}disp('E');otherwisedisp('出错');end第四章1题1) X=0:10;Y=x-x.^3/6;Plot(x,y)2) t=0:0.01:2*pi;x=8.*cos(t);y=4*sqrt(2).*sin(t);plot(x,y)2题M文件:t=-pi:pi/10:pi;y=1./(1+exp(-t));subplot(2,2,1);bar(t,y,'b');title('bar(t,y,''b'')');axis([-5,5,-3,3]); subplot(2,2,2);stairs(t,y,'k');title('stairs (t,y,''k'')');axis([-5,5,-3,3]); subplot(2,2,3);stem(t,y,'m');title('stem (t,y,''m'')');axis([-5,5,-3,3]); subplot(2,2,4);loglog(t,y,'g');title('loglog(t,y,''g'')');axis([-5,5,-3,3]);3题1) t=0:pi/100:2*pi;y=5*cos(t)+4;polar(t,y,'-*')2) t=-pi/3:pi/100:pi/3;r=5*sin(t).^2./cos(t);polar(t,r,'-*')4题1)t=0:pi/100:2*pi;x=exp(-t/20).*cos(t);y=exp(-t/20).*sin(t);z=t;plot3(x,y,z)第五章:1题A=randn(10,5)1) X=mean(A)Y=std(A,0,1)2) max(max(A))min(min(A))3) B=sum(A,2)sum(B)4) sort(A);sort(A,2,'descend')2题1) t=0:15:90;x1=[0,0.2588,0.5000,0.7071,0.8660,0.9659,1.0000]; a1=0:1:90;y1=interp1(t,x1,a1,'spline')x2=[0,0.2679,0.5774,1.0000,1.7320,3.7320,NaN];a2=0:1:75;y2= interp1(t,x2,a2,'spline')p1=polyfit(t,x1,5);z1=polyval(p1,a1)p2=polyfit(t,x2,5);z2=polyval(p2,a2)4题P=[2,-3,5,13];Q=[1,5,8];p=polyder(P)p1=polyder(P,Q)[p,q]= polyder(P,Q)5题P1=[1,2,4,0,5];P2=[1,0];P3=[1,2,3];1) P4=conv(P2,P3)P4=[0,1,2,3,0];P=P1+P42) x=roots(P)3) A=[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5];Y=polyval(P,A)4) Z=polyvalm(P,A)第8章1.分解因式. (2)factor(sym(‘5135’))(1)syms A x y;A=x^4-y^4;factor(A)2.求函数的极限(1)syms x; (2)syms x;limit((x-2)/(x^2-4),x,2)f=(sqrt(pi)-sqrt(acos(x)))/sqrt(x+1);limit(f,x,-1,'right')3.求函数的符号导数。
matlab第二版课后习题答案

matlab第二版课后习题答案
《MATLAB第二版课后习题答案》
MATLAB是一种强大的数学软件,被广泛应用于工程、科学和金融等领域。
《MATLAB第二版》是一本经典的教材,为了帮助学生更好地掌握MATLAB的使用,书中提供了大量的课后习题。
下面我们将为大家总结一些MATLAB第二版课后习题的答案,希望能对大家的学习有所帮助。
1. 第一章课后习题答案
第一章主要介绍了MATLAB的基本操作,包括变量的定义、矩阵的运算、函数的使用等。
在课后习题中,有一道题目是要求计算一个矩阵的逆矩阵。
答案是使用MATLAB中的inv函数,将原矩阵作为参数传入即可得到逆矩阵。
2. 第二章课后习题答案
第二章介绍了MATLAB中的绘图功能,包括二维和三维图形的绘制。
有一道课后习题是要求绘制一个正弦曲线和余弦曲线,并在同一张图上显示。
答案是使用MATLAB中的plot函数,分别绘制正弦曲线和余弦曲线,并使用legend函数添加图例。
3. 第三章课后习题答案
第三章介绍了MATLAB中的控制流程,包括if语句、for循环和while循环等。
有一道课后习题是要求编写一个程序,计算1到100之间所有偶数的和。
答案是使用for循环遍历1到100之间的所有数,判断是否为偶数并累加。
通过以上几个例子,我们可以看到MATLAB第二版课后习题的答案涵盖了各种基本和高级的操作,对于学习MATLAB是非常有帮助的。
希望大家在学习MATLAB的过程中能够多加练习,掌握更多的技巧和方法。
MATLAB程序设计及应用(第二版)课后实验答案

Matlab课后实验题答案《实验一 MATLAB运算基础1. 先求下列表达式的值,然后显示MATLAB工作空间的使用情况并保存全部变量。
(1)0 122sin851ze =+(2)21ln( 2z x=,其中2120.455i x+⎡⎤=⎢⎥-⎣⎦(3)0.30.330.3sin(0.3)ln, 3.0, 2.9,,2.9,3.0 22a ae e az a a--+=++=--(4) 2242011122123t t z t t t t t ⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t =0::^2. 已知:1234413134787,2033657327A B --⎡⎤⎡⎤⎢⎥⎢⎥==⎢⎥⎢⎥⎢⎥⎢⎥-⎣⎦⎣⎦求下列表达式的值:(1) A+6*B 和A-B+I (其中I 为单位矩阵) (2) A*B 和A.*B (3) A^3和A.^3 (4) A/B 及B\A [(5) [A,B]和[A([1,3],:);B^2])3. 设有矩阵A 和B123453166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦(1) 求它们的乘积C 。
(2) 将矩阵C 的右下角3×2子矩阵赋给D 。
(3) 查看MATLAB 工作空间的使用情况。
4. 完成下列操作:(1) 求[100,999]之间能被21整除的数的个数。
(2) 建立一个字符串向量,删除其中的大写字母。
解:(1) 结果:(2). 建立一个字符串向量 例如: |ch='ABC123d4e56Fg9';则要求结果是: ;实验二 MATLAB 矩阵分析与处理1. 设有分块矩阵33322322E R A O S ⨯⨯⨯⨯⎡⎤=⎢⎥⎣⎦,其中E 、R 、O 、S 分别为单位矩阵、随机矩阵、零矩阵和对角阵,试通过数值计算验证22E R RS A OS +⎡⎤=⎢⎥⎣⎦。
MATLAB程序设计教程(第二版)课后答案

MATLAB第二版课后答案unit3-8 unit3实验指导1、n=i nput('请输入一个三位数:');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('请输入成绩');switch ncase num2cell(90:100)p='A';case num2cell(80:89)p='B';case num2cell(70:79)p='C';case num2cell(60:69)p='D';otherwisep='E';end price二p(2)n=input('请输入成绩'); if n>=90&n <=100 p='A:elseif n>=80&n v=89p='B';elseif n>=70&n v=79p='C';elseif n>=60&n v=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);for m=2:20if n(m )>aa=n( m);elseif n(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]; mi n=mi n(n)max二max (n)4b二[-3.0:0.130];for n=1:61a=b( n);y(n )=(exp(0.3*a)-exp(-0.3*a))/2*si n(a+0.3)+log((0.3+a)/2);5y1=0;y2=1;n=input('请输入n的值:');for i=1: ny1=y1+1/i A2;y2二y2*((4*i*i)/((2*i-1)*(2*i+1)));endyiy26A=[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<0disp(lasterr);else disp(A([6],:));disp(lasterr);endf=[];for n=1:40f(n )=n+10*log( n^2+5);endy=f(40)/(f(30)+f(20))(2)f=[];a=0;for n=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 值:');for i=1: ny=y+i A m;end************************************************************fun cti on s=shi8_1( n,m)s=0;for i=1: ns=s+i A 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.A23s=fix(100*ra nd(1,20)*9/10+10)y=sum(s)/20j=0;for i=1:20if s(i)vy&rem(s(i),2)==0j=j+1;A(j)=s(i);else con ti nue;endendA4y1=0;y2=0;n=input('请输入n的值:'); for i=1: n y1=y1+-(-1)A i/(2*i-1); y2=y2+1/4A i; endyiy2unit4实验指导1 (1)x=-10:0.05:10;y=x-x.A3./6;Plot(x,y)(2)x=-10:0.5:10;ezplot('x A2+2*y A2-64',[-8,8]);grid on;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.*((si n( 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).*si n( t);z=t;plot3(x,y,z);grid on;(2)[x,y]=meshgrid(-5:5); z=zeros(11)+5; mesh(x,y,z); shad ing in terp;5[x,y,z]=sphere(20);surf(x,y,z);axis off;shad ing in terp;m=movie in( 20);axis([-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.*si n( t);y=t.*cos(t);grid on;3t=O:pi/1OOO:pi;x=si n( 3.*t).*cos(t);y1=si n(3.*t).*si n( t);y2=2.*x-0.5;plot(x,y1,'k',x,y2);hold on;k二fin d(abs(y1-y2)<1e-2); x1=x(k);y3=2.*x1-0.5;plot(x1,y3,'rp');4x=-2:0.01:2;y=s in (1./x);subplot(2,1,1);plot(x,y);subplot(2,1,2);fplot('si n(1./x)',[-2,2],1e-4);5 (1)i=-4*pi:0.1:10;j=12./sqrt(i);polar(ij);title('{\rho}=12/sqrt(\theta)')(2)a=-pi/6:0.01:pi/6;b=3.*asi n( a).*cos (a) ./((s in (a)).八3+(cos(a)).八3); polar(a,b);6 (1)[u,v]=meshgrid(-4:0.1:4);x=3.*u.*s in (v);y=2.*u.*cos(v);z=4.*u.A2;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);unit5实验指导1A=ra ndn (10,5)x=mea n(A)y=std(A)Max二max(max(A))Min二min( mi n( A))Sumha ng二sum(A,2) SumA=sum(Sumha ng) B=sort(A); C=sort(B,2,'desce nd'); C2 (1)a=0:15:90;b=a./180.*pi;s=s in(b)c=0:15:75;d二c./180.*pi;t=ta n(d)e=i nput('请输入想计算的值:');S=si n( e/180*pi)T=ta n(e/180*pi)S1=i nterp1(a,s,e,'spli ne')T1二in terp1(c,t,e,'spli ne')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=in put('ji sua n zhi :');in terp1( n,N,x,'cubic')3N=64;T=5;t=li nspace(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)5P仁[1,2,4,0,5];P2=[0,1,2];P3=[1,2,3];P=P1+co nv(P2,P3)X=roots(P)A二[-1,1.2,-1.4;0.75,2,3.5;0,5,2.5]; p=polyval(P,A)思考练习A=ra nd(1,30000);a=mea n(A)b二std(A)Max二max(A)Min 二mi n(A)n=0;for i=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]=mi n(p)jun zhi=mea n( p,1)fan gcha=std(p,1,1)zon g=sum(p,2);[Max,wei]=max(z ong)[Mi n, wei]=mi n(zong)[zcj,xsxh]=sort(z on g,'desce nd')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\pcon d(A)2 (1)x1二fzero(@fu nx1,-1) fun cti on fx二fun x1(x) fx=x A41+x A3+1;(2)x2=fzero(@fu nx2,0.5)fun cti on fx二fun x2(x)fx=x-si n( x)/x;(3)optio ns=optimset('Display','off); x=fsolve(@fu n3,[1,1,1]',optio ns) q=fu n3(x) fun cti on q二fun 3(p)x=p(1);y=p (2);z=p (3);q(1)=si n(x)+yA2+log (z)-7;q(2)=3*x+2Ay-zA3+1; q(3)=x+y+z-5;3 (1)t0=0;tf=5;yO=1;[t,y]=ode23(@fu n4 ,[tO,tf],yO); t'y'fun cti on yp二fu n4 (t,y)yp=-(1.2+si n(1O*t))*y;(2)t0=0;tf=5;y0=1;[t,y]=ode23(@fu n5,[t0,tf],y0); t'y'fun cti on yp二fu n5(t,y)yp=cos(t)-y/(1+t A2);4x=fm inbn d(@m ymin, 0,2);-mymi n(x)fun cti on fx=mymi n(x)fx=-(1+x.A2)/(1+x.A4);5optio ns=optimset('Display','off);[x,fval]=fmi neon (@fu n6,[0,0,0],[],[],a,b,lb,ub)-fvalfun eti on f二fun 6(x)f=-(sqrt(x(1))+(400-x(1))*1.1+(sqrt(x (2))+(400-x(1))*1.1-x (2))*1.1+sqrt(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=i nv(A)*BC2=A\B[L,U]=lu(A);x=U\(L\B)(2)A=[6,5,-2,5;9,-1,4,-1;3,4,2,-2;3,-9,0,2]; B二[-4,13,1,11]';C1=i nv(A)*BC2=A\B[L,U]=lu(A);x=U\(L\B)2 (1)x1二fzero(@fu nx1,1.5)fun cti on fx二fun x1(x)fx=3*x+si n(x)-exp(x);(2)x1=fzero(@fu nx2,1)fun cti on fx二fun x2(x) fx=x-1/x+5;(3)optio ns=optimset('Display','off); x=fsolve(@fu n3,[3,0]',optio ns) q=fu n3(x) fun cti on q二fun 3(p)x=p(1);y=p (2);q(1)=x A2+y A2-9;q(2)=x+y-1;3 (1)t0=0;tf=5;yo=[o,i];[t,y]=ode45(@vdpol,[t0,tf],y0);[t,y]fun cti on ydot二vdpol(t,y);ydot(1)=(2-3* y(2)-2*t*y(1))./(1+t A2);ydot(2)=y(1);ydot=ydot';(2)t0=0;tf=5;y0=[i;0;2];[t,y]=ode45(@vdpoll,[t0,tf],y0);[t,y]fun cti on ydot二vdpoll(t,y);ydot(1)=cos(t)-y(3)./(3+si n( t))+5*y(1).*cos(2*t)/((t+1)A2)-y(2); ydot(2)=y(1);ydot(3)=y(2);ydot=ydot';4x=fmi nbn d(@mymi n,0,pi);-mymi n(x)fun cti on fx=mymi n(x)fx=-si n(x)-cos(x.A2);5[x,y1]=fmi nbn d(@mymax,0,1.5);-yifun cti on fx=mymax(x);fx=-(9*x+4*x.A3-12*x.A2);unit7实验指导1 (1)format longfx二in li ne('s in( x)./x');[I, n ]=quadl(fx,0,2,1e-10)(2)format longfx=i nlin e('1./((x-0.3)A2+0.01)-1./((x-0.9)A2+0.04)-6'); [l,n ]=quad(fx,0,1,1e-10)2 (1)global ki;ki=0;l=dblquad(@fxy,0,1,0,1)ki(2)f=in li ne('abs(cos(x+y))','x','y');匸dblquad(f,O,pi,O,pi)3X=0.3:0.2:1.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(s in (p), n)end5f=inlin e('si n(x)./(x+cos(2.*x))');g=i nlin e('(cos(x).*(x+cos(2*x))-si n(x).*(1-2.*si n(2*x)))/(x+cos(2.*x)).八2'); x=-pi:0.01:pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x); %求dp在假设点的函数值dx=diff(f([x,3.01]))/0.01; %直接对f(x)求数值导数gx=g(x); %求函数f的导函数g在假设点的导数plot(x,dpx,x,dx,'.',x,gx,'-'); %作图思考练习2format longfx=i nlin e('1./(1+x.A2)');[I, n]二quad(fx,-l nf,ln f,1e-10)[I, n]=quadl(fx,-I nf,ln f,1e-10) x=-100000:100000;y=1./(1+x.A2);trapz(x,y)format short3(1)format longfx=i nli ne('log(1+x).心+x.A2)');[l,n ]=quad(fx,0,1,1e-10)⑵format longfx=i nli ne('sqrt(cos(t.A2)+4*s in ((2吐).八2)+1)'); [I, n]=quad(fx,0,2*pi,1e-10)4f=in li ne('4.*x.*z.*exp(-z.A2.*y-x.A2)');匸triplequad(f,0,pi,0,pi,0,1)5f=in li ne('s in( x)');g=i nli ne('cos(x)');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;plot(x,dpx,x,dx,'.',x,gx,'-') unit8实验指导1syms x y;s=x A4-y A4;factor(s)factor(5135)2syms x;f=(x-2)/(xA2-4);Iimit(f,x,2)sym x;f=(sqrt(pi)-sqrt(acos(x)))/sqrt(x+1); limit(f,x,-1,'right')3sym x;f=si n(1/x);diff(f,'x')diff(f,'x',2)f=(1-cos(2*x))/x;diff(f,'x')diff(f,'x',2)4sym x;f=sqrt(exp(x)+1);in t(f,'x')syms x y;f=x/(x+y);in t(f,'y')sym x;f=exp(x)*(1+exp(x))八2;in t(f,'x',0,log(2))sym x;f=x*log(x);in t(f,'x',1,exp(1))5sym x;s=symsum((-1)八(x+1)/x,1,l nf) sym y;z=symsum(y A(2*y-1)/(2*y-1),1,I nf)6sym x;f1=(exp(x)+exp(-x))/2;f2=sqrt(xA3-2*x+1);(f1,x,5,0)(f2,x,6,0)7syms x y a;x=solve('xA3+a*x+1=0','x')x=solve('si n( x)+2*cos(x)-sqrt(x)=0','x')[x y]=solve('log(x/y)=9','exp(x+y)=3','x','y')syms n;[x,y]=dsolve('x*(D2y)+(1-n)*(Dy)+y=O','y(O)=O','Dy(O)=O','x') 思考练习2syms x B1 B2 a bs1=2*((cos(x))A2)-(si n(x))八2;s2=si n(B1)*cos(B2)-cos(B1)*si n(B2);s3二sqrt((a+sqrt(aA2-b))/2)+sqrt((a-sqrt(aA2-b))/2);s4=(4*xA2+8*x+3)/(2*x+1);h1=simplify(s1)h2=simplify(s2)h3=simplify(s3)h4=simplify(s4)3syms x a;f=abs(x)/x;limit(f,x,0,'left')f=(x+a/x)Ax;limit(f,x, inf)4syms x y m f=sqrt(x+sqrt(x+sqrt(x))); m=diff(f,'x') diff(m,'x') syms x y; f=x+y-sqrt(x A2+y A2);z1=diff(f,x)z2=diff(f,y)5syms x y; f=x+y-sqrt(xA2+yA2);z1=diff(f,x)z2=diff(f,y)sym x;f=1/(asi n(xF2*(1-xA2)A(1/2)); int(f)6syms xf=1/(1+x);in t(f,0,4)sym x;f=x A3*si n(xF2/(xA6+2*x%+1);in t(f,-1,1)sym x;f=xA3*si n(xF2/(xA6+2*xA4+1); in t(f,-1,1)7syms ns=symsum(1/4A n,1,i nf)sym n;s=symsum((( n+1)/n)A(1/2),1,i nf) eval(y)8syms xf=ta n( x);(f,x,3,0)syms xf=si n( x)A2;(f,x,5,0)9syms xx=solve('log(1+x)-5/(1+si n(x))=2','x')syms x y z[x yz]=solve('4*x A2/(4*x A2+1)=y','4*y A2/(4*y A2+1)=z','4*z A2/(4*z A2+1)=x','x','y','z')10[x ,y]=dsolve('Dx=3*x+4*y','Dy=5*x-7*y','x(0)=0','y(0)=1','t')。
MATLAB程序设计及应用(第二版)课后实验答案

Matlab 课后实验题答案实验一 MATLAB 运算基础1. 先求下列表达式的值,然后显示MATLAB 工作空间的使用情况并保存全部变量。
(1) 0122sin851z e=+(2) 21ln(2z x =,其中2120.455i x +⎡⎤=⎢⎥-⎣⎦(3) 0.30.330.3sin(0.3)ln , 3.0, 2.9,,2.9,3.022a a e e a z a a --+=++=--(4) 2242011122123t t z t t t t t ⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t =0:: 解:2. 已知:1234413134787,2033657327A B --⎡⎤⎡⎤⎢⎥⎢⎥==⎢⎥⎢⎥⎢⎥⎢⎥-⎣⎦⎣⎦求下列表达式的值:(1) A+6*B和A-B+I(其中I为单位矩阵)(2) A*B和A.*B(3) A^3和A.^3(4) A/B及B\A(5) [A,B]和[A([1,3],:);B^2]解:3. 设有矩阵A 和B1234530166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦ (1) 求它们的乘积C 。
(2) 将矩阵C 的右下角3×2子矩阵赋给D 。
(3) 查看MATLAB 工作空间的使用情况。
解:. 运算结果:4. 完成下列操作:(1) 求[100,999]之间能被21整除的数的个数。
(2) 建立一个字符串向量,删除其中的大写字母。
解:(1) 结果:(2). 建立一个字符串向量例如:ch='ABC123d4e56Fg9';则要求结果是:实验二 MATLAB 矩阵分析与处理1. 设有分块矩阵33322322E R A O S ⨯⨯⨯⨯⎡⎤=⎢⎥⎣⎦,其中E 、R 、O 、S 分别为单位矩阵、随机矩阵、零矩阵和对角阵,试通过数值计算验证22E R RS A O S +⎡⎤=⎢⎥⎣⎦。
MATLAB程序设计及应用(第二版)课后实验答案

MATLAB程序设计及应⽤(第⼆版)课后实验答案Matlab 课后实验题答案实验⼀ MATLAB 运算基础1. 先求下列表达式的值,然后显⽰MATLAB ⼯作空间的使⽤情况并保存全部变量。
(1) 0122sin851z e=+ (2) 221ln(1)2z x x =++,其中2120.455i x +??=??-?? (3) 0.30.330.3sin(0.3)ln , 3.0, 2.9,,2.9,3.022a a e e az a a --+=++=-- (4) 2242011122123t t z t t t t t ?≤,其中t =0:0.5:2.5 解:M ⽂件:z1=2*sin(85*pi/180)/(1+exp(2))x=[2 1+2*i;-.45 5];z2=1/2*log(x+sqrt(1+x^2)) 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) t=0:0.5:2.5;z4=(t>=0&t<1).*(t.^2)+(t>=1&t<2).*(t.^2-1)+(t>=2&t<3) .*(t.^2-2*t+1)2. 已知:1234413134787,2033657327A B --==-求下列表达式的值:(1) A+6*B 和A-B+I (其中I 为单位矩阵) (2) A*B 和A.*B (3) A^3和A.^3 (4) A/B 及B\A(5) [A,B]和[A([1,3],:);B^2] 解:M ⽂件:A=[12 34 -4;34 7 87;3 65 7];B=[1 3 -1;2 0 3;3 -2 7]; A+6.*BA-B+eye(3) A*B A.*B A^3 A.^3 A/B B\A [A,B][A([1,3],:);B^2]3. 设有矩阵A 和B1234166789101769,111213141502341617181920970212223242541311A B-???==-???(1) 求它们的乘积C 。
MATLAB程序设计与应用(第二版)课后实验答案

Matlab课后实验题答案实验一 MATLAB运算基础1. 先求下列表达式的值,然后显示MATLAB工作空间的使用情况并保存全部变量。
(1)0 122sin851ze =+(2)21ln(2z x=,其中2120.455ix+⎡⎤=⎢⎥-⎣⎦(3)0.30.330.3sin(0.3)ln, 3.0, 2.9,,2.9,3.0 22a ae e az a a--+=++=--(4)2242011122123t tz t tt t t⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t=0:0.5:2.52. 已知:1234413134787,2033657327A B --⎡⎤⎡⎤⎢⎥⎢⎥==⎢⎥⎢⎥⎢⎥⎢⎥-⎣⎦⎣⎦求下列表达式的值:(1) A+6*B 和A —B+I(其中I 为单位矩阵) (2) A*B 和A.*B (3) A^3和A.^3 (4) A/B 及B\A(5) [A,B ]和[A ([1,3],:);B^2] 解:3. 设有矩阵A 和B123453166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦(1) 求它们的乘积C 。
(2) 将矩阵C 的右下角3×2子矩阵赋给D 。
(3) 查看MATLAB 工作空间的使用情况。
4. 完成下列操作:(1) 求[100,999]之间能被21整除的数的个数。
(2) 建立一个字符串向量,删除其中的大写字母。
解:(1) 结果:(2).建立一个字符串向量 例如: ch='ABC123d4e56Fg9';则要求结果是:实验二 MATLAB 矩阵分析与处理1。
设有分块矩阵33322322E R A O S ⨯⨯⨯⨯⎡⎤=⎢⎥⎣⎦,其中E 、R 、O 、S 分别为单位矩阵、随机矩阵、零矩阵和对角阵,试通过数值计算验证22E R RS A OS +⎡⎤=⎢⎥⎣⎦。
MATLAB程序设计与应用(第二版)课后实验答案

Matlab课后实验题答案实验一 MATLAB运算基础1。
先求下列表达式的值,然后显示MATLAB工作空间的使用情况并保存全部变量。
(1)0 122sin851ze =+(2)21ln(2z x=,其中2120.455ix+⎡⎤=⎢⎥-⎣⎦(3)0.30.330.3sin(0.3)ln, 3.0, 2.9,,2.9,3.0 22a ae e az a a--+=++=--(4)2242011122123t tz t tt t t⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t=0:0.5:2。
52。
已知:1234413134787,2033657327A B --⎡⎤⎡⎤⎢⎥⎢⎥==⎢⎥⎢⎥⎢⎥⎢⎥-⎣⎦⎣⎦求下列表达式的值:(1) A+6*B 和A-B+I (其中I 为单位矩阵) (2) A*B 和A.*B (3) A^3和A.^3 (4) A/B 及B\A(5) [A ,B ]和[A ([1,3],:);B^2] 解:3. 设有矩阵A 和B123453166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦(1) 求它们的乘积C.(2) 将矩阵C 的右下角3×2子矩阵赋给D. (3) 查看MATLAB 工作空间的使用情况。
4. 完成下列操作:(1) 求[100,999]之间能被21整除的数的个数. (2) 建立一个字符串向量,删除其中的大写字母。
解:(1) 结果: (2). 建立一个字符串向量 例如:ch='ABC123d4e56Fg9';则要求结果是:实验二 MATLAB 矩阵分析与处理1。
设有分块矩阵33322322E R A O S ⨯⨯⨯⨯⎡⎤=⎢⎥⎣⎦,其中E 、R 、O 、S 分别为单位矩阵、随机矩阵、零矩阵和对角阵,试通过数值计算验证22E R RS A OS +⎡⎤=⎢⎥⎣⎦。
(完整word版)MATLAB程序设计及应用(第二版)课后实验答案

Matlab 课后实验题答案实验一 MATLAB 运算基础1。
先求下列表达式的值,然后显示MATLAB 工作空间的使用情况并保存全部变量。
(1) 0122sin851z e =+ (2)21ln(2z x =,其中2120.455i x +⎡⎤=⎢⎥-⎣⎦ (3) 0.30.330.3sin(0.3)ln , 3.0, 2.9,,2.9,3.022a a e e az a a --+=++=--(4) 2242011122123t t z t t t t t ⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t =0:0。
5:2。
52。
已知:1234413134787,2033657327A B --⎡⎤⎡⎤⎢⎥⎢⎥==⎢⎥⎢⎥⎢⎥⎢⎥-⎣⎦⎣⎦求下列表达式的值:(1) A+6*B 和A —B+I (其中I 为单位矩阵) (2) A*B 和A 。
*B (3) A^3和A.^3 (4) A/B 及B\A(5) [A,B ]和[A ([1,3],:);B^2]3。
设有矩阵A 和B1234530166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦(1) 求它们的乘积C.(2) 将矩阵C 的右下角3×2子矩阵赋给D 。
(3) 查看MATLAB 工作空间的使用情况。
4. 完成下列操作:(1) 求[100,999]之间能被21整除的数的个数。
(2) 建立一个字符串向量,删除其中的大写字母。
(2). 建立一个字符串向量 例如:ch=’ABC123d4e56Fg9';则要求结果是:实验二 MATLAB 矩阵分析与处理1. 设有分块矩阵33322322E R A O S ⨯⨯⨯⨯⎡⎤=⎢⎥⎣⎦,其中E 、R 、O 、S 分别为单位矩阵、随机矩阵、零矩阵和对角阵,试通过数值计算验证22E R RS A O S +⎡⎤=⎢⎥⎣⎦。
MATLAB程序设计与应用(第二版)课后实验答案

Matlab 课后实验题答案实验一 MATLAB 运算基础1. 先求下列表达式的值,然后显示MATLAB 工作空间的使用情况并保存全部变量。
(1) 0122sin851z e=+ (2) 221ln(1)2z x x =++,其中2120.455i x +⎡⎤=⎢⎥-⎣⎦ (3) 0.30.330.3sin(0.3)ln , 3.0, 2.9,,2.9,3.022a a e e az a a --+=++=--(4) 2242011122123t t z t t t t t ⎧≤<⎪=-≤<⎨⎪-+≤<⎩,其中t =0:0.5:2.5 解:M 文件:z1=2*sin(85*pi/180)/(1+exp(2))x=[2 1+2*i;-.45 5];z2=1/2*log(x+sqrt(1+x^2)) 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) t=0:0.5:2.5;z4=(t>=0&t<1).*(t.^2)+(t>=1&t<2).*(t.^2-1)+(t>=2&t<3) .*(t.^2-2*t+1)2. 已知:1234413134787,2033657327A B --⎡⎤⎡⎤⎢⎥⎢⎥==⎢⎥⎢⎥⎢⎥⎢⎥-⎣⎦⎣⎦求下列表达式的值:(1) A+6*B 和A-B+I (其中I 为单位矩阵) (2) A*B 和A.*B (3) A^3和A.^3 (4) A/B 及B\A(5) [A,B]和[A([1,3],:);B^2] 解:M 文件:A=[12 34 -4;34 7 87;3 65 7];B=[1 3 -1;2 0 3;3 -2 7]; A+6.*BA-B+eye(3) A*B A.*B A^3 A.^3 A/B B\A [A,B][A([1,3],:);B^2]3. 设有矩阵A 和B123453166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦(1) 求它们的乘积C 。
MATLAB程序设计及应用(第二版)课后实验答案(最新整理)

阵和对角阵,试通过数值计算验证。
22E R RS A OS +⎡⎤=⎢⎥⎣⎦解: M 文件如下;由ans,所以22E R RS A O S +⎡⎤=⎢⎥⎣⎦2. 产生5阶希尔伯特矩阵H 和5阶帕斯卡矩阵P ,且求其行列式的值Hh 和Hp 以及它们的条件数Th 和Tp ,判断哪个矩阵性能更好。
为什么?解:M 文件如下:因为它们的条件数Th>>Tp,所以pascal 矩阵性能更好。
3. 建立一个5×5矩阵,求它的行列式值、迹、秩和范数。
解: M 文件如下:4. 已知2961820512885A -⎡⎤⎢⎥=⎢⎥⎢⎥-⎣⎦求A 的特征值及特征向量,并分析其数学意义。
解:M 文件如图:数学意义:V的3个列向量是A的特征向量,D的主对角线上3个是A的特征值,特别的,的3个列向量分别是D的3个特征值的特征向量。
5. 下面是一个线性方程组:111⎡⎤输出结果:由结果,X和X2的值一样,这表示b的微小变化对方程解也影响较小,而A的条件数算得较小,所以数值稳定性较好,A是较好的矩阵。
6. 建立A矩阵,试比较sqrtm(A)和sqrt(A),分析它们的区别。
解:M文件如下:分析结果知:sqrtm(A)是类似A的数值平方根(这可由b1*b1=A的结果看出),而sqrt(A)则是对A中的每个元素开根号,两则区别就在于此。
实验三 选择结构程序设计1. 求分段函数的值。
2226035605231x x x x y x x x x x x x ⎧+-<≠-⎪=-+≤<≠≠⎨⎪--⎩且且及其他用if 语句实现,分别输出x=-5.0,-3.0,1.0,2.0,2.5,3.0,5.0时的y 值。
解:M文件如下:2. 输入一个百分制成绩,要求输出成绩等级A 、B 、C 、D 、E 。
其中90分~100分为A ,80分~89分为B ,79分~79分为C ,60分~69分为D ,60分以下为E 。
要求:(1) 分别用if 语句和switch 语句实现。
Matlab程序设计教程(第二版)课后参考答案

Matlab程序设计教程(第二版)课后参考答案第一章实验1.实验一第1题2.自己验证总结Matlab的主要优点3.实验一第2题4.实验一第3题5.网站思考练习1.启动见书P5 退出见书P62.Matlab主要功能见书P2 4种功能3.分行输入行末尾加续行符,即三个点“…”4.见书P115.直接在命令窗口输入fac第二章实验1.(1) w=sqrt(2)*(1+0.34245*10^(-6))w = 1.4142(2) a=3.5;b=5;c=-9.8;x=(2*pi*a+(b+c)/(pi+a*b*c)-exp(2))/(tan(b+c)+a)x =0.9829(3) a=3.32;b=-7.9;y=2*pi*a^2*((1-pi/4)*b-(0.8333-pi/4)*a)y = -128.4271(4) t=[2,1-3i;5,-0.65];z=0.5*exp(2*t)*log(t+sqrt(1+t.*t))z =1.0e+004 *0.0048 + 0.0002i 0.0048 - 0.0034i1.58992.0090 - 1.3580i2.实验二第1题3.实验二第2题4. H=hilb(5);P=pascal(5);Hh=det(H)Hh = 3.7493e-012Hp=det(P)Hp = 1Th=cond(H)Th = 4.7661e+005Tp=cond(P)Tp = 8.5175e+003条件数越趋近于1,矩阵的性能越好,所以帕斯卡矩阵性能更好。
5. A=[-29,6,18;20,5,12;-8,8,5]A =-29 6 1820 5 12-8 8 5[V,D]=eig(A)V =0.7130 0.2803 0.2733-0.6084 -0.7867 0.87250.3487 0.5501 0.4050D =-25.3169 0 00 -10.5182 00 0 16.8351V为A的特征向量,D为A的特征值。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MATLAB第二版课后答案unit3-8 unit3实验指导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('请输入成绩');switch ncase num2cell(90:100)p='A';case num2cell(80:89)p='B';case num2cell(70:79)p='C';case num2cell(60:69)p='D';otherwisep='E';endprice=p(2)n=input('请输入成绩');if n>=90&n<=100p='A';elseif n>=80&n<=89p='B';elseif n>=70&n<=79p='C';elseif n>=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];b=n(1);for m=2:20if n(m)>aa=n(m);elseif n(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];for n=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的值:');for i=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的值:');if n<=5&n>=0disp(A([n],:));elseif n<0disp(lasterr);else disp(A([6],:));disp(lasterr);end7(1)f=[];f(n)=n+10*log(n^2+5);endy=f(40)/(f(30)+f(20))(2)f=[];a=0;for n=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值:');for i=1:ny=y+i^m;endy************************************************************ function s=shi8_1(n,m)s=0;for i=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;for i=1:20if s(i)<y&rem(s(i),2)==0j=j+1;A(j)=s(i);else continue;endendA4y1=0;y2=0;n=input('请输入n的值:'); for i=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]); grid on;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);grid on;(2)[x,y]=meshgrid(-5:5);z=zeros(11)+5;mesh(x,y,z);shading interp;5[x,y,z]=sphere(20);surf(x,y,z);axis off;shading interp;m=moviein(20);for i=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);grid on;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);hold on;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('ji suan zhi : ');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;for i=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)function fx=funx1(x)fx=x^41+x^3+1;(2)x2=fzero(@funx2,0.5)function fx=funx2(x)fx=x-sin(x)/x;(3)options=optimset('Display','off');x=fsolve(@fun3,[1,1,1]',options)q=fun3(x)function q=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'function yp=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'function yp=fun5(t,y)yp=cos(t)-y/(1+t^2);4x=fminbnd(@mymin,0,2);-mymin(x)function fx=mymin(x)fx=-(1+x.^2)/(1+x.^4);5options=optimset('Display','off');[x,fval]=fmincon(@fun6,[0,0,0],[],[],a,b,lb,ub)-fvalfunction f=fun6(x)f=-(sqrt(x(1))+(400-x(1))*1.1+(sqrt(x(2))+(400-x(1))*1.1-x(2))*1.1+sqrt(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=A\B[L,U]=lu(A);x=U\(L\B)(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=A\B[L,U]=lu(A);x=U\(L\B)2(1)x1=fzero(@funx1,1.5)function fx=funx1(x)fx=3*x+sin(x)-exp(x);(2)x1=fzero(@funx2,1)function fx=funx2(x)fx=x-1/x+5;(3)options=optimset('Display','off');x=fsolve(@fun3,[3,0]',options)q=fun3(x)function q=fun3(p)x=p(1);y=p(2);q(1)=x^2+y^2-9;q(2)=x+y-1;3(1)t0=0;tf=5;y0=[0,1];[t,y]=ode45(@vdpol,[t0,tf],y0);[t,y]function ydot=vdpol(t,y);ydot(1)=(2-3*y(2)-2*t*y(1))./(1+t^2);ydot(2)=y(1);ydot=ydot';(2)t0=0;tf=5;y0=[1;0;2];[t,y]=ode45(@vdpoll,[t0,tf],y0);[t,y]function ydot=vdpoll(t,y);ydot(1)=cos(t)-y(3)./(3+sin(t))+5*y(1).*cos(2*t)/((t+1).^2)-y(2); ydot(2)=y(1);ydot(3)=y(2);ydot=ydot';4x=fminbnd(@mymin,0,pi);-mymin(x)function fx=mymin(x)fx=-sin(x)-cos(x.^2);5[x,y1]=fminbnd(@mymax,0,1.5);-y1function fx=mymax(x);fx=-(9*x+4*x.^3-12*x.^2);unit7实验指导1(1)format longfx=inline('sin(x)./x');[I,n]=quadl(fx,0,2,1e-10)(2)format longfx=inline('1./((x-0.3).^2+0.01)-1./((x-0.9).^2+0.04)-6');[I,n]=quad(fx,0,1,1e-10)2(1)global ki;ki=0;I=dblquad(@fxy,0,1,0,1)ki(2)f=inline('abs(cos(x+y))','x','y');I=dblquad(f,0,pi,0,pi)3X=0.3:0.2:1.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:3nDX=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)).^2');x=-pi:0.01:pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x); %求dp在假设点的函数值dx=diff(f([x,3.01]))/0.01; %直接对f(x)求数值导数gx=g(x); %求函数f的导函数g在假设点的导数plot(x,dpx,x,dx,'.',x,gx,'-'); %作图思考练习2format longfx=inline('1./(1+x.^2)');[I,n]=quad(fx,-Inf,Inf,1e-10)[I,n]=quadl(fx,-Inf,Inf,1e-10)x=-100000:100000;y=1./(1+x.^2);trapz(x,y)format short3(1)format longfx=inline('log(1+x)./(1+x.^2)');[I,n]=quad(fx,0,1,1e-10)(2)format longfx=inline('sqrt(cos(t.^2)+4*sin((2*t).^2)+1)'); [I,n]=quad(fx,0,2*pi,1e-10)4f=inline('4.*x.*z.*exp(-z.^2.*y-x.^2)');I=triplequad(f,0,pi,0,pi,0,1)5f=inline('sin(x)');g=inline('cos(x)');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实验指导1syms x y;s=x^4-y^4;factor(s)factor(5135)2syms x;f=(x-2)/(x^2-4);limit(f,x,2)sym x;f=(sqrt(pi)-sqrt(acos(x)))/sqrt(x+1);limit(f,x,-1,'right')3sym x;f=sin(1/x);diff(f,'x')diff(f,'x',2)sym x;f=(1-cos(2*x))/x;diff(f,'x')diff(f,'x',2)4sym x;f=sqrt(exp(x)+1);int(f,'x')syms x y;f=x/(x+y);int(f,'y')sym x;f=exp(x)*(1+exp(x))^2;int(f,'x',0,log(2))sym x;f=x*log(x);int(f,'x',1,exp(1))5sym x;s=symsum((-1)^(x+1)/x,1,Inf)sym y;z=symsum(y^(2*y-1)/(2*y-1),1,Inf)6sym x;f1=(exp(x)+exp(-x))/2;f2=sqrt(x^3-2*x+1);taylor(f1,x,5,0)taylor(f2,x,6,0)7syms x y a;x=solve('x^3+a*x+1=0','x')x=solve('sin(x)+2*cos(x)-sqrt(x)=0','x')[x y]=solve('log(x/y)=9','exp(x+y)=3','x','y')8syms n;[x,y]=dsolve('x*(D2y)+(1-n)*(Dy)+y=0','y(0)=0','Dy(0)=0','x')思考练习2syms x B1 B2 a bs1=2*((cos(x))^2)-(sin(x))^2;s2=sin(B1)*cos(B2)-cos(B1)*sin(B2);s3=sqrt((a+sqrt(a^2-b))/2)+sqrt((a-sqrt(a^2-b))/2); s4=(4*x^2+8*x+3)/(2*x+1);h1=simplify(s1)h2=simplify(s2)h3=simplify(s3)h4=simplify(s4)3syms x a;f=abs(x)/x;limit(f,x,0,'left')f=(x+a/x)^x;limit(f,x,inf)4syms x y mf=sqrt(x+sqrt(x+sqrt(x)));m=diff(f,'x')diff(m,'x')syms x y;f=x+y-sqrt(x^2+y^2);z1=diff(f,x)z2=diff(f,y)5syms x y;f=x+y-sqrt(x^2+y^2);z1=diff(f,x)z2=diff(f,y)sym x;f=1/(asin(x)^2*(1-x^2)^(1/2));int(f)6syms xf=1/(1+x);int(f,0,4)sym x;f=x^3*sin(x)^2/(x^6+2*x^4+1);int(f,-1,1)sym x;f=x^3*sin(x)^2/(x^6+2*x^4+1);int(f,-1,1)7syms ns=symsum(1/4^n,1,inf)sym n;s=symsum(((n+1)/n)^(1/2),1,inf)eval(y)8syms xf=tan(x);taylor(f,x,3,0)syms xf=sin(x)^2;taylor(f,x,5,0)9syms xx=solve('log(1+x)-5/(1+sin(x))=2','x')syms x y z[x y z]=solve('4*x^2/(4*x^2+1)=y','4*y^2/(4*y^2+1)=z','4*z^2/(4*z^2+1)=x','x','y','z') 10[x ,y]=dsolve('Dx=3*x+4*y','Dy=5*x-7*y','x(0)=0','y(0)=1','t')。