第一题定积分极限微分function y=f1F=1while F~=0syms x y zF=input('请输入表达式:(变量为x,y,z) 退出-0 ')if F~=0Sel=input('请选择要进行的计算:1-微分 2-极限 3-定积分其他-返回 ') switch Selcase 1Var=input('请输入进行微分的变量: ')N=input('请输入阶数: ')disp('结果为: ')diff(F,Var,N)case 2Var=input('请输入进行极限的变量: ')Val=input('请输入极限要趋近的值: ')disp('结果为: ')limit(F,Var,Val)case 3Var=input('请输入积分变量: ')Val_1=input('请输入积分下限: ')Val_2=input('请输入积分上限: ')disp('结果为: ')int(F,Var,Val_1,Val_2)endendF=input('0-退出,其他-继续')end第二题矩阵的运算function y=f2%syms result;while(1)disp('--------------------------------------');disp('1 -Add');disp('2 -Sub');disp('3 -Multi');disp('4 -Divide');disp('0 -Exit');ch = input('Choose an item to continue:');if( ch == 0)return;endM1 = input('Enter the first Matrix:');M2 = input('Enter the second Matrix:');switch(ch)case 1,result = M1+M2;case 2,result = M1-M2;case 3,result = M1*M2;case 4,result = M1/M2;enddisp('The result is :');disp(result);end%End function第三题矩阵的操作function y=f3while(1)disp('--------------------------------------');disp('1 -转置');disp('2 -求秩');disp('3 -求逆');disp('4 -行列式');disp('0 -Exit');ch = input('Choose an item to continue:');if( ch == 0)return;endM = input('Enter the Matrix:');switch(ch)case 1,result = M';case 2,result = rank(M);case 3,result = inv(M);case 4,result = det(M);enddisp('The transform result is :');disp(result);end%End functionendendend第四题向量的判定function y=f4(vec_1,vec_2,dem_1)vec_1=input('第一个向量:')vec_2=input('第二个向量:')Sel_2=input('选择: 1-判断两向量是否共线 2-判断三向量是否共面') if Sel_2==1A=[vec_1;vec_2]if rank(A)==1disp('两向量共线!')elsedisp('两向量不共线!')endelse if Sel_2==2vec_3=input('请输入第三个向量:')dem_3=length(vec_3)if dem_3==dem_1if cro(vec_1,vec_2)*vec_3'==0disp('三向量共面!')elsedisp('三向量不共面!')endelsedisp('输入向量维数不一致!')endendend第五题向量的长度,方向角的计算点积叉积混合积及投影的计算function y=f5n=1while n~=0vec_1=input('请输入第一个向量:')dem_1=length(vec_1)Sel=input('请选择:1-计算向量的方向角,长度 2-计算向量其他运算其他-返回')if Sel==2vec_2=input('请输入第二个向量:')dem_2=length(vec_2)if dem_1==dem_2Sel_1=input('请选择运算:1-点积 2-向量积(三维) 3-投影(三维) 4-混合积(三维) 5-判断共线,共面')switch Sel_1case 5JUDGE(vec_1,vec_2,dem_1)case 1vec_1*vec_2'case 2PAN(vec_1,vec_2)case 3vec_1*vec_2'./sqrt(vec_2*vec_2')case 4vec_3=input('请输入第三个向量(三维):')dem_3=length(vec_3)if dem_3==dem_1A=PAN(vec_1,vec_2)*vec_3'else disp('维数不一致!')endendelsedisp('输入错误!')endelseif Sel==1disp('模为:')Mol=sqrt(vec_1*vec_1')A=eye(dem_1)m=1while m~=dem_1+1acos(A(m,:)*vec_1'./(sqrt(A(m,:)*A(m,:)')*Mol))*180/pim=m+1endelsen=0endendSel=input('继续计算向量的长度、方向角的计算','向量的点积、叉积、混合积及投影-1,退出-2: ')if Sel==2n=0endend第六题点到直线,平面的距离的计算function y=f6n=1while n~=0Point=input('请输入一个三维点坐标向量:')Sel=input('请选择: 1-点到直线的距离 2-点到面的距离 ')switch Selcase 1LinVec=input('请输入直线方程的方向向量:(三维)')LinPot=input('请输入直线方程所经过的点:(三维)')if length(LinVec)==length(LinPot) & length(LinVec)==length(Point)A=p(LinVec,LinPot-Point)disp('点到直线的距离为:')A*A'./(LinVec*LinVec')else disp('输入数值是非法数值!确认后请重新输入!')endPoint=input('1-继续 2-退出')if Point==2n=0endcase 2PlantVec=input('请输入平面法向量:')PlantPot=input('请输入平面上任意一点:')if length(PlantVec)==length(PlantPot) & length(PlantVec)==length(Point)disp('点到平面的距离为:')[PlantPot-Point]*PlantVec'./(PlantVec*PlantVec')disp('输入数值是非法数值!确认后请重新输入!') end endend第七题 椭圆球 function y=pic1 a = 10; b = 20; c = 10;[x,y] = meshgrid(-2:0.1:2,-2:0.1:2);xa = x.^2/a^2; yb = y.^2/b^2;xyz = (ones(size(x))-xa-yb)*c^2; z = xyz.^0.5; mesh(x,y,z);第八题 双曲抛物面 function []=pic2 a = 5; b = 5;[x,y] = meshgrid(-2:0.1:2,-2:0.1:2);xa = x.^2/a^2; yb = y.^2/b^2; z = yb-xa; mesh(x,y,z);第九题 椭圆抛物面 function y=pic3 a = 2; b = 2;[x,y] = meshgrid(-2:0.1:2,-2:0.1:2);xa = x.^2/a^2; yb = y.^2/b^2; z = xa+yb; mesh(x,y,z);第十题 单页双曲面 function y=pic4 theta=0:pi/20:2*pi rho=1:0.05:3[theta,rho]=meshgrid(theta,rho) r=sqrt(rho.^2-1)[x,y,z]=pol2cart(theta,rho,r)figure(1)hold on z=-zsurf(x,y,z) axis off第十一题 双叶双曲面 function k=pic5t1=[-2*pi:0.05:2*pi]; t2=[-1*pi:0.05:1*pi];[t1,t2]=meshgrid(-2*pi:0.05:2*pi,-1*pi:0.05:1*pi); z=0.2*sqrt(sin(t2).*sin(t2)+1);h1=mesh(2*cos(t1).*sin(t2),sin(t1).*sin(t2),z);hold onh2=mesh(2*cos(t1).*sin(t2),sin(t1).*sin(t2),-z);第十二题椭圆锥面function k=tupian4(x,y)x=[-3:0.01:3];y=[-2:0.01:2];[x,y]=meshgrid(-3:0.01:3,-2:0.01:2); z=sqrt((x/3).^2+(y/2).^2); mesh(x,y,z); hold onmesh(x,y,-z);第十三题 常见二维图形theta=0:0.1:2*pi figure(1) rho=2*thetapolar(theta,rho) title('r=at')t=-2*pi:0.1:2*pi figure(1)x=2*(t-sin(t)) y=2*(1-cos(t)) plot(x,y,'g') xlabel('x') ylabel('y') title('摆线')theta=0:0.1:10*pi figure(1)rho=sqrt(4*sin(2*theta)) polar(theta,rho,'g') hold on rho=-rhopolar(theta,rho,'g')legend('r^2=a^2sin2t',2) hold onrho=sqrt(4*cos(2*theta)) polar(theta,rho,'r') hold on rho=-rhopolar(theta,rho,'r')legend('r^2=a^2cos2t',2)theta=0:0.1:4*pi figure(1)rho=exp(0.2*theta) polar(theta,rho) title('r=exp(at)')x=-5:0.1:5y=(1/sqrt((2*pi)))*exp(-x.^2./2) figure(1)plot(x,y,'g') xlabel('x') ylabel('y')title('概率曲线 ')t=0:0.1:2*pi figure(1)x=2*(cos(t)).^3 y=2*(sin(t)).^3 plot(x,y,'g') xlabel('x') ylabel('y')title('x^2/3+y^2/3=a^2/3')theta=0:0.1:2*pi figure(1)rho=2*cos(3*theta) polar(theta,rho,'g')legend('r=asin3t',4)hold onrho=2*sin(3*theta) polar(theta,rho,'r')legend('r=acos3t')theta=0:0.1:2*pi figure(1)rho=2*cos(2*theta) polar(theta,rho,'g') legend('r=acos2t',4)t=0:0.1:2*pi figure(1) x=2*cos(t) y=2*sin(t) plot(x,y,'g') xlabel('x') ylabel('y')title('x^2/a^2+y^2/b^2=1')theta=0:0.1:2*pi figure(1)rho=2*(1-cos(theta)) polar(theta,rho)title('r=a(1-cos(t))')x=-1:(1/20):1 figure(1)subplot(2,2,1) y=asin(x)plot(x,y,'g') title('asin(x)') axis([-1 1 -2 2])subplot(2,2,2) y=acos(x)plot(x,y,'g') title('acos(x)') axis([-1 1 0 4])subplot(2,2,3)y=atan(x)plot(x,y,'g') title('atan(x)') hold on y=y+piplot(x,y,'--') hold on y=y-2*piplot(x,y,'--')axis([-1.5 1.5 -4 4])subplot(2,2,4) y=atan(x)plot(x,y,'g') title('acot(x)') x=-xy=y+pi/2plot(x,y,'--') hold on y=y+piplot(x,y,'--') hold on y=y-2*piplot(x,y,'--')axis([-1.5 1.5 -pi 2*pi])x=-5:0.1:5y=8*2.^3./(x.^2+4*2.^2) figure(1)plot(x,y,'g') hold on x=-2:0.1:2y=sqrt(4-x.^2)+2 plot(x,y,'r') hold ony=-sqrt(4-x.^2)+2 plot(x,y,'r')xlabel('x') ylabel('y')title('y=8a^3/(x^2+4a^2)')y=-5:0.1:5 figure(1)x=(2*(1+y.^2)).^(0.5)plot(x,y,'g')hold onx=-xplot(x,y,'g') xlabel('x') ylabel('y')title('x^2/a^2-y^2/b^2=1')x=-2:0.1:2 figure(1)subplot(2,4,1) y=x.^2plot(x,y,'g') title('x^2')subplot(2,4,2) y=x.^3plot(x,y,'g') title('x^3')subplot(2,4,3) y=x.^(-1)plot(x,y,'g') title('1/x')subplot(2,4,4) x=0:0.1:2 y=x.^0.5plot(x,y,'g')title('x^(1/2)') subplot(2,4,5) x=-2:0.1:2y=(x.^2).^(1/3) plot(x,y,'g') title('x^(2/3)')subplot(2,4,6) x=0:0.1:2 y=x.^(1/3) plot(x,y,'g') hold on x=-x y=-yplot(x,y,'g') title('x^(1/3)')subplot(2,4,7)x=0:0.1:2plot(x,y,'g')hold ony=-yplot(x,y,'g')title('x^(1/3)')x=-4*pi:(pi/20):4*pifigure(1)subplot(2,2,1)y=sin(x)plot(x,y,'g')title('sin(x)')subplot(2,2,2)y=cos(x)plot(x,y,'g')title('cos(x)')subplot(2,2,3)x=-(pi/2-0.0001):pi/20:(pi/2-0.0001)y=tan(x)plot(x,y,'g')title('tan(x)')hold onx=x+piplot(x,y,'g')hold onx=x-2*piplot(x,y,'g')axis([-(1.5*pi-0.0001) (1.5*pi-0.0001) -10 10])subplot(2,2,4)x=0:pi/20:(pi-0.0001)y=cot(x)plot(x,y,'g')title('cot(x)')hold onx=x-piplot(x,y,'g')axis([-(pi-0.0001) (pi-0.0001) -10 10])theta=0:0.1:4*pifigure(1)polar(theta,rho) title('rt=a')。