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

合集下载

(完整word版)MATLAB程序设计教程(第二版)课后答案

(完整word版)MATLAB程序设计教程(第二版)课后答案

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]; 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];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。

matlab程序设计(第二版)课后作业答案

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程序设计教程课后答案.doc

MATLAB程序设计教程课后答案.doc

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(' 请输入成绩 '); ifn>=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)try n;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];min=min(n)max=max(n)4b=[::];for n=1:61a=b(n);y(n)=(exp*a)-exp*a))/2*sin(a++log(+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=[];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^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::10;y=x-x.^3./6;plot(x,y)(2)x=-10::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::5;y=(1./(2*pi)).*exp((-(x.^2))/2); plot(x,y);(2)t=-2*pi::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.*;plot(x,y1,'k',x,y2);hold on;k=find(abs(y1-y2)<1e-2);x1=x(k);y3=2.*;plot(x1,y3,'rp');4x=-2::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::10;j=12./sqrt(i);polar(i,j);title('{\rho}=12/sqrt(\theta)')(2)a=-pi/6::pi/6;b=3.*asin(a).*cos(a)./((sin(a)).^3+(cos(a)).^3); polar(a,b);6( 1)[u,v]=meshgrid(-4::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::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,,;,2,;0,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)>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,,,,,,,,,,];[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=[,,]';x=A\pA=[1/2,1/3,1/4;1/3,1/4,1/5;1/4,1/5,1/6]; p=[,,]';x=A\pcond(A)2( 1)x1=fzero(@funx1,-1)function fx=funx1(x)fx=x^41+x^3+1;(2)x2=fzero(@funx2,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=-+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))*+(sqrt(x(2))+(400-x(1))*(2))*+sqrt(3)+(((400-x(1) )*(2))*(3))*+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,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,;-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./(.^2+-1./(.^2+-6');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=::;F=[,,,,,,];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::pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x);%dx=diff(f([x,]))/; %直接对gx=g(x);%plot(x,dpx,x,dx,'.',x,gx,'-');%求 dp 在假设点的函数值f(x) 求数值导数求函数 f 的导函数作图g 在假设点的导数思考练习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)');(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::2*pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x);dx=diff(f([x,2*pi+]))/;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程序设计教程第二版课后答案

end A 4 y1=0;y2=0; n=input('请输入 n 的值:'); for i=1:n
y1=y1+-(-1)^i/(2*i-1); y2=y2+1/4^i; end y1 y2 unit4 实验指导 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; 2 t=-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)
p='A'; case num2cell(80:89)
p='B'; case num2cell(70:79)
p='C'; case num2cell(60:69)

(完整word版)MATLAB程序设计与应用第二版课后题答案2

(完整word版)MATLAB程序设计与应用第二版课后题答案2

第二章3.设矩阵A为A=[24 23 9 21 6;65 74 24 11 21;34 5 98 75 21;8 42 42 53 121;43 21 45 64 21];(1)B=A(2:5,1:2:5)B =65 24 2134 98 218 42 12143 45 21(2)A(7)=[]A =24 65 34 8 43 23 5 42 21 9 24 98 42 45 21 11 75 53 64 6 21 21 121 21(3)A+30(4)size(A);ndims(A)(5)题目有误(6)reshape(x,3,4)(7)abs(x)(8)char(x)4. L1 =0 0 0 0 1 0 0 0 0L2 =1 1 1 1 1 0 0 0 0L3 =0 0 0 1 1 1 0 0 0L4 =4 5 65.(1)B=A(1:3,:)C=A(:,1:2)D=A(2:4,3:4)E=B*CB =23.0000 10.0000 -0.7780 041.0000 -45.0000 65.0000 5.000032.0000 5.0000 0 32.0000C =23.0000 10.000041.0000 -45.000032.0000 5.00006.0000 -9.5400D =65.0000 5.00000 32.000054.0000 3.1400E =1.0e+003 *0.9141 -0.22391.20802.71231.1330 -0.2103(2)E<Dans =0 10 00 1E&Dans =1 10 11 1E|Dans =1 11 11 1~D|~Eans =0 01 00 0find(A>=10&A<25)ans =156.all(A)ans =any(A)ans =1isnan(A)ans =0 1 0 0 0 0 0isinf(A)ans =0 0 1 1 0 0 0isfinite(A)ans =1 0 0 0 1 1 17.A(1).x1=’学号’;A(1).x2=’姓名’;A(1).x3=’专业’;A(1).x4.x41=’成绩1’;………. A(2).x1=’学号’;A(2).x2=’姓名’;A(2).x3=’专业’;A(2).x4.x41=’成绩1’;………. A(3).x1=’学号’;A(3).x2=’姓名’;A(3).x3=’专业’;A(3).x4.x41=’成绩1’;………. A(4).x1=’学号’;A(4).x2=’姓名’;A(4).x3=’专业’;A(4).x4.x41=’成绩1’;………. A(5).x1=’学号’;A(5).x2=’姓名’;A(5).x3=’专业’;A(5).x4.x41=’成绩1’;……….8.(1)size(B)ans =2 2ndims(B)ans =2(2)B(2)ans =[3x3 doubleB(4)ans ={3x3 cell}(3)B(3)=[]B =[1] [3x3 double] {3x3 cell}B{3}=[]B =[1] [3x3 double] []第三章1.(1)A=eye(3)(2) A=100+100*rand(5,6)(3)A=1+sqrt(0.2)*randn(10,50)(4)B=ones(size(A))(5)A+30*eye(size(A))(6)B=diag(diag(A))2.B=rot90(A)C=rot90(A,-1)3.B=inv(A) ;A的逆矩阵C=det(A) ;A的行列式的值D=A*BE=B*AD=E 因此A与A-1是互逆的。

MATLAB程序设计教程(第二版)课后答案

MATLAB程序设计教程(第二版)课后答案

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运算基础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程序设计教程(第二版)课后答案3-8

MATLAB程序设计教程(第二版)课后答案3-8

MA TLAB 第二版课后答案unit2-8第二章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|~Dunit3 实验指导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('请输入成绩'); 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'; otherwise p='E'; endprice=p(2)n=input('请输入成绩'); if n>=90&n<=100 p='A';elseif n>=80&n<=89 p='B';elseif n>=70&n<=79 p='C';elseif n>=60&n<=69 p='D'; elsep='E'; end price=p (3)try n; 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];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)+l og((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)));endy1y27(1)f=[];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^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)unit4实验指导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);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)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,l b,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)));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,'-'); %作图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',2sym 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')[xy]=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')。

matlab程序设计(第二版)课后作业答案

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 函数给图形加上插图说明。

(完整word版)MATLAB程序设计及应用(第二版)课后实验答案

(完整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 求下列表达式的值。

(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)第三章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');otherwise第四章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题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];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程序设计与应用第二版课后题答案2(可编辑修改word版)

MATLAB程序设计与应用第二版课后题答案2(可编辑修改word版)

第二章3.设矩阵A 为A=[24 23 9 21 6;65 74 24 11 21;34 5 98 75 21;8 42 42 53 121;43 21 45 64 21];(1)B=A(2:5,1:2:5)B =65 24 2134 98 218 42 12143 45 21(2)A(7)=[]A =24 65 34 8 43 23 5 42 21 9 24 98 42 45 21 11 75 53 64 6 21 21 121 21(3)A+30(4)size(A);ndims(A)(5)题目有误(6)reshape(x,3,4)(7)abs(x)(8)char(x)4. L1 =0 0 0 0 1 0 0 0 0L2 =1 1 1 1 1 0 0 0 0L3 =0 0 0 1 1 1 0 0 0L4 =4 5 65.(1)B=A(1:3,:)C=A(:,1:2)D=A(2:4,3:4)E=B*CB =23.0000 10.0000 -0.7780 041.0000 -45.0000 65.0000 5.000032.0000 5.0000 0 32.0000C =23.0000 10.000041.0000 -45.000032.0000 5.00006.0000 -9.5400D =65.0000 5.00000 32.000054.0000 3.1400E =1.0e+003 *0.9141 -0.22391.20802.71231.1330 -0.2103(2)E<Dans =0 10 00 1E&Dans =1 10 11 1E|Dans =1 11 11 1~D|~Eans =0 01 00 0find(A>=10&A<25)ans =156.all(A)ans =any(A)ans =1isnan(A)ans =0 1 0 0 0 0 0isinf(A)ans =0 0 1 1 0 0 0isfinite(A)ans =1 0 0 0 1 1 17.A(1).x1=’学号’;A(1).x2=’姓名’;A(1).x3=’专业’;A(1).x4.x41=’成绩1’;………. A(2).x1=’学号’;A(2).x2=’姓名’;A(2).x3=’专业’;A(2).x4.x41=’成绩1’;………. A(3).x1=’学号’;A(3).x2=’姓名’;A(3).x3=’专业’;A(3).x4.x41=’成绩1’;………. A(4).x1=’学号’;A(4).x2=’姓名’;A(4).x3=’专业’;A(4).x4.x41=’成绩1’;………. A(5).x1=’学号’;A(5).x2=’姓名’;A(5).x3=’专业’;A(5).x4.x41=’成绩1’;……….8.(1)size(B)ans =2 2ndims(B)ans =2(2)B(2)ans =[3x3 doubleB(4)ans ={3x3 cell}(3)B(3)=[]B =[1][3x3 double] {3x3 cell}B{3}=[]B =[1] [3x3 double] []第三章1.(1)A=eye(3)(2) A=100+100*rand(5,6)(3)A=1+sqrt(0.2)*randn(10,50)(4)B=ones(size(A))(5)A+30*eye(size(A))(6)B=diag(diag(A))2.B=rot90(A)C=rot90(A,-1)3.B=inv(A) ;A 的逆矩阵C=det(A) ;A 的行列式的值D=A*BE=B*AD=E 因此A 与A-1 是互逆的。

Matlab程序设计教程(第二版)课后参考答案

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的特征值。

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 和B123453166789101769,111213141502341617181920970212223242541311A B ⎡⎤⎡⎤⎢⎥⎢⎥-⎢⎥⎢⎥⎢⎥⎢⎥==-⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎢⎥⎣⎦⎣⎦(1) 求它们的乘积C 。

MATLAB程序设计及应用(第二版)课后实验答案

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程序设计教程(第二版)课后答案(20210119130626)

MATLAB程序设计教程(第二版)课后答案(20210119130626)

MATLAB程序设计教程(第二版)课后答案-CAL-FENGHAI-(2020YEAR-YICAI) JINGBIANMATLAB第二版课后答案unit3-8unit3实验指导lx 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&*=100p='A';else讦n>=80&*=89P-B';elseif n>=70&nv=79p-c;elseif n>=60&nv=69P='D';elseP='E';endprice=p(3)tryn;catchprice=,erroe,end3n=[l,5,56,4,3,476,45,6,3,76,45,6,4,3,6,4,23,76,908,6];a=n(l);b=n(l);for m=2:20讦n(m)>aa=n(m);else讦n(m)<bb=n(m);endendmax=amin=b法20=(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=[::];for n=l:61a=b(n);y(n)=(exp*a)-exp*a))/2*sin(a++log(+a)/2);endy5yi=o;y2=i;n=input('请输入n的值:’);for i=l:nyl=yl+l/i A2;y2=y2*((4*i*i)/((2*i-l)*(2*i+l)));endyiy26A=[l,l,m,l;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的值J);if n<=5&n>=0disp(A([n]z:));else讦n<0disp(lasterr);else disp(A([6],:));disp(lasterr);end7 (1)f=[];for n=l:40 f(n)=n+10*log(n A2+5);end y=f(40)/(f(30)+f(20))(2)f=[];a=O;for n=l:40f(n)=a+n*(n+l); a 二f(n);endy=f(40)/(f(30)+f(20))8y=o;m=input『输入m的值:1); n=input('输入n值:匕for i=l:ny=y+i A m;end********* 沐)|(**4(*4(*4(>|(床床穴床床 ******** 沐末床床床穴末穴穴*4(******)»(4cH(沐function s=shi8_l(n,m) s=0;for i=l:ns=s+i A m;end******床审水沐审审沐璟*****末中末4c穴末穴末沐床床床床床水沐审审沐璟才卡末穴穴床中末穴************shi8_l(100/l)+shi8_l(50,2)+shi8_l(10/l/2)思聶练习2N珂1,2,3,4,5];2.*NN./2l./Nl./N •八23s=fix(100*rand(l,20)*9/10+10)y=sum ⑸/20j=o;for i=l:20if s(i)<y&rem(s(i)/2)==0j=j+l;A(j)=s(i);else continue;endendA4yl=0;y2=0;n=input('iW输入n 的值:’); for i=l:nyl=yl+-(-l)A i/(2*i-l); y2=y2+l/4A i;endyiy2unit4实验指导1(1)x=-10::10;y=x-x.A3./6;Plot(x’y)(2)x=-10::10;ezplot(I x A2+2*y A2-64,/[-8,8]); grid on;2t=-pi:pi/10:pi; y=l./(l+exp(-t));subplot(221);bar(t,y);title,条形图(t,y)J;axis(卜pi’piOl]);subplot(2,2,2);stairsf^y/b');title,阶梯图(t,y)J; axis(卜pi’piQJ]);subplot(2,2,3); stem(t,y/k'); titleC 杆图(t 別); axis(卜pi,piQJ]); subplot(2z2,4);loglogft.y/y');title('对数坐标图(t,y门;3(1) t=0:pi/50:2*pi; r=5.*cos(t)+4;polar(tj);title('\rho=5*cos\theta+4,);(2)t=-pi/3:pi/50:pi/3; r=5.*((sin(t)).A2)./cos(t); polar(tj);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(ll)+5;mesh(x,y/z);shadi ng in terp;5[x,y,z]=sphere(20); surf(x,y,z);axis off;shading interp; m=moviein(20); for i=l:20axis(卜i"i,i 凡i]) m(:,i)=getframe;endmovie(m,4);思考练习2(1)x=-5::5;y=(l./(2*pi)).*exp((-(x.A2))/2); plot(x’y);(2) t=-2*pi::2*pi; x=t.*sin(t); y=t.*cos(t); plot(x’y); grid on;3 t=0:pi/1000:pi; x=sin(3.*t).*cos(t);yl=sin(3.*t).*sin(t); y2=2.*;plot(x/yl,,k,,x/y2);hold on;k=find(abs(yl-y2)<le-2);xl=x(k);y3=2.*;plot(xl,y3;rp,);4x=-2::2;y=sin(l./x);subplot(2,l,l);plot(x’y);subplot(2 几2);fplot('sin(l./x)',[-2,2],le-4);4(1)i=-4*pi::10;j=12./sqrt(i);Polar(iJ);title(,{\rho}=12/sqrt(\theta)1)(2)a=-pi/6::pi/6;b=3.*asin(a).*cos(a)./( (sin (a)).A3+(cos(a)).A3); polar(a,b); 5(1)[u,v]=meshgrid(-4::4);x=3.*u.*sin(v);y=2.*u.*cos(v);z=4.*u.A2;subplot(2JJ);mesh(x,y/z);subplot(2,l,2);surf(xMZ);(2)[x,y]=meshgrid(-3::3);z=-5./(l+x.A2+y.A2);subplot(l/2,l);mesh(x,y,z);subplot(l/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(Sumha ng)B=sort(A);C=sort(B,2,'descend');C2 (1) a=0:15:90; b=a./180.*pi;s=si n(b) c=0:15:75; d=c./180.*pi;t=tan(d)e=input('iW输入想计算的值:');S=sin(e/180*pi)T=tan(e/180*pi)Sl=interpl(a,s/e/spli ne")Tl=interpl(c/t/e/,spline1)Pl=polyfit(a,s/5);P2=polyfit(c/t,5);S2=polyval(Pl,e)T2=polyval(P2,e)(2) 0=(1,9,16,25,36,49,64,81,100]; N=sqrt(n); x=inputfji suan zhi :'); interplfn^N^x/cubic')3N=64;T=5;t=linspace(0,T,N); h=exp(-t);dt=t(2)-t(l); f=l/dt;X=fft(t);F=X(l:N/2+l); f=f*(0:N/2)/N; plot(f,abs(F),“)4P=[2z-3/0,5/13];Q=[l,5,8]; p=polyder(P) q=polyder(P,Q)[a,b]=polyder(P,Q)5P1=[1,2/4/0Z5];P2=[0,l,2];P3=[l,2,3];P=Pl+conv(P2,P3)X=roots(P)A=[-l〃;,2,;0,5,];p=polyval(P,A)思考练习4A=rand(l z30000);a=mean(A)b=std(A)Max=max(A)Min=min(A)n=0;for i=l:30000if(A(i)>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)jun zhi=mean(p,l)fangcha=std(p,l/l)zong=sum(p,2);[Max,wei]=max(z ong)[Min,wei]=min(zong)[zcj/xsxh]=sort(zong/descend,)6x=[l:10:101];y二[0〃””];[p,s]=polyfit(x,y/5)a=l:5:101;yl=polyval(p,a);unit6实验指导1A=[l/2,1/3,1/4; 1/3,1/4,1/5; 1/4,1/5,1/6];P=[J';x=A\pA=[ 1/2,1/34/4; 1/3,1/4,1/5; 1/4,1/5,1/6];P=[〃]';x=A\pcond(A)2 (1)xl=fzero(@funxl z-l)function fx=funxl(x) fx=x A41+x A3+l;(2) x2=fzero(@funx2, function fx=funx2(x) fx=x-sin(x)/x;(3) options=optimset(,Display,/off,); x=fsolve(@fun3,[l/l,l],/options)q=fun3(x)function q=fun3(p)x=p ⑴;y=p(2);z=p(3); q(l)=sin(x)+y A2+log (z)-7; q(2)=3*x+2A y-z A3+l;q(3)=x+y+z-5;3 (1)to=o;tf=5;yo=i;[t/y]=ode23(@fun4,[t0/tf]/y0);t'y; .......................function yp=fun4(t,y)yp=-+sin(10*t))*y;(2)to=o;tf=5;yo=i;[t/y]=ode23(@fun5z[t0/tf]/y0);t'y1funct:ion yp=fun5(t,y)yp=cos(t)-y/(l+t A2);4x=fminbnd(@mymin,0/2);-mymin(x)function fx=mymin(x)fx=-(l+x.A2)/(l+x.A4);5options=optimset(,Display,/off,);[x,fval]=fmincon(@fun6/[0,0,0],[]/[]/a,b,lb,ub)-fvalfunction f=fun6(x)f=-(sqrt(x(l))+(400-x(l))*+(sqrt(x(2))+(400-x(l))*(2))*+sqrt(3)+(((400- x(l))*(2) )*(3))*+sqrt(x(x4)));思考练习1 (1)A=[2,3,5;3,7,4;l,-7,1];B 珂10,3,5]';Cl=inv(A)*BC2=A\B[L,U]=I U(A);x=U\(L\B)(2)A=[6,5,-2,5;9,-l,4,-l;3,4,2,-2;3,-9,0,2];B^I-4,13,141]1;Cl=inv(A)*BC2=A\B[L,U]=I U(A);x=U\(L\B)2 (1)xl=fzero(@funxl,function fx=funxl(x)fx=3*x+sin(x)-exp(x);(2)xl=fzero(@funx2,l)function fx二funx2(x)fx=x-l/x+5;(3)options=optimset(,Display,/off,);x=fsolve(@fun3,[3,0],/options)q=fun3(x)function q=fun3(p)x=p(l);尸p⑵;q(l)=x A2+y A2-9;q(2)=x+y-l;3(1)to=o;tf=5;yo=[o z i];[t/y]=ode45(@vdpol,[t0,tf],y0);[t,y]B ................................................................................................ funct:ion ydot=vdpol(t,y);ydot(l)=(2-3*y ⑵・2末广y ⑴)・/(l+t 八2);ydot(2)=y(l);ydot=ydot';(2)to=o;tf=5;yo=[i;o;2];[t/y]=ode45(@vdpoll,[t0,tf],y0);Ky]function ydot=vdpoll(t,y);ydot(l)=cos(t)-y(3)./(3+sin(t))+5*y(l).*cos(2*t)/((t+l).A2)-y(2); ydot(2)=y(l); ydot(3)=y(2);ydot=ydot,;4x=fminbnd(@mymin,O,pi);-mymin(x)function fx=mymin(x)fx=-sin(x)-cos(x.A2);5[x,yl]=fminbnd(@mymax,O z;-yi .................................................................................................... function fx=mymax(x);fx=-(9*x+4*x.A3-12*x.A2);unit7实验指导1 (1)format longfx=inline('sin(x)./x');[l/n]=quadl(fx/0z2/le-10)(2)format longfx=inline(l l./(.A2+-l./(.A2+-6,);[l/n]=quad(fx,0,l/le-10)2 (1)global ki;ki=O;l=dblquad(@fxy,0,1,0,1)ki(2)f=inline('abs(cos(x+y))'/,x,/,y,);I二dblquad(fOpiQpi)3Y —..・A —.. jF=[〃〃〃];trapz(X,F)4p=0:pi/5:2*pi;for n=l:3nDX=diff(sin(p),n)end5f=inline('sin(x)./(x+cos(2.*x))');g=inline(,(cos(x).*(x+cos(2*x))-sin(x).*(l-2.*sin(2*x)))/(x+cos(2.*x)).A2,); pi::pi; p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x); %求dp在假设点的函数值dx=diff(f([xj))/; %直接对f(x)求数值导数gx=g(x); %求函数f的导函数g在假设点的导数plot(x,dpx,x,dx,'.:x,gx,7); %作图思考练习2format longfx=inline('l./(l+x.A2)');[l,n]=quad(fx,-lnf/lnf z le-10)[l/n]=quadl(fx/-lnf/lnf/le-10)x=-100000:100000;y=l./(l+x.A2);trapz(x,y)format short3(1)format longfx=inline(I log(l+x)./(l+x.A2)');(l/n]=quad(fx,0/l,le-10)⑵format longfxTnlinersqr^costHHQsinQ 牡)・八2)+盯);[l/n]=quad(fx,0,2*pi,le-10)4f=inline(,4.*x.* z.*exp(-z.A2.*y-x.A2)');I二triplequad(fOpiOpiQl)5f=inline('sin(x)');g=inline(,cos(x)1);x=0::2*pi;p=polyfit(x,f(x),5);dp=polyder(p);dpx=polyval(dp,x);dx=diff(f([x/2*pi+]))/;gx=g(x);plot(x,dpX/X,dx/・:x,gx/」) unit8实验指导1 syms x y;s=x A4-y A4;factor(s) factor(5135)2 syms x; f=(x-2)/(x A2-4); limit(f,x,2) sym x;f=(sqrt(pi)-sqrt(acos(x)))/sqrt(x+l); limit(f,x,-l/right,) sym x; f=sin(l/x); diffff/x') 3sym x;f=(l-cos(2*x))/x;diff(f;x')diff(f,*2)4sym x;f=sqrt(exp(x)+l);intff/x')syms x y;f=x/(x+y);intff/y1)sym x;f=exp(x)*(l+exp(x))A2;int(f,'x',0,log ⑵)sym x;f=x*log(x);int(f/x',l,exp ⑴)5sym x;s=symsum((-l)A(x+l)/x,lJnf)sym y;z=symsum(y A(2*y-l)/(2*y-l)/lJnf)6sym x;fl=(exp(x)+exp(-x))/2;f2=sqrt(x A3-2*x+l);taylor(fl/x,5,0)taylor(f2,x,6,0)7syms x y a;x=solve(l x A3+a*x+l=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)+(l-n)*(Dy)+y=0l/,y(0)=0,/l Dy(0)=0,,l x,)思考练习2syms x Bl B2 a b sl==2*((cos(x))A2)-(sin(x))A2; s2=sin(Bl)*cos(B2)-cos(Bl)*sin(B2);s3=sqrt((a+sqrt(a A2-b))/2)+sqrt((a-sqrt(a A2-b))/2); S4=(4*X A2+8*X+3)/(2*X+1); hl=simplify(sl)h2=simplify(s2)h3=simplify(s3)h4=simplify(s4)3syms x a;f=abs(x)/x;limit(f z x,O/left I)f=(x+a/x)A x;4syms x y mf=sqrt(x+sqrt(x+sqrt(x))); m=diff(f;x')difffm/x1)syms x y;f=x+y-sqrt(x A2+y A2); zl=diff(f?x) z2=diff(f,y)5syms x y;f=x+y-sqrt(x A2+y A2); zl=diff(f z x) z2=diff(f/y)sym x;f=l/(asin(x)A2*(l-x A2)A(l/2)); int(f)6syms x f=l/(l+x); int(f,0,4)sym x;f=x A3*sin(x)A2/(x A6+2*x A4+l);sym x;f=x A3*sin(x)A2/(x A6+2*x A4+l); int(f z-l?l)7syms n s=symsum(l/4A n,l,inf)sym n;s=symsum(((n+l)/n)A(l/2)z l,inf) eval(y)8syms xf=tan(x);taylor(f/x/3,0) syms xf=sin(x)A2;taylor(f z x z5,0)9syms xx=solve(I log(l+x)-5/(l+sin(x))=2,/x I)syms x y z[xyz]=solve(,4*x A2/(4*x A2+l)=y,,,4*y A2/(4*y A2+l)=z,,,4*z A2/(4*z A2+l)=x I/,x,,,y,z,z,) 10[x /y]=dsolve(,Dx=3*x+4*y l/,Dy=5*x-7*y,/l x(0)=0'/,y(0)=l,/,t,)。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 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')。

相关文档
最新文档