您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 信息化管理 > matlab教程2011a(张志涌)-课后答案
第二章%分段函数的写法symsyxz=int(x*y,x,0,1);g=evalin(symengine,['piecewise([y1/2,'char(z)'],[y=1/2,1])'])G=int(g,y)g=piecewise([1/2y,y/2],[y=1/2,1])G=piecewise([1/2y,y^2/4],[y=1/2,y])%习题2-1class(vpa(sym(3/7+0.1),4))%习题2-2findsym(sym('sin(w*t)'),1)findsym(sym('a*exp(-X)'),1)findsym(sym('z*exp(j*th)'),1)%习题2-3symsxapositivex_1=solve('x^3-44.5')symsxunrealx_2=solve('x^2-a*x+a^2')symsaunrealx_2=solve('x^2-a*x+a^2')x_3=solve('x^2-a*x-a^2')symsxrealevalin(symengine,'anames(Properties)')evalin(symengine,'getprop(x)')%习题2-47/3,pi/3,pi*3^(1/3)a=pi*3^(1/3),b=sym(pi*3^(1/3)),c=sym(pi*3^(1/3),'d'),d=sym('pi*3^(1/3)')vpa(abs(a-d)),vpa(abs(b-d)),vpa(abs(c-d))%习题2-5symsa11a12a13a21a22a23a31a32a33A=[a11a12a13;a21a22a23;a31a32a33]a=det(A)B=inv(A)C=subexpr(B)[RS,w]=subexpr(B,'w')%习题2-6symsksymsapositive%fk=a^k*heaviside(k)fk=a^ks=symsum(fk,k,0,inf)%习题2-7clearallsymsksymsxpositivefk=2/(2*k+1)*(((x-1)/(x+1))^(2*k+1))s=symsum(fk,k,0,inf)s1=simple(s)%习题2-8clearall,symsty=abs(sin(t))df=diff(y),class(df)df1=limit(df,t,0,'left')df2=subs(df,'t',sym(pi/2))%习题2-9clearall,symsx;f=exp(-abs(x)).*abs(sin(x));fint=int(f,x,-5*pi,1.7*pi),digits(64),vpa(fint)class(fint)%习题2-10clearall,symsxy,f=x.^2+y.^2,fint=(int(int(f,y,1,x.^2),x,1,2)),double(fint)%习题2-11clearall,symstx;f=sin(t)/t,yx=int(f,t,0,x),ezplot(yx,[02*pi])fint=subs(yx,x,4.5),%或yxd=int(f,t,0,4.5),fint=double(yxd)holdon,plot(4.5,fint,'*r')%习题2-12%clearall,symsxn;f=(sin(x))^n;yn=int(f,'x',0,pi/2),class(yn)clearall,symsxn;symsnpositive;f=(sin(x))^n;yn=int(f,'x',0,pi/2),class(yn)%y(1/3)=?yn1=subs(yn,'n',sym(1/3)),vpa(yn1)%或yn=limit(yn,n,1/3),vpa(yn)%或yy=int(sin(x).^(1/3),x,0,pi/2),vpa(yy)%习题2-23clear,symsxySS=dsolve('Dy*y/5+x/4=0','x')ezplot(subs(S(1),'C3',1),[-2,2-2,2],1),holdonezplot(subs(S(2),'C3',1),[-2,2-2,2],1)%解为S=%2^(1/2)*(C3-(5*x^2)/8)^(1/2)%-2^(1/2)*(C3-(5*x^2)/8)^(1/2)ezplot(subs(S(1),'C3',1),[-2,2-2,2],1),holdonezplot(subs(S(2),'C3',1),[-2,2-2,2],1)%用此两条指令绘圆,在y=0处有间隙ezplot(subs(y^2-(S(1))^2,'C3',1),[-2,2-2,2],2)%用椭圆方程绘图不产生间隙colormap([001])%用ezplot(fun)绘图时,如果fun中只有一个参数,绘图的颜色是蓝色;如果fun中有两个参数,绘图的颜色是绿色,此指令设置图形颜色为蓝。gridonS1=subs(S(1),'C3',1)subs(S1,{x},{1.6^(1/2)})y=double(solve(S1))t=linspace(y(2),y(1),100)S2=subs(S(2),'C3',1)figureplot(t,subs(S1,x,t)),holdonplot(t,subs(S2,x,t))axis([-2,2-2,2])%习题2-24x=dsolve('Dx=a*t^2+b*t','x(0)=2','t')%习题2-25[f,g]=dsolve('Df=3*f+4*g','Dg=-4*f+3*g','f(0)=0','g(0)=1','x')第三章%习题3-1a=0:2*pi/9:2*pib=linspace(0,2*pi,10)%习题3-2rand('twister',0),A=rand(3,5)[I1,J1]=find(A0.5)subindex_A=sub2ind(size(A),I1,J1)subindex_A=find(A0.5)[I,J]=ind2sub(size(A),subindex_A)index_A=[IJ]%122_2rand('twister',0),A=rand(3,5),B=A0.5,C=find(B)[ci,cj]=ind2sub(size(A),C)%此法太繁[Ci,Cj]=find(B)%122_5t=linspace(1,10,100)(1)y=1-exp(-0.5.*t).*cos(2.*t),plot(t,y)(2)L=length(t)fork=1:L,yy(k)=1-exp(-0.5*t(k))*cos(2*t(k)),end,plot(t,yy)%122_6clear,formatlong,rand('twister',1),A=rand(3,3),B=diag(diag(A)),C=A.*(~B)%或C=A-B%或C=triu(A,1)+tril(A,-1)%习题3-3%s=sign(randint(1,1000,[],123)-.5);%n=sum(s==-1)rand('state',123),s=sign(rand(1,1000)-.5),n=sum(s==-1)%习题3-4clearallA=[12;34]B1=A.^(0.5),B2=A^(0.5),A1=B1.^2A2=B2^2A1-Anorm(A1-A)A1-A2norm(A1-A2)clearallA=sym('[12;34]')B1=A.^(0.5),B2=A^(0.5),A1=simple(B1.^2)A2=simple(B2^2)A1-Avpa(A1-A)A1-A2vpa(A1-A2)%习题3-5t=linspace(1,10,100)%(1)L=length(t)fork=1:Lyy(k)=1-exp(-0.5*t(k))*cos(2*t(k))endfigure(1),plot(t,yy)%(2)y=1-exp(-0.5.*t).*cos(2.*t),figure(2),plot(t,y)figure(3),subplot(1,2,1),plot(t,y)subplot(1,2,2),plot(t,yy)%习题3-6clear,formatlong,rand('twister',1),A=rand(3,3),B=diag(diag(A)),C=A.*(~B)%或C=A-B%或C=triu(A,1)+tril(A,-1)%习题3-7clear,x=-3*pi:pi/15:3*pi;y=x;[X,Y]=meshgrid(x,y);%X=ones(size(y))*x;Y=y*ones(size(x));warningoff;Z=sin(X).*sin(Y)./X./Y;%(1)“非数”数目m=sum(sum(isnan(Z)));%k=Z(isnan(Z));m=length(k)%(2)绘图surf(X,Y,Z);shadinginterp%(3)“无裂缝”图形的全部指令:x=-3*pi:pi/15:3*pi;y=x';[X,Y]=meshgrid(x,y);%X=ones(size(y))*x;Y=y*ones(size(x));X=X+(X==0)*eps;Y=Y+(Y==0)*eps;Z=sin(X).*sin(Y)./X./Y;surf(X,Y,Z);shadinginterp%习题3-8clearfork=10:-1:1;A=reshape(1:10*k,k,10);Sa(k,:)=sum(A,1);endSaclearfork=10:-1:1;A=reshape(1:10*k,k,10);ifk==1Sa(k,:)=A;elseSa(k,:)=sum(A);endendSa第四章%习题4-1clearallloadprob_401;diff_y=diff(y)./diff(t);gradient_y=gradient(y)./gradient(t);%plot(t(1:end-1),diff_y,t,gradient_y)figure(1)subplot(1,2,1),plot(t,y,t(1:end-1),diff_y)subplot(1,2,2),plot(t,y,t,gradient_y)%上面结果不好因自变量采样间距太小,将间距增大后结果较好N=20diff_y1=(diff(y(1:N:end)))./diff(t(1:N:end));gradient_y1=(gradient(y(1:N:end)))./gradient(t(1:N:end));%plot(t(1:end-1),diff_y,t,gradient_y)t1=t(1:N:end);length(t1)figure(2)subplot(1,2,1),plot(t,y,t1(1:end-1),diff_y1)subplot(1,2,2),plot(t,y,t1,gradient_y1)%习题4-2d=0.5;tt=0:d:10;t=tt+(tt==0)*eps;y=sin(t)./t;s=d*trapz(y)%计算出积分值ss=d*(cumtrapz(y))%计算梯形法累计积分并绘积分曲线plot(t,y,t,ss,'r'),holdon%用find指令计算y(4.5),并绘出该点y4_5=ss(find(t==4.5))%插值法计算y(4.5),并绘出该点yi=interp1(t,ss,4.5),plot(4.5,yi,'r+')%yi=interp1(t,ss,[4.24.34.5]),plot([4.24.34.5],yi,'r+')%clf%用精度可控指令quad即Simpson法,quadl即Lobatto法计算y(4.5)yy=quad('sin(t)./t',0,4.5)yy=quadl('sin(t)./t',0,4.5)warningoff%取消警告性提示时用%此法可用,但
本文标题:matlab教程2011a(张志涌)-课后答案
链接地址:https://www.777doc.com/doc-5212962 .html