计算题(6题共60%):要求熟练使用MATLAB 命令解题。
第三~七章各至少1题。
其中带∆号共出1题。
第三章(1)用矩阵除法解线性方程组;(ch3.ex2)解线性方程组⎪⎪⎩⎪⎪⎨⎧-=+=+--=-+=-+14235231543421431321x x x x x x x x x x x 。
>>A=[5 1 –1 0;1 0 3 –1;-1 –1 0 5;0 0 2 4];b=[1;2;3;-1]; x=A\b解线性方程组123411932621531x x x -⎛⎫⎛⎫⎛⎫⎪⎪ ⎪-=- ⎪⎪ ⎪ ⎪⎪ ⎪-⎝⎭⎝⎭⎝⎭。
>> A=[4 1 -1;3 2 -6;1 -5 3];b=[9;-2;1];>> rank(A), rank([A,b])ans =3,ans =3 %相等且为x 个数有唯一解;不等无解(最小二乘);相等不为x 个数无穷多解>> x=A\b(2)行列式det 、逆inv ;(ch3. ex6) p56411326153-⎛⎫ ⎪- ⎪ ⎪-⎝⎭>>a=[4 1 -1;3 2 -6;1 -5 3];det(a),inv(a),(3)特征值、特征向量eig ;(ch3.ex6)411326153-⎛⎫ ⎪- ⎪ ⎪-⎝⎭>>a=[4 1 -1;3 2 -6;1 -5 3]; [v,d]=eig(a)(4∆)线性方程组通解; (ch3.ex3) p58>>a=[2,1,-1,1;1,2,1,-1;1,1,2,1];b=[1,2,3]';>>rref([a,b])(5∆)矩阵相似对角化。
P59第四章(1)用roots 求多项式的根;p71>>roots([3 0 -4 0 2 -1])存在高次项237625685x x x x -+-,求其所有根,进行验算>>p=zeros(1,24);p([1 17 18 22])=[5 -6 8 -5]; x=roots(p),polyval(p,x)(2)用fzero 解非线性方程;(ch4.ex2) p72 eg4.3>>fun=@(x)x*sin(x^2-x-1) ; %一定是一元函数fplot(fun,[-2,0.1]);grid on;>>fzero(fun,[,])(3)用fsolve 解非线性方程组;(ch4.ex5,ex6) p74%方程组在某点或某区域附近的解求解下列方程组在区域0,1αβ<<内的解0.7sin 0.2cos 0.7cos 0.2sin ααββαβ=+⎧⎨=-⎩>>fun=@(x)[x(1)-0.7*sin(x(1))-0.2*cos(x(2)),x(2)-0.7*cos(x(1))+0.2*sin(x(2))];[a,b,c]=fsolve(fun,[0.5 0.5])(4)用fminbnd 求一元函数极值; (ch4.ex8)%极小值点,求极大值点fun2=inline([‘-’,str])clear;fun=@(x)x^2*sin(x^2-x-2);fplot(fun,[-2 2]);grid on; %作图观察x(1)=-2;x(3)=fminbnd(fun,-1,-0.5);x(5)=fminbnd(fun,1,2);fun2=@(x)-(x^2*sin(x^2-x-2)); %将fun 变号x(2)=fminbnd(fun2,-2,-1);x(4)=fminbnd(fun2,-0.5,0.5);x(6)=2fun=@(x)x.^2.*sin(x.^2-x-2); %注意用数组运算fun(x)(5)用fminsearch 求多元函数极值;(ch4.ex8,ex9) p76close;x=-2:0.1:1;y=-7:0.1:1;[x,y]=meshgrid(x,y);z=y.^3/9+3*x.^2.*y+9*x.^2+y.^2+x.*y+9;mesh(x,y,z);grid on;%作图观察, 可看到[0 0]附近极小值,[0 -5]附近极大值fun=@(x)x(2)^3/9+3*x(1)^2*x(2)+9*x(1)^2+x(2)^2+x(1)*x(2)+9;x=fminsearch(fun,[0 0])%求极小值fun2=@(x)-(x(2)^3/9+3*x(1)^2*x(2)+9*x(1)^2+x(2)^2+x(1)*x(2)+9);x=fminsearch(fun2,[0 -5])%求极大值(6∆)最小二乘拟合polyfit、lsqcurvefit;(ch4.ex10) p76第五章(1)用diff或gradiet求导数;(ch5.ex4) p91t=0:0.01:1.5;x=log(cos(t));y=cos(t)-t.*sin(t);dydx=gradient(y,x) %这里dydx仅仅是个普通变量名plot(x,dydx) %dydx函数图,作图观察x=-1时,dydx的值约0.9%以下是更精确的编程计算方法[x_1,id]=min(abs(x-(-1)));%找最接近x=-1的点,id为这个点的下标dydx(id)(2)用trapz、quadl或integral求积分;(ch5.ex5) p93Ex5(2)方法一:fun=@(x)exp(2*x).*cos(x).^3;integral(fun,0,2*pi)方法二用trapz:x=linspace(0,2*pi,100);y=exp(2*x).*cos(x).^3;trapz(x,y)(3)用dblquad(二元)或triplequad(三元)求矩形区域重积分;(ch5.ex5(6)) p94 fun=@(r,th)sqrt(1+r.^2.*sin(th));dblquad(fun,0,1,0,2*pi)(4∆)一般区域重积分quad2d, integral2, integral3;(ch5.ex5(7))p94fun=@(x,y)1+x+y.^2;%必须用点运算clo=@(x)-sqrt(2*x-x.^2);dhi=@(x)sqrt(2*x-x.^2);integral2(fun,0,2,clo,dhi)(5∆)函数单调性分析;(6∆)曲线长度或曲面面积。
(ch5.ex6) p90%先写参数方程x=2*cos(t);y=3*sin(t);%计算x'(t)=-2*sin(t),y'(t)=3*cos(t)%4*sin(t)^2+9*cos(t)^2=4+5*cos(t)^2fun=@(t)sqrt(4+5*cos(t).^2);quadl(fun,0,2*pi)ans = 15.8654第六章(1)用ode45求解微分方程;(ch6.ex1(1)) p107fun=@(x,y)x+y;[t,y]=ode45(fun,[0 1 2 3],1) %注意由于初值为y(0)=1, [0 1 2 3]中0不可缺(2)用ode45求解微分方程组;(ch6.ex1(2)) p109fun=@(t,y)[-2*y(1)-3*y(2);2*y(1)+y(2)];[t,y]=ode45(fun,[0 10],[-2.7;2.8])plot(y(:,1),y(:,2))(3)用ode45求解高阶微分方程;(ch6.ex1(3)) p109%高阶导数y''化为一阶(y')',多变量(y,y')化为单变量x.%令x(1)=y,x(2)=y',化为方程组%x(1)'=x(2),x(2)'=0.01*x(2)^2-2*x(1)+sin(t)%初始值x(1)=0,x(2)=1.%运行下列指令clear;close;fun=@(t,x)[x(2);0.01*x(2)^2-2*x(1)+sin(t)];%fun表示两个方程的右端,注意第一个x(2)表示x(1)的导函数。
[t,x]=ode45(fun,[0 5],[0;1]);x(end,1)plot(t,x(:,1))(4∆)齐次线性常系数微分方程通解;(ch6.ex2)roots([1 10 54 132 137 50])得到-3.0000 + 4.0000i-3.0000 - 4.0000i-2.0000-1.0000 + 0.0000i-1.0000 - 0.0000i%通解A1*exp(-3*t)*cos(4*t)+A2*exp(-3*t)*sin(4*t)+A3*exp(-2*t)+A4*exp(-t)+A5*t*exp(-t)(5 )边值问题求解(bvpinit, bvp5c, deval);(ch6.ex1(6)) p111%令y(1)=x, y(2)=x', 则方程为y'(1)=y(2), y'(2)=-2/t*y(2)+(2*y(1)+10*cos(log(t)))/t/t clear;close;sinit=bvpinit(1:0.5:3,[2;0]) %边值x(1)=1, x(3)=3, 估计x(t)=2, x'(t)=0.odefun=inline('[y(2);-2/t*y(2)+(2*y(1)+10*cos(log(t)))/t/t]','t','y');bcfun=inline('[ya(1)-1;yb(1)-3]','ya','yb');sol=bvp5c(odefun,bcfun,sinit)t=linspace(1,3,101);y=deval(sol,t);plot(t,y(1,:),sol.x,sol.y(1,:),'o',sinit.x,sinit.y(1,:),'s')legend('解曲线','解点','粗略解')y1=deval(sol,1.5:0.5:2.5);y1(1,:)第七章(1)符号对象syms, vpa, subs;(ch7.ex2) p125syms a;A=[1 2;2 a];iA=inv(A),[v,d]=eig(A)(2)符号函数factor, expand, simple;p129(3)符号极限limit, symsum;(ch7.ex4,ex5) p131syms x y;limit((3^x+9^x)^(1/x),x,inf)s1=limit(log(2*x+exp(-y))/sqrt(x^3+y^2),x,0,'right');s2=limit(s1,y,0,'right')syms k n x;s1=symsum(k^2,k,1,n);s1=simple(s1)s2=symsum(k^(-2),k,1,inf);s2=simple(s2)s3=symsum(1/(2*n+1)/(2*x+1)^(2*n+1),n,0,inf);s3=simple(s3)(4)符号微积分diff, taylor, int;(ch7.ex6,ex10) p131syms x y z;s=sin(x^2*y*z);s=diff(s,x,2);s=diff(s,y,1);s=subs(s,{x,y,z},{1,1,3})syms x y;f=(x-y)^3*sin(x+2*y);Ix=simple(int(f,y,-x,x))(5)符号解方程solve, vpasolve, dsolve;(ch7.ex12,ex13) P135syms x;solve(5*x^23-6*x^7+8*x^6-5*x^2)syms a b;[sa,sb]=vpasolve([a==0.7*sin(a)+0.2*cos(b),b==0.7*cos(a)-0.2*sin(b)],[a,b],[0.5,0.5])三、编程题(10%):要求使用MATLAB控制流语句编程,主要涉及for, while, if等语句以及关系与逻辑运算,M函数编写。