%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,ex3r=2;p=0.5;n=12;T=log(r)/n/log(1+0.01*p)T=11.5813%Page20,ex4x=-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=24x(x1_index)ans=-0.8500x(x1_index)=[];f=x.^4-2.^x;%删去绝对值最小的点以求函数绝对值次小的点[f2,x2_index]=min(abs(f))%求另一近似根--函数绝对值次小的点f2=0.0630x2_index=65x(x2_index)ans=1.2500%Page20,ex5z=magic(10)z=929918156774515840988071416735557644148188202254566370478587192136062697128869325296168755234172476839042492633652358289914830323966796139597293138457210129496783537444653111810077843643502759sum(z)ans=505505505505505505505505505505sum(diag(z))ans=505z(:,2)/sqrt(3)ans=57.157746.188046.765450.229553.693613.85642.88683.46416.928210.3923z(8,:)=z(8,:)+z(3,:)z=9299181567745158409880714167355576441481882022545663704785871921360626971288693252961687552341724768390424926336523582899148303239668387101115119838710111511910129496783537444653111810077843643502759%Page40ex1先在编辑器窗口写下列M函数,保存为eg2_1.mfunction[xbar,s]=ex2_1(x)n=length(x);xbar=sum(x)/n;s=sqrt((sum(x.^2)-n*xbar^2)/(n-1));例如x=[81706551766690876177];[xbar,s]=ex2_1(x)xbar=72.4000s=12.1124%Page40ex2s=log(1);n=0;whiles=100n=n+1;s=s+log(1+n);endm=n计算结果m=37%Page40ex3clear;F(1)=1;F(2)=1;k=2;x=0;e=1e-8;a=(1+sqrt(5))/2;whileabs(x-a)ek=k+1;F(k)=F(k-1)+F(k-2);x=F(k)/F(k-1);enda,x,k计算至k=21可满足精度%Page40ex4clear;tic;s=0;fori=1:1000000s=s+sqrt(3)/2^i;ends,toctic;s=0;i=1;whilei=1000000s=s+sqrt(3)/2^i;i=i+1;ends,toctic;s=0;i=1:1000000;s=sqrt(3)*sum(1./2.^i);s,toc%Page40ex5t=0:24;c=[15141414141516182022232528...313231292725242220181716];plot(t,c)%Page40ex6%(1)x=-2:0.1:2;y=x.^2.*sin(x.^2-x-2);plot(x,y)y=inline('x^2*sin(x^2-x-2)');fplot(y,[-22])%(2)参数方法t=linspace(0,2*pi,100);x=2*cos(t);y=3*sin(t);plot(x,y)%(3)x=-3:0.1:3;y=x;[x,y]=meshgrid(x,y);z=x.^2+y.^2;surf(x,y,z)%(4)x=-3:0.1:3;y=-3:0.1:13;[x,y]=meshgrid(x,y);z=x.^4+3*x.^2+y.^2-2*x-2*y-2*x.^2.*y+6;surf(x,y,z)%(5)t=0:0.01:2*pi;x=sin(t);y=cos(t);z=cos(2*t);plot3(x,y,z)%(6)theta=linspace(0,2*pi,50);fai=linspace(0,pi/2,20);[theta,fai]=meshgrid(theta,fai);x=2*sin(fai).*cos(theta);y=2*sin(fai).*sin(theta);z=2*cos(fai);surf(x,y,z)%(7)x=linspace(0,pi,100);y1=sin(x);y2=sin(x).*sin(10*x);y3=-sin(x);plot(x,y1,x,y2,x,y3)%page41,ex7x=-1.5:0.05:1.5;y=1.1*(x1.1)+x.*(x=1.1).*(x=-1.1)-1.1*(x-1.1);plot(x,y)%page41,ex8分别使用whichtrapz,typetrapz,dirC:\MATLAB7\toolbox\matlab\datafun\%page41,ex9clear;close;x=-2:0.1:2;y=x;[x,y]=meshgrid(x,y);a=0.5457;b=0.7575;p=a*exp(-0.75*y.^2-3.75*x.^2-1.5*x).*(x+y1);p=p+b*exp(-y.^2-6*x.^2).*(x+y-1).*(x+y=1);p=p+a*exp(-0.75*y.^2-3.75*x.^2+1.5*x).*(x+y=-1);mesh(x,y,p)%page41,ex10lookforlyapunovhelplyapA=[123;456;780];C=[2-5-22;-5-24-56;-22-56-16];X=lyap(A,C)X=1.0000-1.0000-0.0000-1.00002.00001.0000-0.00001.00007.0000%Chapter3%Exercise1a=[1,2,3];b=[2,4,3];a./b,a.\b,a/b,a\bans=0.50000.50001.0000ans=221ans=0.6552%一元方程组x[2,4,3]=[1,2,3]的近似解ans=0000000.66671.33331.0000%矩阵方程[1,2,3][x11,x12,x13;x21,x22,x23;x31,x32,x33]=[2,4,3]的特解%Exercise2(1)A=[41-1;32-6;1-53];b=[9;-2;1];rank(A),rank([A,b])%[A,b]为增广矩阵ans=3ans=3%可见方程组唯一解x=A\bx=2.38301.48942.0213%Exercise2(2)A=[4-33;32-6;1-53];b=[-1;-2;1];rank(A),rank([A,b])ans=3ans=3%可见方程组唯一解x=A\bx=-0.4706-0.29410%Exercise2(3)A=[41;32;1-5];b=[1;1;1];rank(A),rank([A,b])ans=2ans=3%可见方程组无解x=A\bx=0.3311-0.1219%最小二乘近似解%Exercise2(4)a=[2,1,-1,1;1,2,1,-1;1,1,2,1];b=[123]';%注意b的写法rank(a),rank([a,b])ans=3ans=3%rank(a)==rank([a,b])4说明有无穷多解a\bans=1010%一个特解%Exercise3a=[2,1,-1,1;1,2,1,-1;1,1,2,1];b=[1,2,3]';x=null(a),x0=a\bx=-0.62550.6255-0.20850.4170x0=1010%通解kx+x0%Exercise4x0=[0.20.8]';a=[0.990.05;0.010.95];x1=a*x,x2=a^2*x,x10=a^10*xx=x0;fori=1:1000,x=a*x;end,xx=0.83330.1667x0=[0.80.2]';x=x0;fori=1:1000,x=a*x;end,xx=0.83330.1667[v,e]=eig(a)v=0.9806-0.70710.19610.7071e=1.0000000.9400v(:,1)./xans=1.17671.1767%成比例,说明x是最大特征值对应的特征向量%Exercise5%用到公式(3.11)(3.12)B=[6,2,1;2.25,1,0.2;3,0.2,1.8];x=[25520]';C=B/diag(x)C=0.24000.40000.05000.09000.20000.01000.12000.04000.0900A=eye(3,3)-CA=0.7600-0.4000-0.0500-0.09000.8000-0.0100-0.1200-0.04000.9100D=[171717]';x=A\Dx=37.569625.786224.7690%Exercise6(1)a=[41-1;32-6;1-53];det(a),inv(a),[v,d]=eig(a)ans=-94ans=0.2553-0.02130.04260.1596-0.1383-0.22340.1809-0.2234-0.0532v=0.0185-0.9009-0.3066-0.7693-0.1240-0.7248-0.6386-0.41580.6170d=-3.05270003.67600008.3766%Exercise6(2)a=[11-1;02-1;-120];det(a),inv(a),[v,d]=eig(a)ans=1ans=2.0000-2.00001.00001.0000-1.00001.00002.0000-3.00002.0000v=-0.57730.5774+0.0000i0.5774-0.0000i-0.57730.57740.5774-0.57740.5773-0.0000i0.5773+0.0000id=1.00000001.0000+0.0000i0001.0000-0.0000i%Exercise6(3)A=[5765;71087;68109;