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程序设计(第二版)课后作业答案
一、实验结果: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数学实验答案(全)
MATLAB数学实验答案(全)第⼀次练习教学要求:熟练掌握Matlab 软件的基本命令和操作,会作⼆维、三维⼏何图形,能够⽤Matlab 软件解决微积分、线性代数与解析⼏何中的计算问题。
补充命令vpa(x,n) 显⽰x 的n 位有效数字,教材102页fplot(‘f(x)’,[a,b]) 函数作图命令,画出f(x)在区间[a,b]上的图形在下⾯的题⽬中m 为你的学号的后3位(1-9班)或4位(10班以上) 1.1 计算30sin limx mx mx x →-与3sin lim x mx mxx →∞-syms xlimit((902*x-sin(902*x))/x^3) ans =366935404/3limit((902*x-sin(902*x))/x^3,inf)//inf 的意思 ans = 0 1.2 cos1000xmxy e =,求''y syms xdiff(exp(x)*cos(902*x/1000),2)//diff 及其后的2的意思 ans =(46599*cos((451*x)/500)*exp(x))/250000 - (451*sin((451*x)/500)*exp(x))/250 1.3 计算221100x y edxdy +??dblquad(@(x,y) exp(x.^2+y.^2),0,1,0,1)//双重积分 ans = 2.13941.4 计算4224x dx m x +? syms xint(x^4/(902^2+4*x^2))//不定积分 ans =(91733851*atan(x/451))/4 - (203401*x)/4 + x^3/12 1.5 (10)cos ,x y e mx y =求//⾼阶导数syms xdiff(exp(x)*cos(902*x),10) ans =-356485076957717053044344387763*cos(902*x)*exp(x)-3952323024277642494822005884*sin(902*x)*exp(x)1.6 0x =的泰勒展式(最⾼次幂为4).syms xtaylor(sqrt(902/1000+x),5,x)//泰勒展式 ans =-(9765625*451^(1/2)*500^(1/2)*x^4)/82743933602 +(15625*451^(1/2)*500^(1/2)*x^3)/91733851-(125*451^(1/2)*500^(1/2)*x^2)/406802 + (451^(1/2)*500^(1/2)*x)/902 +(451^(1/2)*500^(1/2))/500 1.7 Fibonacci 数列{}n x 的定义是121,1x x ==12,(3,4,)n n n x x x n --=+=⽤循环语句编程给出该数列的前20项(要求将结果⽤向量的形式给出)。
数学实验(第二版)课后习题答案
贵州师范学院2012级数本一班李刚数学实验课后练习答案习题2.11. syms x y;>> x=-5:0.01:5;>> y=x.^1/2;>> plot(x,y)2. f plot('exp(-x.^2)',[-5,5])3. ezplot('x.^3+y.^3-3*x*y',[-5,5])4 . ezplot('y.^2-x.^3/(1-x)',[-5,5])5.t=0:0.1:2*pi;x=t-sin(t);y=2*(1-cos(t));plot(x,y)6. t=0:0.1:2*pi; x=cos(t).^3; >> y=sin(t).^3;>> plot(t,y)>>7: t=0:0.1:2*pi; x=cos(t); y=2*sin(t); z=3*t; plot3(x,y,z)8: x =0:0.1:2*pi; r=x; polar(x,r)9: x =0:0.1:2*pi; r=exp(x); polar(x,r)10: x=0:0.1:2*pi; r=sqrt(cos(2*x)); polar(x,r)11: x=0:0.1:2*pi; r=sqrt(sin(2*x)); polar(x,r)12: x =0:0.1:2*pi; r=1+cos(x); polar(x,r)练习2.2 1:(1)(2):syms n; limit('sqrt(n+2)-2*(sqrt(n+1))+sqrt(n)',n,inf)Ans= 0 (3):: (4):(5):(6):2:3:fplot('x.^2*sin(x.^2-x-2)',[-2,2])练习2.3 1:(2):2:练习2.4 1:(1)(2):(3)(4):2:(1):syms x;int(x^(-x),x,0,1)ans =int(x^(-x),x = 0 .. 1)vpa(ans,10)ans =1.291285997(2):syms x;int(exp(2*x)*cos(x)^3,x,0,2*pi)ans =-22/65+22/65*exp(4*pi)(3):syms x; int(exp(x^2/2)/sqrt(2*pi),x,0,1)ans =-1125899906842624/5644425081792261*i*erf(1/2*i*2^(1/2))*pi^(1/2)*2^(1/2) >> vpa(ans,10)ans =.4767191345(4):syms x;int(x*log(x^4)*asin(1/x^2),x,1,3)ans =int(x*log(x^4)*asin(1/x^2),x = 1 .. 3)>> vpa(ans,10)ans =2.459772128(5):syms x ;int(exp(x^2/2)/sqrt(2*pi),x,-inf,inf)ans =Inf(6):syms x ;int(sin(x)/x,x,0,inf)ans =1/2*pi(7):syms x ;int(tan(x)/sqrt(x),x,0,1)Warning: Explicit integral could not be found. > In sym.int at 58ans =int(tan(x)/x^(1/2),x = 0 .. 1)>> vpa(ans,10)ans =.7968288892(8):syms x ;int(exp(-x^2/2)/(1+x^4),x,-inf,inf)ans =1/4*pi^(3/2)*2^(1/2)*(AngerJ(1/2,1/2)-2/pi^(1/2)*sin(1/2)+2/pi^(1/2)*cos(1/2)-WeberE(1/2,1/2 ))>> vpa(ans,10)ans =1.696392536(9):syms x ;int(sin(x)/sqrt(1-x^2),x,0,1)ans =1/2*pi*StruveH(0,1)>> vpa(ans,10)ans =.8932437410练习2.5(1):syms n;symsum(1/n^2^n,n,1,inf)ans =sum(1/((n^2)^n),n = 1 .. Inf)(2):s yms n ;symsum(sin(1/n),n,1,inf)ans =sum(sin(1/n),n = 1 .. Inf)(3):syms n ;symsum(log(n)/n^3,n,1,inf) ans =-zeta(1,3)(4):syms n ;symsum(1/(log(n))^n,n,3,inf) ans =sum(1/(log(n)^n),n = 3 .. Inf)(5):syms n;symsum(1/(n*log(n)),n,2,inf) ans =sum(1/n/log(n),n = 2 .. Inf)(6):yms n;symsum((-1)^n*n/(n^2+1),n,1,inf)ans =-1/4*Psi(1-1/2*i)+1/4*Psi(1/2-1/2*i)-1/4*Psi(1+1/2*i)+1/4*Psi(1/2+1/2*i)第三章练习3.11:(1):a=-30:1:30;b=-30:1:30;[x,y]=meshgrid(a,b);z=10*sin(sqrt(x.^2+y.^2))./(sqrt(1+x.^2+y.^2)); meshc(x,y,z)(2):a=-30:1:30;b=-30:1:30;[x,y]=meshgrid(a,b);z=4*x.^2/9+y.^2;meshc(x,y,z)(3):(4):a=-30:1:30;b=-30:1:30;[x,y]=meshgrid(a,b); z=x.^2/3-y.^2/3; meshc(x,y,z)(5):a=-30:1:30;>> b=-30:1:30;>> [x,y]=meshgrid(a,b); >> z=x*y;>> meshc(x,y,z)(6):(7):a=-30:1:30;>> b=-30:1:30;>> [x,y]=meshgrid(a,b); >> z=sqrt(x.^2+y.^2); >> meshc(x,y,z)(8):(9):a=-30:1:30;>> b=-30:1:30;>> [x,y]=meshgrid(a,b);>> z=atan(x./y);>> meshc(x,y,z)练习3.21;a=-1:0.1:1;>> b=0:0.1:2;>> [x,y]=meshgrid(a,b);>> z=x.*exp(-x.^2-y.^2);>> [px,py]=gradient(z,0.1,0.1);>> contour(a,b,z)>> hold on>> quiver(a,b,px,py)2:a=-2:0.1:1;>> b=-7:0.1:1;>> [x,y]=meshgrid(a,b);>> z=y.^3/9+3*x.^2.*y+9*x.^2+y.^2+x.*y+9; >> plot3(x,y,z)>> grid on3:[x,y]=meshgrid(-2*pi:0.2:2*pi); z=x.^2+2*y.^2;plot3(x,y,z)hold onezplot('x^2+y^2-1',[-2*pi,2*pi]) ; grid on4:t=0:0.03:2*pi;>> s=[0:0.03:2*pi]';>> x=(0*s+1)*cos(t);y=(0*s+1)*sin(t);z=s*(0*t+1); >> mesh(x,y,z)>> hold on>> [x,y]=meshgrid(-1:0.1:1);>> z=1-x+y;>> mesh(x,y,z)5:syms x y z dx dyz=75-x^2-y^2+x*y;zx=diff(z,x),zy=diff(z,y)zx =-2*x+yzy =-2*y+x练习3.31:ezplot('x^2+y^2-2*x',[-2,2]);>> grid onsyms x y ;s=int(int(x+y+1,y,-sqrt(1-(x-1)^2),sqrt(1-(x-1)^2)),x,0,2)s =2*pi2:syms r t ;>> s=int(int(sqrt(1+r^2*sin(t)),r,0,1),t,0,2*pi)s =int(1/2*((1+sin(t))^(1/2)*sin(t)^(1/2)+log(sin(t)^(1/2)+(1+sin(t))^(1/2)))/sin(t)^(1/2),t = 0 .. 2*pi) 3:syms x y z ;>> s=int(int(int(1/(1+x+y+z)^3,z,0,1-x-y),y,0,1-x),x,0,1)s =-5/16+1/2*log(2)4:s=vpa(int(int(x*exp(-x^2-y^2),y,0,2),x,-1,10))s =0.16224980455070416645061789474030练习3.41:(1):y=dsolve('Dy=x+y','y(0)=1','x')得:y =-1-x+2*exp(x)(2):y=dsolve('Dy=2*x+y^2','y(0)=0')y =tan(t*x^(1/2)*2^(1/2))*x^(1/2)*2^(1/2)练习4.11:(1):p=[5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -6 8 0 0 0 -5 0 0]; >> x=roots(p)x =0.97680.9388 + 0.2682i0.9388 - 0.2682i0.8554 + 0.5363i0.8554 - 0.5363i0.6615 + 0.8064i0.6615 - 0.8064i0.3516 + 0.9878i0.3516 - 0.9878i-0.0345 + 1.0150i-0.0345 - 1.0150i-0.4609 + 0.9458i-0.4609 - 0.9458i-0.1150 + 0.8340i-0.1150 - 0.8340i-0.7821 + 0.7376i-0.7821 - 0.7376i-0.9859 + 0.4106i-0.9859 - 0.4106i-1.0416-0.7927(2): p=[8 36 54 23];x=roots(p)x =-1.8969 + 0.6874i-1.8969 - 0.6874i-0.70632:p1=[1 0 -3 -2 -1];p2=[1 -2 5];[q2,r2]=deconv(p1,p2)q2 =1 2 -4r2 =0 0 0 -20 19 3:syms x;f=x^4+3*x^3-x^2-4*x-3;g=3*x^3+10*x^2+2*x-3;p1=factor(f),p2=factor(g)p1 =(x+3)*(x^3-x-1)p2 =(x+3)*(3*x^2+x-1)4:syms x ;f=x^12-1;p=factor(f)p =(-1+x)*(1+x^2+x)*(1+x)*(1-x+x^2)*(1+x^2)*(x^4-x^2+1)5: (1):p=[1 0 1];q=[1 0 0 0 1];[a,b,r]=residue(p,q)a =-0.0000 - 0.3536i-0.0000 + 0.3536i0.0000 - 0.3536i0.0000 + 0.3536ib =0.7071 + 0.7071i0.7071 - 0.7071i-0.7071 + 0.7071i-0.7071 - 0.7071ir =[](2):p=[1];q=[1 0 0 0 1];[a,b,r]=residue(p,q)a =-0.1768 - 0.1768i -0.1768 + 0.1768i0.1768 - 0.1768i0.1768 + 0.1768ib =0.7071 + 0.7071i0.7071 - 0.7071i -0.7071 + 0.7071i -0.7071 - 0.7071ir =[](3):p=[1 0 1];q=[1 1 -1 -1];[a,b,r]=residue(p,q)a =0.5000-1.00000.5000b =-1.0000-1.00001.0000r =[] (4): p=[1 1 0 0 0 -8];[a,b,r]=residue(p,q)a =-4-38b =-11r =1 1 1练习 4.21:(1):D=[2 1 3 1;3 -1 2 1;1 2 3 2;5 0 6 2];det(D)ans =6(2):syms a b c dD=[a 1 0 0 ;-1 b 1 0;0 -1 c 1;0 0 -1 d];det(D)ans =a*b*c*d+a*b+a*d+c*d+12:(1):D=[1 1 1 1; a b c d;a^2 b^2 c^2 d^2;a^3 b^3 c^3 d^3];det(D)ans =b*c^2*d^3-b*d^2*c^3-b^2*c*d^3+b^2*d*c^3+b^3*c*d^2-b^3*d*c^2-a*c^2*d^3+a*d^2*c^3+a *b^2*d^3-a*b^2*c^3-a*b^3*d^2+a*b^3*c^2+a^2*c*d^3-a^2*d*c^3-a^2*b*d^3+a^2*b*c^3+a^ 2*b^3*d-a^2*b^3*c-a^3*c*d^2+a^3*d*c^2+a^3*b*d^2-a^3*b*c^2-a^3*b^2*d+a^3*b^2*c(2): s yms a b x y zD=[a*x+b*y a*y+b*z a*z+b*x; a*y+b*z a*z+b*x a*x+b*y;a*z+b*x a*x+b*y a*y+b*z];det(D)ans =3*a^3*x*z*y+3*b^3*y*x*z-a^3*x^3-a^3*y^3-b^3*z^3-a^3*z^3-b^3*x^3-b^3*y^33: (1): D=[1 1 1 1;1 2 -1 4;2 -3 -1 -5;3 1 2 11];D1=[5 1 1 1;-2 2 -1 4;-2 -3 -1 -5;0 1 2 11];D2=[1 5 1 1;1 -2 -1 4;2 -2 -1 -5;3 0 2 11];D3=[1 1 5 1;1 2 -2 4;2 -3 -2 -5;3 1 0 11];D4=[1 1 1 5;1 2 -1 -2;2 -3 -1 -2;3 1 2 0];x1=det(D1)/det(D);x2=det(D2)/det(D);x3=det(D3)/det(D);x4=det(D4)/det(D);x1,x2,x3,x4x1 =1x2 =2x3 =3x4 =-1(2):D=[5 6 0 0 0;1 5 6 0 0;0 1 5 6 0;0 0 1 5 6;0 0 0 1 5]; D1=[1 6 0 0 0;0 5 6 0 0;0 1 5 6 0;0 0 1 5 6;1 0 0 1 5]; D2=[5 1 0 0 0;1 0 6 0 0;0 0 5 6 0;0 0 1 5 6;0 1 0 1 5]; D3=[5 6 1 0 0;1 5 0 0 0;0 1 0 6 0;0 0 0 5 6;0 0 1 1 5]; D4=[5 6 0 1 0;1 5 6 0 0;0 1 5 0 0;0 0 1 0 6;0 0 0 1 5]; D5=[5 6 0 0 1;1 5 6 0 0;0 1 5 6 0;0 0 1 5 0;0 0 0 1 1]; x1=det(D1)/det(D);x2=det(D2)/det(D);x3=det(D3)/det(D);x4=det(D4)/det(D);x5=det(D5)/det(D);x1,x2,x3,x4,x5x1 =2.2662x2 =-1.7218x3 =1.0571x4 =-0.5940x5 =0.3188练习 4.3 1:A=[1 2 0;3 4 -1; 1 1 -1];B=[1 2 3;-1 0 1;-2 4 -3];A',2+A,2*A-B,A*B,A^2,A^(-1)ans =1 3 12 4 10 -1 -1ans =3 4 25 6 13 3 1ans =1 2 -37 8 -34 -2 1ans =-1 2 51 2 162 -2 7ans =7 10 -214 21 -33 5 0ans =-3.0000 2.0000 -2.00002.0000 -1.0000 1.0000-1.0000 1.0000 -2.0000 2:(1):B=[2 4 3];B'ans =243(2):A=[1 2 3];B=[2 4 3];A.*B,B.*Aans =2 8 9ans =2 8 93:(1):A=[0 1 0;1 0 0;0 0 1];B=[1 0 0;0 0 1;0 1 0];C=[1 -4 3;2 0 -1;1 -2 0];A^(-1),B^(-1),X=A^(-1)*C*B^(-1) ans =0 1 01 0 00 0 1ans =1 0 00 0 10 1 0X =2 -1 01 3 -41 0 -2(2):>> A=[1 2 3;2 2 3;3 5 1];B=[1 0 0;2 0 0;3 0 0];A^(-1),x=A^(-1)*Bans =-1.0000 1.0000 0.00000.5385 -0.6154 0.23080.3077 0.0769 -0.1538x =1 0 00 0 00 0 0练习 4.41:(1):A=[4 2 -1;3 -1 2;11 3 0];b=[2;10;8];B=[A,b];rank(A),rank(B)ans =2ans =3(2):A=[2 1 -1 1;3 -2 1 -3;1 4 -3 5];b=[1;4;-2];B=[A,b];rank(A),rank(B)ans =2ans =2(3):A=[ 1 1 1 1; 1 2 -1 4;2 -3 -1 -5;3 1 2 11];b=[5;-2;-2;0];B=[A,b];rank(A),rank(B)ans =4ans =4(4):A=[ 1 1 2 -1; 2 1 1 -1;2 2 1 2];b=[0;0;0];B=[A,b];rank(A),rank(B)ans =3ans =32:syms a;A=[-2 1 1;1 -2 1;1 1 -2];b=[-2;a;a^2];B=[A,b];rank(A),rank(B)ans =2ans =3练习4.51:(1):A=[0 1;-1 0];[a,b]=eig(A)a =0.7071 0.70710 + 0.7071i 0 - 0.7071ib =0 + 1.0000i 000 - 1.0000i(2):A=[0 0 1;0 1 0;1 0 0];[a,b]=eig(A)a =0.7071 0.7071 00 0 -1.0000-0.7071 0.7071 0b =-1 0 00 1 00 0 1(3):A=[4 1 -1;3 2 -6;1 -5 3];[a,b]=eig(A)a =0.0185 -0.9009 -0.3066-0.7693 -0.1240 -0.7248-0.6386 -0.4158 0.6170b =-3.0527 0 00 3.6760 00 0 8.3766(4):A=[1 1 1 1;1 1 -1 -1;1 -1 1 -1;1 1 -1 1];[a,b]=eig(A)a =0.5615 0.3366 0.2673 -0.7683-0.5615 -0.3366 0.0000 -0.0000-0.5615 -0.3366 -0.5345 -0.6236-0.2326 0.8125 0.8018 -0.1447b =-1.4142 0 0 00 1.4142 0 00 0 2.0000 00 0 0 2.0000(5):A=[5 7 6 5;7 10 8 7;6 8 10 9;5 7 9 10];[a,b]=eig(A)a =0.8304 0.0933 0.3963 0.3803-0.5016 -0.3017 0.6149 0.5286-0.2086 0.7603 -0.2716 0.55200.1237 -0.5676 -0.6254 0.5209b =0.0102 0 0 00 0.8431 0 00 0 3.8581 00 0 0 30.2887(6):A=[5 6 0 0 0;1 5 6 0 0 ;0 1 5 6 0 ;0 0 1 5 6; 0 0 0 1 5 ]; [a,b]=eig(A)a =0.7843 -0.7843 -0.9860 -0.9237 -0.92370.5546 0.5546 0.0000 0.3771 -0.37710.2614 -0.2614 0.1643 -0.0000 0.00000.0924 0.0924 0.0000 -0.0628 0.06280.0218 -0.0218 -0.0274 0.0257 0.02579.2426 0 0 0 00 0.7574 0 0 00 0 5.0000 0 00 0 0 2.5505 00 0 0 0 7.4495 2:(1):A=[0 1;-1 0];[a,b]=eig(A)a =0.7071 0.70710 + 0.7071i 0 - 0.7071ib =0 + 1.0000i 00 0 - 1.0000i>> P=orth(a),B=P'*A*P,P*P'P =-0.7071 -0.70710 - 0.7071i 0 + 0.7071iB =0 + 1.0000i 0 - 0.0000i0 - 0.0000i 0 - 1.0000ians =1.0000 0 + 0.0000i0 - 0.0000i 1.0000>> inv(a)*A*a0 + 1.0000i 000 - 1.0000i3:(1):A=[2 0 0;0 3 2;0 2 3]; [a,b]=eig(A)a =0 1.0000 0-0.7071 0 0.70710.7071 0 0.7071b =1.0000 0 00 2.0000 00 0 5.0000>> P=orth(a),B=P'*A*P,P*P'P =-1.0000 0 -0.00000.0000 0.7071 0.7071-0.0000 -0.7071 0.7071B =2.0000 0.0000 0.00000.0000 1.0000 00.0000 0 5.0000ans =1.0000 -0.0000 0.0000-0.0000 1.0000 -0.00000.0000 -0.0000 1.0000(2):A=[1 1 0 -1;1 1 -1 0;0 -1 1 1;-1 0 1 1];[a,b]=eig(A)a =-0.5000 0.7071 0.0000 0.50000.5000 -0.0000 0.7071 0.50000.5000 0.7071 0.0000 -0.5000-0.5000 0 0.7071 -0.5000 b =-1.0000 0 0 00 1.0000 0 00 0 1.0000 00 0 0 3.0000 >> P=orth(a),B=P'*A*P,P*P'P =-0.5000 -0.4998 -0.4783 -0.52100.5000 -0.4822 0.5212 -0.49580.5000 0.4998 -0.4964 -0.5037-0.5000 0.5175 0.5031 -0.4786 B =-1.0000 0.0000 0.0000 0.00000.0000 2.9988 -0.0362 0.03440.0000 -0.0362 1.0007 -0.00060.0000 0.0344 -0.0006 1.0006 ans =1.0000 0.0000 0.0000 -0.00000.0000 1.0000 -0.0000 00.0000 -0.0000 1.0000 0.0000-0.0000 0 0.0000 1.0000练习5.3 1: [m,v]=unifstat(1,11)m =6v =8.33332:[m,v]=normstat(0,16)m =v =256>> s=sqrt(v)s =163:x=randn(200,6);s=std(x)s =0.9094 0.9757 0.9702 0.9393 0.9272 1.09824: x=normrnd(0,16,300,1);hist(x,10)练习 5.61:x=[352 373 411 441 462 490 529 577 641 692 743];y=[166 153 177 201 216 208 227 238 268 268 274];plot(x,y,'*')4:(1):x=[10 10 10 15 15 15 20 20 20 25 25 25 30 30 30];y=[25.2 27.3 28.7 29.8 31.1 27.8 31.2 32.6 29.7 31.7 30.1 32.3 29.4 30.8 32.8]; plot(x,y,'*')。
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程序,计算并输出下列公式的结果:y = \\frac{1}{\\sqrt{2\\pi\\sigma^2}} e^{-\\frac{(x-\\mu)^2}{2\\sigma^2}}其中,x, $\\mu$, $\\sigma$ 分别由用户输入。
要求输出结果精确至小数点后两位。
答案如下:x=input('请输入 x 的值:');mu=input('请输入 mu 的值:');sigma=input('请输入 sigma 的值:');y=1/sqrt(2*pi*sigma^2) *exp(-(x-mu)^2/ (2*sigma^2));fprintf('y = %.2f\', y);2.编写MATLAB程序,求解下列方程的解:4x + y = 11\\\\x + 2y = 7答案如下:A= [4,1;1,2];B= [11;7];X=inv(A) *B;fprintf('x = %.2f, y = %.2f\', X(1), X(2));第二章课后练习题1.编写MATLAB程序,计算下列多项式的值:P(x) = x^4 - 2x^3 + 3x^2 - x + 1其中,x 由用户输入。
要求输出结果精确至小数点后两位。
答案如下:x=input('请输入 x 的值:');y=x^4-2*x^3+3*x^2-x+1;fprintf('P(%.2f) = %.2f\', x, y);2.编写MATLAB程序,绘制下列函数的图像:f(x) = \\begin{cases} x + 1, & x < 0 \\\\ x^2, & 0 \\leq x < 1 \\\\ 2x - 1, & x \\geq 1 \\end{cases}答案如下:x=-2:0.01:2;y1=x+1;y2=x.^2.* ((x>=0) & (x<1));y3=2*x-1;plot(x,y1,x,y2,x,y3);legend('y1 = x + 1','y2 = x^2','y3 = 2x - 1');总结本文提供了《MATLAB数学实验第二版》的部分课后练习题及其答案。
matlab课后习题答案
习题二之阳早格格创做1.怎么样明白“矩阵是MATLAB最基础的数据对于象”?问:果为背量不妨瞅成是仅有一止或者一列的矩阵,单个数据(标量)不妨瞅成是仅含一个元素的矩阵,故背量战单个数据皆不妨动做矩阵的惯例去处理.果此,矩阵是MATLAB最基础、最要害的数据对于象.2.设A战B是二个共维共大小的矩阵,问:(1)A*B战A.*B的值是可相等?问:没有相等.(2)A./B战B.\A的值是可相等?问:相等.(3)A/B战B\A的值是可相等?问:没有相等.(4)A/B战B\A所代表的数教含意是什么?问:A/B等效于B的顺左乘A矩阵,即A*inv(B),而B\A等效于B矩阵的顺左乘A矩阵,即inv(B)*A.3.写出完毕下列支配的下令.(1)将矩阵A第2~5止中第1, 3, 5列元素赋给矩阵B.问:B=A(2:5,1:2:5); 或者B=A(2:5,[1 3 5])(2)简略矩阵A的第7号元素.问:A(7)=[](3)将矩阵A的每个元素值加30.问:A=A+30;(4)供矩阵A的大小战维数.问:size(A);ndims(A);(5)将背量t的0元素用呆板整去代替.问:t(find(t==0))=eps;(6)将含有12个元素的背量x变换成34 矩阵.问:reshape(x,3,4);(7)供一个字符串的ASCII码.问:abs(‘123’); 或者double(‘123’);(8)供一个ASCII码所对于应的字符.问:char(49);4.下列下令真止后,L1、L2、L3、L4的值分别是几?A=1:9;B=10-A;...L1=A==B;L2=A<=5;L3=A>3&A<7;L4=find(A>3&A<7);问:L1的值为[0, 0, 0, 0, 1, 0, 0, 0, 0]L2的值为[1, 1, 1, 1, 1, 0, 0, 0, 0]L3的值为[0, 0, 0, 1, 1, 1, 0, 0, 0]L4的值为[4, 5, 6]5.已知完毕下列支配:(1)与出A的前3止形成矩阵B,前二列形成矩阵C,左下角32⨯子矩阵形成矩阵D,B与C的乘积形成矩阵E.问:B=A(1:3,:);C=A(:,1:2);D=A(2:4,3:4);E=B*C;(2)分别供E<D、E&D、E|D、~E|~D战find(A>=10&A<25).问:E<D=010001⎡⎤⎢⎥⎢⎥⎢⎥⎣⎦,E&D=110111⎡⎤⎢⎥⎢⎥⎢⎥⎣⎦,E|D=111111⎡⎤⎢⎥⎢⎥⎢⎥⎣⎦,~E|~D=001000⎡⎤⎢⎥⎢⎥⎢⎥⎣⎦find(A>=10&A<25)=[1; 5].6.当A=[34, NaN, Inf, -Inf, -pi, eps, 0]时,分解下列函数的真止截止:all(A),any(A),isnan(A),isinf(A),isfinite(A).问:all(A)的值为0any(A)的值为1isnan(A)的值为[0, 1, 0, 0, 0, 0, 0]isinf(A)的值为[0, 0, 1, 1, 0, 0, 0]isfinite(A)的值为[1, 0, 0,0, 1, 1, 1]7.用结构体矩阵去保存5名教死的基础情况数据,每名教死的数据包罗教号、姓名、博业战6门课程的结果.问:student(1).id='0001';student(1).name='Tom';student(1).major='computer';student(1).grade=[89,78,67,90,86,85];8.修坐单元矩阵B并回问有闭问题.B{1,1}=1;B{1,2}='Brenden';B{2,1}=reshape(1:9,3,3);B{2,2}={12,34,2;54,21,3;4,23,67};(1)size(B)战ndims(B)的值分别是几?问:size(B)的值为2,2.ndims(B)的值为2.(2)B(2)战B(4)的值分别是几?问:B(2)=147258369⎡⎤⎢⎥⎢⎥⎢⎥⎣⎦,B(4)=[12][34][2][54][21][3][4][23][67]⎡⎤⎢⎥⎢⎥⎢⎥⎣⎦(3)B(3)=[]战B{3}=[]真止后,B的值分别是几?问:当真止B(3)=[]后,B={1, [1, 4, 7; 2, 5, 8; 3, 6, 9], {12, 34, 2; 54, 21, 3; 4, 23, 67}}当真止B{3}=[]后,B={1,[]; [1, 4, 7; 2, 5, 8; 3, 6, 9],{12, 34, 2; 54, 21, 3; 4, 23, 67}}习题三1.写出完毕下列支配的下令.(1)修坐3阶单位矩阵A.问:A=eye(3);(2)修坐5×6随机矩阵A,其元素为[100,200]范畴内的随机整数.问:round(100+(200-100)*rand(5,6));(3)爆收均值为1,圆好为0.2的500个正态分散的随机数.问:1+sqrt(0.2)*randn(5,100);(4)爆收战A共样大小的幺矩阵.问:ones(size(A));(5)将矩阵A对于角线的元素加30.问:A+eye(size(A))*30;(6)从矩阵A提与主对于角线元素,并以那些元素形成对于角阵B.问:B=diag(diag(A));2.使用函数,真止圆阵左旋90o或者左旋90o的功能.比圆,本矩阵为A,A左旋后得到B,左旋后得到C.问:B=rot90(A);C=rot90(A,-1);3.修坐一个圆阵A,供A的顺矩阵战A的止列式的值,并考证A与A-1是互顺的.问:A=rand(3)*10;B=inv(A);C=det(A);先估计B*A,再估计A*B,由估计可知B*A=A*B,即A·A-1=A-1·A是互顺.4.供底下线性圆程组的解.问:A=[4,2,-1;3,-1,2;12,3,0];b=[2;10;8];x=inv(A)*b圆程组的解为x=6.000026.666727.3333 -⎡⎤⎢⎥⎢⎥⎢⎥⎣⎦5.供下列矩阵的主对于角线元素、上三角阵、下三角阵、秩、范数、条件数战迹.(1)112351423052111509A-⎡⎤⎢⎥-⎢⎥=⎢⎥⎢⎥⎣⎦(2)0.434328.9421B⎡⎤=⎢⎥-⎣⎦问:(1)与主对于角线元素:diag(A);上三角阵:triu(A);下三角阵:tril(A);秩:rank(A);范数:norm(A,1); 或者 norm(A);或者 norm(A,inf);条件数:cond(A,1); 或者 cond(A,2); 或者 cond(A,inf)迹:trace(A);(2)【请参照(1)】.6.供矩阵A的特性值战相映的特性背量.问:[V,D]=eig(A);习题四1.从键盘输进一个4位整数,按如下准则加稀后输出.加稀准则:每位数字皆加上7,而后用战除以10的余数与代该数字;再把第一位与第三位接换,第二位与第四位接换.问:a=input('请输进4位整数:');A=[a/1000,a/100,a/10,a];A=fix(rem(A,10));A=rem(A+7,10);b=A(3)*1000+A(4)*100+A(1)*10+A(2);disp(['加稀后的值为:',num2str(b)]);2.分别用if语句战switch语句真止以下估计,其中a、b、c 的值从键盘输进.问:(1) 用if语句真止估计:a=input('请输进a的值:');b=input('请输进b的值:');c=input('请输进c的值:');x=input('请输进x的值:');y=a*x^2+b*x+c;endy=a*((sin(b))^c)+x;endy=log(abs(b+c/x));enddisp(['y=',num2str(y)]);(2) 用switch语句真止估计:a=input('请输进a的值:');b=input('请输进b的值:');c=input('请输进c的值:');x=input('请输进x的值:');switch fix(x/0.5)case {1,2}y=a*x^2+b*x+c;case num2cell(3:6)y=a*((sin(b))^c)+x;case num2cell(7:10)y=log(abs(b+c/x));enddisp(['y=',num2str(y)]);3.爆收20个二位随机整数,输出其中小于仄衡值的奇数.问:A=fix(10+89*rand(1,20));sum=0;for i=1:20sum=sum+A(i);endB=A(find(A<(sum/20)));C=B(find(rem(B,2)==0));disp(C);4. 输进20个数,供其中最大数战最小数.央供分别用循环结媾战调用MATLAB 的max 函数、min 函数去真止. 问:(1) 用循环结构真止:v_max=0;v_min=0;for i=1:20x=input(['请输进第', num2str(i), '数:']);if x>v_maxv_max=x;end;if x<v_minv_min=x;end;enddisp(['最大数为:', num2str(v_max)]);disp(['最小数为:', num2str(v_min)]);(2) 用max 函数、min 函数真止:for i=1:5A(i)=input(['请输进第', num2str(i), '数:']);enddisp(['最大数为:', num2str(max(A))]);disp(['最小数为:', num2str(min(A))]);5. 已知:236312222s =+++++,分别用循环结媾战调用MATLAB 的sum 函数供s 的值.问:(1) 用循环结构真止:s=0;for i=0:63s=s+2^i;ends(2) 调用sum函数真止:s=0:63;s=2.^s;sum(s)6.当n分别与100、1000、10000时,供下列各式的值.(1)111111(1)(ln2) 234nn+-+-++-+=(2)1111() 3574π-+-+=(3) 11111() 4166443n+++++=(4)224466(2)(2)133557(21)(21)2n nn nπ⎛⎫⨯⨯⨯⨯⎛⎫⎛⎫⎛⎫⎛⎫=⎪⎪⎪⎪ ⎪⨯⨯⨯-⨯+⎝⎭⎝⎭⎝⎭⎝⎭⎝⎭央供分别用循环结媾战背量运算(使用sum或者prod函数)去真止.问:(1) 用循环结构真止:sum=0;for k=1:100sum=sum+(-1)^(k+1)/k;endsum使用sum函数:x=[];for k=1:10000x=[x, (-1)^(k+1)/k];endsum(x)(2)用循环结构真止:sum=0;for k=1:100sum=sum+(-1)^(k+1)/(2*k-1);endsum使用sum函数:x=[];for k=1:100x=[x, (-1)^(k+1)/(2*k-1)];endsum(x)(3)用循环结构真止:sum=0;for k=1:100sum=sum+1/(4^k);endsum使用sum函数真止:x=[];for k=1:100x=[x, 1/(4^k)];endsum(x)(4)用循环结构真止:t=1;for k=1:100t=t*(((2*k)*(2*k))/((2*k-1)*(2*k+1)));endt使用prod函数真止:x=[];for k=1:100x=[x, ((2*k)*(2*k))/((2*k-1)*(2*k+1))];endprod(x)7. 编写一个函数文献,供小于任性自然数n的斐波那契(Fibnacci)数列各项.斐波那契数列定义如下:问:function x=fibnacci(n)for i=1:nif i<=2x(i)=1;elsex(i)=x(i-1)+x(i-2);endend8.编写一个函数文献,用于供二个矩阵的乘积战面乘,而后正在下令文献中调用该函数.问:函数文献myfnc.m:function [x, y]=myfnc(A, B)tryx=A*B;catchx=[];endy=A.*B;下令文献myexe.m:A=input('请输进矩阵A:');B=input('请输进矩阵B:');[x, y]=myfnc(A, B);if length(x)==0display('二矩阵的维数没有匹配,无法举止乘积运算!');disp('矩阵A 战矩阵B 的乘积为:'); xenddisp('矩阵A 战矩阵B 的面乘为:'); y9. 先用函数的递归调用定义一个函数文献供1n m i i =∑,而后调用该函数文献供100501021111k k k k k k ===++∑∑∑. 问:函数文献myfnc.m :function sum=myfnc(n, m)if n<=1sum=1;elsesum= myfnc (n-1, m)+n^m;end正在下令窗心中调用myfnc.m 文献,估计100501021111k k k k k k ===++∑∑∑: sum=myfnc(100, 1)+myfnc(50, 2)+myfnc(10,-1) 10.写出下列步调的输出截止.① s=0;a=[12,13,14;15,16,17;18,19,20;21,22,23]; for k=afor j=1:4if rem(k(j),2)~=0s=s+k(j);endendends问:真止截止为②下令文献exe.m真止后的截止为:x =41220y=2 4 6。
最新Matlab数学实验第二版课后习题答案
Matlab数学实验第二版课后习题答案胡良剑第一章%Page20,ex1(5) 等于[exp(1),exp(2);exp(3),exp(4)](7) 3=1*3, 8=2*4(8) a为各列最小值,b为最小值所在的行号(10) 1>=4,false, 2>=3,false, 3>=2, ture, 4>=1,ture(11) 答案表明:编址第2元素满足不等式(30>=20)和编址第4元素满足不等式(40>=10)(12) 答案表明:编址第2行第1列元素满足不等式(30>=20)和编址第2行第2列元素满足不等式(40>=10)%Page20, ex2(1)a, b, c的值尽管都是1,但数据类型分别为数值,字符,逻辑,注意a与c相等,但他们不等于b(2)double(fun)输出的分别是字符a,b,s,(,x,)的ASCII码%Page20,ex3>> r=2;p=0.5;n=12;>> T=log(r)/n/log(1+0.01*p)T =11.5813%Page20,ex4>> x=-2:0.05:2;f=x.^4-2.^x;>> [fmin,min_index]=min(f)fmin =-1.3907 %最小值min_index =54 %最小值点编址>> x(min_index)ans =0.6500 %最小值点>> [f1,x1_index]=min(abs(f)) %求近似根--绝对值最小的点f1 =0.0328x1_index =24>> x(x1_index)ans =-0.8500>> x(x1_index)=[];f=x.^4-2.^x; %删去绝对值最小的点以求函数绝对值次小的点>> [f2,x2_index]=min(abs(f)) %求另一近似根--函数绝对值次小的点f2 =0.0630x2_index =65>> x(x2_index)ans =1.2500%Page20,ex5>> z=magic(10)z =92 99 1 8 15 67 74 51 58 4098 80 7 14 16 73 55 57 64 414 81 88 20 22 54 56 63 70 4785 87 19 21 3 60 62 69 71 2886 93 25 2 9 61 68 75 52 3417 24 76 83 90 42 49 26 33 6523 5 82 89 91 48 30 32 39 6679 6 13 95 97 29 31 38 45 7210 12 94 96 78 35 37 44 46 5311 18 100 77 84 36 43 50 27 59>> sum(z)ans =505 505 505 505 505 505 505 505 505 505>> sum(diag(z))ans =505>> z(:,2)/sqrt(3)ans =57.157746.188046.765450.229553.693613.85642.88683.46416.928210.3923>> z(8,:)=z(8,:)+z(3,:)z =92 99 1 8 15 67 74 51 58 4098 80 7 14 16 73 55 57 64 414 81 88 20 22 54 56 63 70 4785 87 19 21 3 60 62 69 71 2886 93 25 2 9 61 68 75 52 3417 24 76 83 90 42 49 26 33 6523 5 82 89 91 48 30 32 39 6683 87 101 115 119 83 87 101 115 11910 12 94 96 78 35 37 44 46 5311 18 100 77 84 36 43 50 27 59 1小时单位负责人接到报告后,应当于1小时内向事故发生地县级以上人民政府安全生产监督管理部门和负有安全生产监督管理职责的有关部门报告。
数学实验(MATLAB)课后习题答案
数学实验练习2.1画出下列常见曲线的图形。
(其中a=1,b=2,c=3)1、立方抛物线3xy=解:x=-5:0.1:0;y=(-x).^(1/3);y=-y;x=0:0.1:5;y=[y,x.^(1/3)];x=[-5:0.1:0,0:0.1:5];plot(x,y)2、高斯曲线2x e=y-解:fplot('exp(-x.^2)',[-5,5])3、笛卡儿曲线)3(13,1333222axy y x t at y t at x =++=+=解:ezplot('x.^3+y.^3-3*x*y',[-5,5])xyx.3+y.3-3 x y = 0或t=-5:0.1:5; x=3*t./(1+t.^2); y=3*t.^2./(1+t.^2); plot(x,y)4、蔓叶线)(1,1322322xa x y t at y t at x -=+=+=解:ezplot('y.^2-x.^3/(1-x)',[-5,5])xyy.2-x.3/(1-x) = 0或t=-5:0.1:5; x=t.^2./(1+t.^2); y=t.^3./(1+t.^2); plot(x,y)5、摆线)cos 1(),sin (t b y t t a x -=-= 解:t=0:0.1:2*pi;x=t-sin(t); y=2*(1-cos(t)); plot(x,y)6、星形线)(sin ,cos 32323233a y x t a y t a x =+== 解:t=0:0.1:2*pi; x=cos(t).^3; y=sin(t).^3;plot(x,y)或ezplot('x.^(2/3)+y.^(2/3)-1',[-1,1])xyx.2/3+y.2/3-1 = 07、螺旋线ct z t b y t a x ===,sin ,cos 解:t=0:0.1:2*pi; x=cos(t); y=2*sin(t); z=3*t; plot3(x,y,z) grid on8、阿基米德螺线θa r = 解:x =0:0.1:2*pi; r=x; polar(x,r)902701809、对数螺线θa e r = 解:x =0:0.1:2*pi; r=exp(x); polar(x,r)90270180010、双纽线))()((2cos 22222222y x a y x a r -=+=θ 解:x=0:0.1:2*pi; r=sqrt(cos(2*x)); polar(x,r)90270或ezplot('(x.^2+y.^2).^2-(x.^2-y.^2)',[-1,1]) grid onxy(x.2+y.2).2-(x.2-y.2) = 011、双纽线)2)((2sin 222222xy a y x a r =+=θ 解:x=0:0.1:2*pi; r=sqrt(sin(2*x)); polar(x,r)90270或ezplot('(x.^2+y.^2).^2-2*x*y',[-1,1]) grid onxy(x.2+y.2).2-2 x y = 012、心形线)cos 1(θ+=a r 解:x =0:0.1:2*pi; r=1+cos(x); polar(x,r)90270练习2.21、求出下列极限值。
MATLAB程序设计教程(第二版)课后答案
MA TLAB第二版课后答案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')。
(完整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程序设计(第二版)课后作业答案
一、实验结果: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数学实验第二版课后习题答案
Matlab数学实验第二版课后习题答案胡良剑第一章%Page20,ex1(5) 等于[exp(1),exp(2);exp(3),exp(4)](7) 3=1*3, 8=2*4(8) a为各列最小值,b为最小值所在的行号(10) 1>=4,false, 2>=3,false, 3>=2, ture, 4>=1,ture(11) 答案表明:编址第2元素满足不等式(30>=20)和编址第4元素满足不等式(40>=10)(12) 答案表明:编址第2行第1列元素满足不等式(30>=20)和编址第2行第2列元素满足不等式(40>=10)%Page20, ex2(1)a, b, c的值尽管都是1,但数据类型分别为数值,字符,逻辑,注意a与c相等,但他们不等于b(2)double(fun)输出的分别是字符a,b,s,(,x,)的ASCII码%Page20,ex3>> r=2;p=0.5;n=12;>> T=log(r)/n/log(1+0.01*p)T =11.5813%Page20,ex4>> x=-2:0.05:2;f=x.^4-2.^x;>> [fmin,min_index]=min(f)fmin =-1.3907 %最小值min_index =54 %最小值点编址>> x(min_index)ans =0.6500 %最小值点>> [f1,x1_index]=min(abs(f)) %求近似根--绝对值最小的点f1 =0.0328x1_index =24>> x(x1_index)ans =-0.8500>> x(x1_index)=[];f=x.^4-2.^x; %删去绝对值最小的点以求函数绝对值次小的点>> [f2,x2_index]=min(abs(f)) %求另一近似根--函数绝对值次小的点f2 =0.0630x2_index =65>> x(x2_index)ans =1.2500%Page20,ex5>> z=magic(10)z =92 99 1 8 15 67 74 51 58 4098 80 7 14 16 73 55 57 64 414 81 88 20 22 54 56 63 70 4785 87 19 21 3 60 62 69 71 2886 93 25 2 9 61 68 75 52 3417 24 76 83 90 42 49 26 33 6523 5 82 89 91 48 30 32 39 6679 6 13 95 97 29 31 38 45 7210 12 94 96 78 35 37 44 46 5311 18 100 77 84 36 43 50 27 59>> sum(z)ans =505 505 505 505 505 505 505 505 505 505>> sum(diag(z))ans =505>> z(:,2)/sqrt(3)ans =57.157746.188046.765450.229553.693613.85642.88683.46416.928210.3923>> z(8,:)=z(8,:)+z(3,:)z =92 99 1 8 15 67 74 51 58 4098 80 7 14 16 73 55 57 64 414 81 88 20 22 54 56 63 70 4785 87 19 21 3 60 62 69 71 2886 93 25 2 9 61 68 75 52 3417 24 76 83 90 42 49 26 33 6523 5 82 89 91 48 30 32 39 6683 87 101 115 119 83 87 101 115 11910 12 94 96 78 35 37 44 46 5311 18 100 77 84 36 43 50 27 59 1小时单位负责人接到报告后,应当于1小时内向事故发生地县级以上人民政府安全生产监督管理部门和负有安全生产监督管理职责的有关部门报告。
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程序设计教程(第二版)课后参考答案第一章实验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第二版课后答案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;end.endA4y1=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程序设计与应用(第二版)实验参考答案-推荐下载
z=x+y;
elseif t=='-'
z=x-y;
elseif t=='*'
z=x*y;
elseif t=='/'
end
z=x/y;
disp([num2str(x),t,num2str(y),'
fix(s/10)
3
对全部高中资料试卷电气设备,在安装过程中以及安装结束后进行高中资料试卷调整试验;通电检查所有设备高中资料电试力卷保相护互装作置用调与试相技互术通关,1系电过,力管根保线据护敷生高设产中技工资术艺料0不高试仅中卷可资配以料置解试技决卷术吊要是顶求指层,机配对组置电在不气进规设行范备继高进电中行保资空护料载高试与中卷带资问负料题荷试2下卷2,高总而中体且资配可料置保试时障卷,各调需类控要管试在路验最习;大题对限到设度位备内。进来在行确管调保路整机敷使组设其高过在中程正资1常料中工试,况卷要下安加与全强过,看度并22工且22作尽22下可22都能22可地护以缩1关正小于常故管工障路作高高;中中对资资于料料继试试电卷卷保破连护坏接进范管行围口整,处核或理对者高定对中值某资,些料审异试核常卷与高弯校中扁对资度图料固纸试定,卷盒编工位写况置复进.杂行保设自护备动层与处防装理腐置,跨高尤接中其地资要线料避弯试免曲卷错半调误径试高标方中高案资等,料,编试要5写、卷求重电保技要气护术设设装交备备置底4高调、动。中试电作管资高气,线料中课并敷3试资件且、设卷料中拒管技试试调绝路术验卷试动敷中方技作设包案术,技含以来术线及避槽系免、统不管启必架动要等方高多案中项;资方对料式整试,套卷为启突解动然决过停高程机中中。语高因文中此电资,气料电课试力件卷高中电中管气资壁设料薄备试、进卷接行保口调护不试装严工置等作调问并试题且技,进术合行,理过要利关求用运电管行力线高保敷中护设资装技料置术试做。卷到线技准缆术确敷指灵设导活原。。则对对:于于在调差分试动线过保盒程护处中装,高置当中高不资中同料资电试料压卷试回技卷路术调交问试叉题技时,术,作是应为指采调发用试电金人机属员一隔,变板需压进要器行在组隔事在开前发处掌生理握内;图部同纸故一资障线料时槽、,内设需,备要强制进电造行回厂外路家部须出电同具源时高高切中中断资资习料料题试试电卷卷源试切,验除线报从缆告而敷与采设相用完关高毕技中,术资要资料进料试行,卷检并主查且要和了保检解护测现装处场置理设。备高中资料试卷布置情况与有关高中资料试卷电气系统接线等情况,然后根据规范与规程规定,制定设备调试高中资料试卷方案。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Matlab与数学实验(第二版)(张志刚刘丽梅版)习题答案(1,3,4,5章)第一章d1zxt1用format的不同格式显示2*Pi,并分析格式之间的异同。
a=2*pi ;disp('***(1) 5位定点表示2*pi:')format short , a % 5位定点表disp('***(2) 15位定点表示2*pi:')format long , a % 15位定点表disp('***(3) 5位浮点表示2*pi:')format short e , a % 5位浮点表示disp('***(4) 15位浮点表示2*pi:')format long e , a % 15位浮点表示disp('***(5) 系统选择5位定点和5位浮点中更好的表示2*pi:')format short g , a % 系统选择5位定点和5位浮点中更好的表示disp('***(6) 系统选择15位定点和15位浮点中更好的表示2*pi:')format long g , a % 系统选择15位定点和15位浮点中更好的表disp('***(7) 近似的有理数的表示2*pi:')format rat , a % 近似的有理数的表disp('***(8) 十六进制的表示:')format hex , a % 十六进制的表disp('***(9) 用圆角分(美制)定点表示2*pi:')format bank , a % 用圆角分(美制)定点表示d1zxt2利用公式求Pi的值。
sum=0 ;n=21;for i = 1:4:n % 循环条件sum= sum+(1/i) ; % 循环体enddiff=0 ;for j = 3:4:(n-2) % 循环条件diff= diff+(1/j) ; % 循环体endpai=4*(sum-diff)d1zxt3 编程计算1!+3!+...+25!的阶乘。
% 方法1:利用“while循环”来计算1!+3!+...+25!的值。
sum=0;i=1;while i<26prd=1;j=1;while j<=i % 求数i的阶乘prd=prd*j;j=j+1;endsum=sum+prd;i=i+2;enddisp('1!+3!+...+25!的和为:')sum% 方法2:利用“阶乘函数”来计算1!+3!+...+25!的值。
sum=0;for i=1:2:25sum=sum+factorial(i); % 求阶乘函数factorial(i) enddisp('1!+3!+...+25!的和为:')sumd1zxt4 编M文件计算n的阶乘。
n = 6 % 可以任意输入n的值?prd=1;j=1 ;while j<=n % 求数n的阶乘prd=prd*j;j=j+1;enddisp('n的阶乘n!为:')prdd1zxt4 JCHS 编阶乘计算n的阶乘。
function d1zxt4JCHS(n)ndisp('编阶乘计算n的阶乘为:')prd=1;j=1 ;while j<=n % 求数n的阶乘prd=prd*j;j=j+1;endd1zxt5_1计算表达式的值。
exp(123)+1234^34*log2(3)/cos(21/180*pi)value=exp(123)+1234^34*log2(3)/cos(21/180*pi)d1zxt5_2 计算函数的值。
function [y]=d1zxt5_2(x)xdisp('此时对应x 的y 值为:')y=tan(-x^2)*acos(x);第二章d3zl1x=0:0.1:4;y1=x.^(-1.0 )y2=x.^(-0.5)y3=x.^(+0.5)y4=x.^(+2.0 )y5=x.^(+3.0)y6=x.^(+4.0)plot(x,y1,x,y2,x,y3,x,y4,x,y5,x,y6) % 洋红,差号Legend ('y1=x.^(-1.0 )', 'y2=x.^(-0.5) ', 'y3=x.^(+0.5) ', 'y4=x.^(+2.0 )', 'y5=x.^(+3.0)', 'y6=x.^(+4.0)' ) %图形标注d3zd2tx=-10:0.1:10;y1=(1/3).^xy2=(1/2).^xy3=(2).^xy4=(3).^xplot(x,y1,x,y2,x,y3,x,y4) % 洋红,差号Legend ('y1=(1/3)^x', 'y2=(1/2)^x ', 'y3=(2)^x ', 'yy4=(3)^x' ) %图形标注d3zd3tx=0.1:0.1:10;y1=log(x)/log(1/3);y2=log(x)/log(1/2);y3=log(x)/log(2);y4=log(x)/log(3);plot(x,y1,x,y2,x,y3,x,y4) % 洋红,差号Legend ('y1=log1/3(x)', 'y2=log1/2(x)', 'y3=log2(x) ', 'y4=log3(x)' ) %图形标注d3zd4tx=-4:0.1:4;subplot(1,3,1)plot(x,x.^2.*sin(x)) ,grid on,title('用plot绘图y=x^2*sin(x)') % 用plot绘图,网格打开,加上图名subplot(1,3,2)fplot('x.^2.*sin(x)',[-4,4]) ,grid on,title('用fplot绘图y=x^2*sin(x)' ) % 用fplot绘图,网格打开,加上图名subplot(1,3,3)ezplot('x.^2.*sin(x)',[-4,4]) ,grid on,title('用ezplot绘图y=x^2*sin(x)' ) % 用ezplot绘图,网格打开,加上图名d3zd5t% 用plot绘图subplot(1,2,1)x=0:0.2:5;y= 3.*cos(x).*exp(sin(x));plot(x,y,'yd--'),grid on,title('用plot绘图y=3*cos(x)*exp(sin(x)) 注意:数据点!')% 用fplot绘图subplot(1,2,2)fplot('3*cos(x)*exp(sin(x))',[0,5],'yd--') ,grid on,title('用fplot绘图y=3*cos(x)*exp(sin(x)) 注意:数据点!') % 用fplot绘图d3zd6tx1=-pi:0.1:pi;y1=x1.*sin(x1);plot(x1,y1, 'mo-.')hold onx2=pi:0.1:4*pi;y2=x2.*tan(1./x2).*sin((x2).^3);plot(x2,y2, 'rx-')x3=-pi:0.1:4*pi;y3=(x3).^3;plot(x3,y3, 'y*--')x4=1:0.1:8;y4=tan(x4)+sin(x4);plot(x4,y4, 'gs:')legend('x*sinx','x*tan(1/x)*sinx^3)','x^3','tanx+sinx')d3zd6tsubplot(2,2,1)x1=-pi:0.1:pi;y1=x1.*sin(x1);plot(x1,y1, 'mo-.')xlabel('横坐标:x,[-pi,pi]')ylabel('纵坐标:x*sinx')title('图1 函数y=x*sinx的曲线')subplot(2,2,2)x2=pi:0.1:4*pi;y2=x2.*tan(1./x2).*sin((x2).^3);plot(x2,y2, 'rx-')xlabel('横坐标:x,[pi,4pi]')ylabel('纵坐标:x*tan(1/x)*sinx^3)')title('图2 函数y=x*tan(1/x)*sinx^3)的曲线')subplot(2,2,3)x3=-pi:0.1:4*pi;y3=(x3).^3;plot(x3,y3, 'y*--')xlabel('横坐标:x,[-pi,4pi]')ylabel('纵坐标:x^3')title('图3 函数y=x^3的曲线')subplot(2,2,4)x4=1:0.1:8;y4=tan(x4)+sin(x4);plot(x4,y4, 'gs:')xlabel('横坐标:x,[1,8]')ylabel('纵坐标:tanx+sinx')title('图4 函数y=tanx+sinx的曲线')d3zd7t 绘制摆线r=10 ;t=0:0.1:4*pi;x=r*(t-sin(t));y=r*(1-cos(t));plot(x,y)第四章d4zd1t同p88例2s=sym(['(1+2*x-y)^2']);p=expand(s)p1=collect(p, 'y')p1=collect(p, 'y')d4zd2t参考p83例5a=[4 -19 -4 1];b=[-3 1];[q,r]=deconv(a,b)q=poly2str(q, 'x')r=poly2str(r, 'x')d4zd3tp=sym('120-46*x-19*x^2+4*x^3+x^4')q=sym('20*x+9*x^2+x^3')zdgy=gcd(p,q)zxgb=lcm(p,q)d4zd4t%参考p99例题1.p=[1 0 0 0 -1 2 -3];r=roots(p)%参考p99例题2.s1=sym(['x^6-x^2+2*x-3']);solve(s1, 'x')d4zd5t%画出方程对应的函数在[0,2]内的图形:[x,y]=fplot('sin(x)-log(x+0.1)',[0,2]);plot(x,y)grid on%方程在1附近的根:x=fzero('sin(x)-log(x+0.1)',1)%方程的根:s1=sym(['sin(x)-log(x+0.1)']);solve(s1, 'x')d4zd7t1% syms x;syms p;p=input('输入第1个多项式: ','s')syms q;q=input('输入第2个多项式: ','s')% p=sym('120-46*x-19*x^2+4*x^3+x^4') % q=sym('20*x+9*x^2+x^3')syms zdgy;syms zxgb;zdgy=gcd(p,q)zxgb=lcm(p,q)2p=sym('120-46*x-19*x^2+4*x^3+x^4')q=sym('20*x+9*x^2+x^3')zdgy=gcd(p,q)zxgb=lcm(p,q)第五章d5zd1ta=rand(8,8);a' %求矩阵a的转置a^(-1) %求矩阵a的逆rank(a) %求矩阵a的秩d5zd2tA=[2 7 9 6 1 0;3 5 0 7 8 7;5 5 1 9 2 1;1 4 7 4 2 0;6 0 5 3 2 0]B=[1 7 0 1 3 6 0;3 8 4 5 3 4 5;2 6 5 2 1 8 4;2 5 5 4 4 5 2;5 1 9 6 8 3 1;7 1 6 0 7 2 9]rank(A*B) %求矩阵(A*B)的秩rank(A) %求矩阵(A)的秩rank(B) %求矩阵(A)的秩rank(B*A) %求矩阵(B*A)的秩(无法计算B*A)d5zd5t参考p114-116 例题1、2、3A=[2 2 -2;2 5 -4;-2 -4 5]p=poly(A) % 求矩阵A的特征多项式poly2str(p, 'x') % 以惯用形式表示求出的A的特征多项式p[p,d]=eig(A)%返回矩阵A的: 特征向量矩阵p,%返回矩阵A的: 特征值矩阵d%满足Av=vdformat short %5位定点表示p*p' %结果表明:p为“所求”得到的【正交的相似变换矩阵】p'*A*p %能够将矩阵A对角化,即满足p'*A*p =以A的3个%特征值1、1、10为对角元素的对角矩阵d5zd7t 参考p118 例题5A=[2 0 0;0 3 2;0 2 3][p,d]=eig(A)%返回矩阵A的: 特征向量矩阵p,%返回矩阵A的: 特征值矩阵d%满足Av=vdp*p' %结果表明:p为“所求”得到的【正交的相似变换矩阵】p'*A*p %能够将矩阵A对角化,即满足p'*A*p =以A的3个%特征值1、2、5为对角元素的对角矩阵syms x1 x2 x3X=[x1; x2; x3];Y=p*Xd5zd8t 1参考p108 例题5A=[2 5;1 3]B=[4 -6;2 1]X=B/Ad5zd8t 2 参考p108 例题5A=[2 5;1 3]B=[4 -6;2 1]X=B/Ad5zd11t 1参考p111 例题10A=[2 1 -1 1;4 2 -2 1;2 1 -1 -1]b=[1;2;1]B=([A,b])rref(B)d5zd11t 2参考p111 例题9A=[2 1 -1 1;3 -2 1 -3;1 4 -3 5]b=[1;1;-2]B=([A,b])rref(B)d5zd16tA=[2 -2 0;-2 1 -2;0 -2 0]B=[2 1 1;1 2 1;1 1 2]C=A+BAT=eig(A)BT=eig(B)CT=eig(C)X=A T(1,1)+A T(2,1)+AT(3,1)+BT(1,1)+BT(2,1)+BT(3,1) Y=CT(1,1)+CT(2,1)+CT(3,1)。