习题2.1画出下列常见曲线的图形y (1)立方抛物线3x 命令:syms x y;ezplot('x.^(1/3)')(2)高斯曲线y=e^(-X^2);命令:clearsyms x y;ezplot('exp(-x*x)')(3)笛卡尔曲线命令:>> clear>> syms x y;>> a=1;>> ezplot(x^3+y^3-3*a*x*y)(4)蔓叶线命令:>> clear>> syms x y;>> a=1 ezplot(y^2-(x^3)/(a-x))(5)摆线:()()t b y t t a x cos 1,sin -=-=命令:>> clear>> t=0:0.1:2*pi;>> x=t-sin(t);>>y=2*(1-cos(t)); >> plot(x,y)7螺旋线命令:>> clear >> t=0:0.1:2*pi; >> x=cos(t); >> y=sin(t);>> z=t;>>plot3(x,y,z) (8)阿基米德螺线>> theta=0:0.1:2*pi;>> rho1=(theta);>> subplot(1,2,1),polar(theta,rho1)(9) 对数螺线命令:cleartheta=0:0.1:2*pi;rho1=exp(theta);subplot(1,2,1),polar(theta,rho1) (12)心形线>> theta=0:0.1:2*pi;>> rho1=1+cos(theta);>> subplot(1,2,1),polar(theta,rho1)练习2.21. 求出下列极限值(1)nn n n 3lim 3+∞→命令:>>syms n>>limit((n^3+3^n)^(1/n))ans =3(2))121(lim n n n n ++-+∞→命令:>>syms n>>limit((n+2)^(1/2)-2*(n+1)^(1/2)+n^(1/2),n,inf)ans =(3)x x x 2cot lim 0→命令:syms x ;>> limit(x*cot(2*x),x,0)ans =1/2(4))(cos lim c m xx ∞→ 命令:syms x m ;limit((cos(m/x))^x,x,inf)ans =1(5))111(lim 1--→e x x x 命令:syms x>> limit(1/x-1/(exp(x)-1),x,1)ans =(exp(1)-2)/(exp(1)-1)(6))(2lim x x x x -+∞→命令:syms x>> limit((x^2+x)^(1/2)-x,x,inf)ans =1/2练习2.41. 求下列不定积分,并用diff 验证:(1)⎰+xdx cos 1 >>Clear>> syms x y>> y=1/(1+cos(x));>> f=int(y,x)f =tan(1/2*x)>> y=tan(1/2*x);>> yx=diff(y,x);>> y1=simple(yx)y1 =1/2+1/2*tan(1/2*x)^2 (2)⎰+e x dx 1clearsyms x yy=1/(1+exp(x));f=int(y,x)f =-log(1+exp(x))+log(exp(x))syms x yy=-log(1+exp(x))+log(exp(x));yx=diff(y,x);y1=simple(yx)y1 =1/(1+exp(x))(3)dx x x ⎰sin 2syms x yy=x*sin(x)^2;>> f=int(y,x)f =x*(-1/2*cos(x)*sin(x)+1/2*x)-1/4*cos(x)^2-1/4*x^2clearsyms x y y=x*(-1/2*cos(x)*sin(x)+1/2*x)-1/4*cos(x)^2-1/4*x^2;yx=diff(y,x);>> y1=simple(yx)y1 =x*sin(x)^2(4) xdx ⎰sec 3syms x yy=sec(x)^3;f=int(y,x)f =1/2/cos(x)^2*sin(x)+1/2*log(sec(x)+tan(x))clearsyms x yy=1/2/cos(x)^2*sin(x)+1/2*log(sec(x)+tan(x));yx=diff(y,x);y1=simple(yx)y1 =1/cos(x)^32. 求下列积分的数值解1)dx x x ⎰-10clearsyms xy=int(x^(-x),x,0,1)y =int(x^(-x),x = 0 .. 1)vpa(y,10)ans =1.2912859972)xdx e x cos 3202⎰πclearsyms xy=int(exp(2*x)*cos(x)^3,x, clearsyms xy=int((1/(2*pi)^(1/2))*exp(-x^2/2),x,0,1)y =7186705221432913/36028797018963968*erf(1/2*2^(1/2))*2^(1/2)*pi^(1/0,2*pi) y =22/65*exp(pi)^4-22/65vpa(ans,10)(3) dx x e 210221-⎰π>> clear>> syms x>> y=int(1/(2*pi)^(1/2)*exp(-x^2/2),0,1);>> vpa(y,14)ans =.341344746068552(4)>> clear>> syms x>> y=int(x*log(x^4)*asin(1/x^2),1,3);Warning: Explicit integral could not be found.> In sym.int at 58>> vpa(y,14)ans =2.45977212823752(5)>> clear>> syms x>> y=int(1/(2*pi)^(1/2)*exp(-x^2/2),-inf,inf);>> vpa(y,14)ans =.99999999999999练习2.51判断下列级数的收敛性,若收敛,求出其收敛值。
1)syms ns1=symsum(1/n^(2^n),n,1,inf)s1 =sum(1/(n^(2^n)),n = 1 .. Inf)vpa(s1,10)ans =1.062652416因此不收敛2)syms ns1=symsum(sin(1/n),n,1,inf)s1 =sum(sin(1/n),n = 1 .. Inf)vpa(s1,10)ans =sum(sin(1/n),n = 1 .. Inf)不收敛(3)>> clear>> syms n>> s=symsum(log(n)/n^3,n,1,inf)s =-zeta(1,3)收敛(4) syms ns1=symsum(1/(log10(n))^n,n,3,inf)s1 =sum(1/((log(n)/log(10))^n),n = 3 .. inf)不收敛(5) syms ns1=symsum(1/n*log10(n),n,2,inf)s1 =sum(1/n*log(n)/log(10),n = 2 .. Inf)不收敛(6)>> clear>> syms n>> s=symsum((-1)^n*n/n^2+1,n,1,inf)sum((-1)^n/n+1,n = 1 .. Inf)不收敛习题3.11)clear;[x,y]=meshgrid(-30:0.3:30);z=10*sin(sqrt(x.^2+y.^2))./sqrt(1+x.^2+y.^2); >> meshc(x,y,z)clear>> [x,y]=meshgrid(-30:0.1:30);>> z=10*sin((x^2+y^2)^(1/2))/(1+x^2+y^2)^(1/2) mesh(x,y,z)1.2.取适当的参数绘制下列曲面的图形。
(1)clear>> a=-2:0.1:2;>> b=-3:0.1:3;>> [x,y]=meshgrid(a,b);>> z=(1-(x.^2)/4-(y.^2)/9).^(1/2);>> mesh(x,y,z)>> hold onmesh(x,y,-z)(2)clear>> a=-1:0.1:1;>> b=-2:0.1:2;[x,y]=meshgrid(a,b);>> z=(4/9)*(x.^2)+(y.^2);>> mesh(x,y,z)(4)clear>> [x,y]=meshgrid(-1:0.1:1);>> z=(1/3)*(x.^2)-(1/3)*(y.^2);>> mesh(x,y,z)习题3.2P49/例3.2.1命令:syms x ylimit(limit((x^2+y^2)/(sin(x)+cos(y)),0),pi), ans =-pi^2limit(limit((1-cos(x^2+y^2))/((x^2+y^2)),0),0), ans =P49/例3.2.2命令:clear;syms x y z dx dy dz zxz zy zxx zxy z=atan(x^2*y)z =atan(x^2*y)zx=diff(z,x),zy=diff(z,y)zx2*x*y/(1+x^4*y^2)zy =x^2/(1+x^4*y^2)dz=zx*dx+zy*dy,dz =2*x*y/(1+x^4*y^2)*dx+x^2/(1+x^4*y^2)*dzxx=diff(zx,x),zxy=diff(zx,y)zxx =2*y/(1+x^4*y^2)-8*x^4*y^3/(1+x^4*y^2)^2 zxy =2*x/(1+x^4*y^2)-4*x^5*y^2/(1+x^4*y^2)^23.2.1作图表示函数z=x*exp(-x^2-y^2) (-1<x<1,0<y<2)沿x轴方向梯度clear>> 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),hold off习题3.41.解下列微分方程(1)y=dsolve('Dy=x+y','y(0)=1','x')y =-x-1+2*exp(x)x=[1 2 3]x = 1 2 3-x-1+2*exp(x)ans =3.4366 11.7781 36.1711(2)x'=2*x+3*y,y'=2*x+y,x(0)=-2,y(0)=2.8,0<t<10,做相平面图新建M函数function dy=weifen1(t,y)dy=zeros(2,1);dy(1)=2*y(1)+3*y(2);dy(2)=2*y(1)+y(2);输入命令>> t=0:0.1:10;>> [t,y]=ode15s('weifen1',[0,10],[-2 2.8]);>> plot(t,y)(3)y''-0.01(y')^2+2*y1=sin(t),y(0)=0,y'(0)=1,0<t<5,做y的图新建M函数function dy=weifen2(t,y)dy=zeros(2,1);dy(1)=y(2);dy(2)=0.01*y(2)^2-2*y(1)+sin(t);输入命令>> [t,y]=ode15s('weifen2',[0,5],[0 1]);>> plot(t,y)1.绘制飞船轨迹图新建M函数function dy=weifen3(t,y)dy=zeros(4,1);dy(1)=y(3);dy(2)=y(4);dy(3)=2*y(4)+y(1)-(1-1/82.45)*(y(1)+1/82.45)/((y(1)+1/82.45)^2+y(2)^2)^(3/2)-(1/82.45)*(y(1)+1/82.45-1)/((y(1)+1-1/82.45)^2+y(2)^ 2)^(3/2);dy(4)=-2*y(3)+y(2)-(1-1/82.45)*y(2)^2/((y(1)+1/82.45)^2+y(2)^2)^(3/2)-(1/82.45)*y(2)/((y(1)+1 -1/82.45)^2+y(2)^2)^(3/2);输入命令>> [t,y]=ode15s('weifen3',[0,10],[1.2 0 0 -1]);>> plot(t,y)习题4.14.1.5(1)>> clear>> 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.7071i-0.7071 - 0.7071i0.7071 + 0.7071i0.7071 - 0.7071i>> r =[]>> format rataa =-1/6369051672525780 - 1189/3363i-1/6369051672525779 + 1189/3363i1/5095241338020627 - 1189/3363i1/5095241338020627 + 1189/3363i4.1.5(2)>> p=[1];>> q=[1 0 0 0 1];>> [a,b,r]=residue(p,q)a =0.1768 - 0.1768i0.1768 + 0.1768i-0.1768 - 0.1768i-0.1768 + 0.1768ib =-0.7071 + 0.7071i-0.7071 - 0.7071i0.7071 + 0.7071i0.7071 - 0.7071ir =[]>> format rat>> aa =1189/6726 - 1189/6726i1189/6726 + 1189/6726i-1189/6726 - 1189/6726i-1189/6726 + 1189/6726i习题4.24.2.1(1)>> clear>> D=[2 1 3 1;3 -1 2 1;1 2 3 2;5 0 6 2];>> det(D)ans =64.3.3(1)>> clear>> 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];>> X=C*inv(A)*inv(B)X =-4 3 10 -1 2-2 0 1习题4.34.3.3(2)>> clear>> D=[1 2 3;2 2 3;3 5 1];>> D1=[1 2 3;2 2 3;3 5 1];>> D2=[1 1 3;2 2 3;3 3 1];>> D3=[1 2 1;2 2 2;3 5 3];X1=det(D1)/det(D);X2=det(D2)/det(D);X3=det(D3)/det(D); >> X1,X2,X3X1 =1X2 =X3 =4.4.1(1)>> clear>> A=[4 2 -1;3 -1 2;3 -1 2;11 3 0];>> B=[4 2 -1 2;3 -1 2 10;11 3 0 8];>> rank(A),RANK(B)ans =2Warning: Function call RANK invokes inexact match E:\toolbox\matlab\matfun\rank.m. ans =3习题4.44.4.1(3)clear>> A=[1 1 1 1;1 2 -1 4;2 -3 -1 -5;3 1 2 11];>> B=[1 1 1 1 5;1 2 -1 4 -2;2 -3 -1 -5 -2;3 1 2 11 0];>> rank(A),rank(B)ans =4ans =4习题4.54.5.1(3)>> clear>> A=[4 1 -1;3 2 -6;1 -5 3];>> [a,b]=eig(A)a =92/4963 -1237/1373 -424/1383-627/815 -449/3622 -1301/1795-1122/1757 -1097/2638 559/906b =-4695/1538 0 00 1963/534 00 0 8318/9934.5.1(5)>> clear>> A=[5 7 6 5;7 10 8 7;6 8 10 9;5 7 9 10];>> [a,b]=eig(A)a =431/519 308/3301 472/1191 551/1449 -641/1278 -2209/7323 1175/1911 2100/3973 -434/2081 1050/1381 -855/3148 494/895 368/2975 -1049/1848 -3157/5048 473/908b =23/2266 0 0 00 1639/1944 0 00 0 3615/937 00 0 0 2938/974.5.3>> clear>> A=[2 0 0;0 3 2;0 2 3];>> [a,b]=eig(A);>> [a,b]=eig(A)a =0 1 0-985/1393 0 985/1393 985/1393 0 985/1393b =1 0 00 2 00 0 5 >> p=orth(a)p =0 -1 0985/1393 0 985/1393 -985/1393 0 985/1393>> B=p'*A*pB =1 0 00 2 00 0 5 >> p*p'ans =1 0 00 1 00 0 1习题5.75.7.5>> clear>> x=0:0.01:1;>> y=exp(-x.^2/2);>> plot(x,y);>> syms x;>> vpa(int(exp(-x.^2/2),x,0,1),6) ans =.855620>> n=10000;>> x=rand(n,1);>> y=rand(n,1);>> m=sum(y<exp(-x.^2/2))m =8564>> s=m/ns =0.8564>>练习6.7求这两家煤场如何分配供煤能使总运输量最小建立数学模型:minz=10*x1+5*x2+6*x3+4*x4+8*x5+15*x6s.t.:x1+x2+x3>=60x4+x5+x6>=100x1+x4=45x2+x5=75x3+x6=40输入命令>> c=[10;5;6;4;8;15];>> A=[-1 -1 -1 0 0 0;0 0 0 -1 -1 -1];>> b=[-60;-100];>> Aeq=[1 0 0 1 0 0;0 1 0 0 1 0;0 0 1 0 0 1];>> beq=[45;75;40];>> lb=zeros(6,1);>> [x,fv]=linprog(c,A,b,Aeq,beq,lb)Optimization terminated.x =0.000020.000040.000045.000055.00000.0000fv =960.0000。