答案(可通过左边的bookmark迅速查找答案)第一次练习1.在主窗口输入:a=exp(1)A=piexp(pi)-pi^exp(1)%比较eπ和πe的大小2.A=rand(3,3)%产生随机数矩阵B=inv(A)%求A的逆矩阵C=B*AD=B.*AE=sqrt(C)formatshort%设置数据的形式E第二次练习1.%%质点运动图形clear;t=0:0.05:1000;w1=2;w2=[1,2,4,3,5,7,sqrt(3),sqrt(5),exp(1)];%w2可以选不同的值x=sin(w1*t);forn=1:9;y=sin(w2(n)*t);subplot(3,3,n);plot(x,y);end2.%%本征函数静态%画出四种本征函数系sin(nπx/l),cos(nπx/l),sin((n+1/2)πx/l),cos((n+1/2)πx/l)的图形,其中n取1,2,3,4。clear;clf;n=1:3;x=0:0.01:1;[XN]=meshgrid(x,n)Y1=sin(pi*N.*X);Y2=cos(pi*N.*X);Y3=sin(pi*(N+1/2).*X);Y4=cos(pi*(N+1/2).*X);Y=cat(3,Y1,Y2,Y3,Y4);fork=1:4subplot(2,2,k)plot(x,Y(:,:,k),'b')axis([0,1,-1,1])end第三次练习1.%%本征函数动态clear;clf;clc;n=1:3;%x=0:0.04:1;t=0:0.02*pi:0.8*pi;[XNT]=meshgrid(x,n,t);fork=1:50subplot(2,1,1)Y1=sin(pi*N(:,:,1).*X(:,:,1)).*cos(pi*N(:,:,1).*T(:,:,k));plot(x,Y1);axis([0,1,-1,1])m1(:,k)=getframe;subplot(2,1,2)Y2=-cos(pi*N(:,:,1).*X(:,:,1)).*sin(pi*N(:,:,1).*T(:,:,k));plot(x,Y2);axis([0,1,-1,1])m2(:,k)=getframe;endmovie(m1,1);movie(m2,1);2.%画复变函数图形%(z-0.5)1/2z=cplxgrid(50);cplxmap(z,sqrt(z-0.5))%画ez的图形z=cplxgrid(50);cplxmap(z,exp(z))%画lnz的图像z=cplxgrid(50);cplxmap(z,log(z))3.%两端固定弦的级数解%初速度为零,初位移不为零clear;clc;functionjxjN=50t=0:0.005:2.0;x=0:0.001:1;ww=wfun(N,0);ymax=max(abs(ww));h=plot(x,ww,'linewidth',3);axis([0,1,-ymax,ymax])sy=[];forn=2:length(t)ww=wfun(N,t(n));set(h,'ydata',ww);drawnow;sy=[sy,sum(ww)];endfunctionwtx=wfun(N,t)x=0:0.001:1;a=1;wtx=0;forI=1:NifI~=7wtx=wtx+0.05*((sin(pi*(7-I)*4/7)-sin(pi*(7-I)*3/7)).../(7-I)/pi-(sin(pi*(7+I)*4/7)-sin(pi*...(7+I)*3/7))/(7+I)/pi)*cos(I*pi*a*t).*sin(I*pi*x);elsewtx=wtx+0.05/7*cos(I*pi*a*t).*sin(I*pi*x);endend%初速度不为零,初位移为零functionpsiN=50;t=0:0.005:2.0;x=0:0.001:1;ww=psi1fun1(N,0);h=plot(x,ww,'linewidth',3);axis([0,1,-0.08,0.08])sy=[];forn=2:length(t)ww=psi1fun1(N,t(n));set(h,'ydata',ww);drawnow;sy=[sy,sum(ww)];endfunctionwtx=psi1fun1(N,t)x=0:0.001:1;a=1;wtx=0;fork=1:NBk=2/(k*k*pi*pi)*(cos(3*k*pi/7)-cos(4*k*pi/7));wtx=wtx+Bk*sin(k*pi*t)*sin(k*pi*x);end第四次练习1.%mandelbrot集的绘制dxy=0.001;N1=2600;N2=2700;N=70;RGB=zeros(N1,N2,3);form=1:N1forn=1:N2z=0;k=0;c=(-1.3+m*dxy)*i+(-2.1+n*dxy);whileabs(z)=50&k=Nz=z^2+c;k=k+1;ends=10*k/(N+1);RGB(m,n,1)=mod(s,1);endendRGB(:,:,2)=1-RGB(:,:,1);B=100*RGB(:,:,1);RGB(:,:,3)=mod(B,1);image(RGB);%Julia集的绘制clc;clear[x,y]=meshgrid(-1.5:0.002:1.5);z=x+y*i;N1=1501;N=70;c=0.1+0.75*i;form=1:N1forn=1:N1k=0;whileabs(z(m,n))=80&k=Nz(m,n)=z(m,n)^2+c;k=k+1;ends=10*k/(N+1);RGB(m,n,1)=mod(s,1);endendRGB(:,:,2)=1-RGB(:,:,1);B=100*RGB(:,:,1);RGB(:,:,3)=mod(B,1);image(RGB)2.%用IFS画羽毛树叶%羽毛树figurett=[100,500,1000,3000,6000,10000];fort=1:6subplot(2,3,t)N=tt(t);v=rand(N,1);x=[.5,zeros(1,N-1)];y=zeros(1,N);forkk=2:Nvv=v(kk);ifvv=.02x(kk)=0.5;y(kk)=0.27*y(kk-1);elseifvv=.17y(kk)=.246*x(kk-1)+0.224*y(kk-1)-0.036;x(kk)=-.139*x(kk-1)+0.263*y(kk-1)+0.57;elseifvv=.3x(kk)=.17*x(kk-1)-.215*y(kk-1)+.408;y(kk)=.222*x(kk-1)+.176*y(kk-1)+.0893;elsex(kk)=.781*x(kk-1)+.034*y(kk-1)+.1075;y(kk)=-.032*x(kk-1)+.739*y(kk-1)+.27;endendplot(x(1:N),y(1:N),'.','markersize',4)end%,这个程序是利用IFS迭代画出三角形图形%几率三角形N=50000;v=rand(N,1);ABC=[-1,sqrt(2)*i,1];xy=[i;zeros(N-1,1)];forkk=2:Nifv(kk)1/3,xy(kk)=0.5*xy(kk-1)+0.5*ABC(1);elseifv(kk)2/3,xy(kk)=0.5*xy(kk-1)+0.5*ABC(2);else,xy(kk)=0.5*xy(kk-1)+0.5*ABC(3);endendfigureplot(xy,'.','MarkerSize',4)axisequal第五次练习1.%%无限长细杆热传导[XTtheta]=meshgrid(-5:0.2:6,0.01:0.01:1,0:0.01:1);a=2;U=1/(2*sqrt(pi*T)).*exp(-(X-theta).^2./(4*a^2*T));u=0.01*trapz(U,3);fork=1:100plot(X(1,:,1),u(k,:));axis([-5602]);pause(0.01);end2.%达朗贝尔公式的绘画%初位移不为零,初速度为零u(1:140)=0;x=linspace(0,1,140);u(61:80)=0.05*sin(pi*x(61:80)*7);uu=u;h=plot(x,u,'linewidth',3);axis([0,1,-0.05,0.05]);set(h,'EraseMode','xor')forat=2:60lu(1:140)=0;ru(1:140)=0;lx=[61:80]-at;rx=[61:80]+at;lu(lx)=0.5*uu(61:80);ru(rx)=0.5*uu(61:80);u=lu+ru;set(h,'XData',x,'YData',u);drawnow;pause(0.1)end%初位移为零,初速度不为零t=0:0.005:8;x=-10:0.1:10;a=1;[X,T]=meshgrid(x,t);xpat=X+a*T;xpat(find(xpat=0))=0;xpat(find(xpat=1))=1;xmat=X-a*T;xmat(find(xmat=0))=0;xmat(find(xmat=1))=1;jf=1/2/a*(xpat-xmat);h=plot(x,jf(1,:),'linewidth',3);%画动画set(h,'erasemode','xor');axis([-1010-11])holdonforj=2:length(t)pause(0.01)set(h,'ydata',jf(j,:));drawnow;end3.%通电圆线圈生成的磁场(直接数值积分)clear;figure(1)a=0.35;y=-1:0.04:1;the=0:pi/20:2*pi;[Y,Z,T]=meshgrid(y,y,the);r=sqrt((a*cos(T)).^2+Z.^2+(Y-a*sin(T)).^2);r3=r.^3;dby=a*Z.*sin(T)./r3;by=pi/40*trapz(dby,3);dbz=a*(a-Y.*sin(T))./r3;bz=pi/40*trapz(dbz,3);subplot(1,2,1)%二维图形[bSY,bSZ]=meshgrid([0:0.05:0.2],0);h1=streamline(Y(:,:,1),Z(:,:,1),by,bz,bSY,bSZ,[0.1,1000]);h2=copyobj(h1,gca);%用图形复制与旋转画其余的象限,代替下面三句rotate(h2,[1,0,0],180,[000]);h3=copyobj(allchild(gca),gca);rotate(h3,[0,1,0],180,[000]);title('磁场的二维图','fontsize',15);forkk=1:4%曲率较大的场线要取不同的步长[bSY,bSZ]=meshgrid(0.2+kk*0.02,0);streamline(Y(:,:,1),Z(:,:,1),by,bz,bSY,bSZ,[0.02/(kk+1),4500]);streamline(-Y(:,:,1),Z(:,:,1),-by,bz,-bSY,bSZ,[0.02/(kk+1),4500]);end[X,Y,Z]=meshgrid(-0.5:0.04:0.5);%画三维图形r2=X.^2+Y.^2+Z.^2;fork=1:81phi=pi/40*(k-1);costh=cos(phi);sinth=sin(phi);R3=(r2+a^2-2*a*(X*costh+Y*sinth)).^(3/2);Bx0(:,:,:,k)=a*Z*costh./R3;By0(:,:,:,k)=a*Z*sin