当前位置:文档之家› Matlab上机练习参考答案

Matlab上机练习参考答案

Matlab 上机练习二班级 学号 姓名按要求完成题目,并写下指令和运行结果。

(不需要画图)1、 求⎥⎦⎤⎢⎣⎡+-+-+-+-++=i 44i 93i 49i 67i 23i 57i 41i 72i 53i 84x 的共轭转置。

>> x=[4+8i 3+5i 2-7i 1+4i 7-5i;3+2i 7-6i 9+4i 3-9i 4+4i];>> x’ans =- -- ++ -- ++ -2、计算⎥⎦⎤⎢⎣⎡=572396a 与⎥⎦⎤⎢⎣⎡=864142b 的数组乘积。

>> a=[6 9 3;2 7 5];>> b=[2 4 1;4 6 8];>> a.*bans =12 36 38 42 403、 对于B AX =,如果⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=753467294A ,⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡=282637B ,求解X 。

>> A=[4 9 2;7 6 4;3 5 7];>> B=[37 26 28]’;>> X=A\BX =4、 ⎥⎦⎤⎢⎣⎡-=463521a ,⎥⎦⎤⎢⎣⎡-=263478b ,观察a 与b 之间的六种关系运算的结果。

>> a=[1 2 3;4 5 6];>> b=[8 –7 4;3 6 2];>> a>bans =0 1 01 0 1 >> a>=bans =0 1 01 0 1 >> a<bans =1 0 1 0 1 0 >> a<=bans =1 0 1 0 1 0 >> a==bans =0 0 0 0 0 0>> a~=bans =1 1 11 1 15、[]7.0=-a,在进行逻辑运算时,a相当于什么样的逻辑量。

82.05-相当于a=[1 1 0 1 1]。

6、角度[]60x,求x的正弦、余弦、正切和余切。

=3045>> x=[30 45 60];>> x1=x/180*pi;>> sin(x1)ans =>> cos(x1)ans =>> tan(x1)ans =>> cot(x1)ans =7、 用四舍五入的方法将数组[ ]取整。

>> b=[ ];>> round(b)ans =2 6 4 98、设⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡------=81272956313841A ,⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡-----=793183262345B ,求C1=A*B’;C2=A’*B;C3=A.*B,并求上述所有方阵的逆阵。

>> A=[1 4 8 13;-3 6 -5 -9;2 -7 -12 -8];>> B=[5 4 3 -2;6 -2 3 -8;-1 3 -9 7];>> C1=A*B'C1 =19 -82 3012 27 3-38 54 29>> C2=A'*BC2 =-15 16 -24 36 63 -17 93 -105 22 6 117 -60 19 46 84 -10 >> C3=A.*BC3 =5 16 24 -26 -18 -12 -15 72 -2 -21 108 -56 >> inv(C1)ans =>> inv(C2)Warning: Matrix is close to singular or badly scaled.Results may be inaccurate. RCOND = .ans =+015 *>> inv(C3)Error using ==> invMatrix must be square.9、设x=rcost+3t,y=rsint+3,分别令r=2,3,4,画出参数t=0~10区间生成的x~y 曲线。

>> t=linspace(0,10);>> r1=2;>> x1=(r1*cos(t)+3*t);>> y1=r1*sin(t)+3;>> r2=3;>> x2=(r2*cos(t)+3*t);>> y2=r2*sin(t)+3;>> r3=4;>> x3=(r3*cos(t)+3*t);>> y3=r3*sin(t)+3;>> plot(x1,y1,'r',x2,y2,'b',x3,y3,'m')10、设f(x)=x5- 4x4 +3x2- 2x+ 6(1) 在x=[-2,8]之间取100个点,画出曲线,看它有几个过零点。

(提示:用polyval 函数)>> x=linspace(2,8,100);>> y=polyval([1 0 -4 3 -2 6],x);>> plot(x,y,'b',x,0,'y')(2) 用roots函数求此多项式的根。

t=[1 0 -4 3 -2 6]p=roots(t)11、设x=sint, y=sin(nt+a),(1)若a=1,令n =1,2,3,4,在四个子图中分别画出其曲线。

(2)若n=2,取a=0,π/3,π/2,及π,在四个子图中分别画出其曲线。

(1)a=1;x=sin(t);y1=sin(1*t+a);y2=sin(2*t+a);y3=sin(3*t+a);y4=sin(4*t+a);subplot(2,2,1);plot(x,y1);subplot(2,2,2);plot(x,y2);subplot(2,2,3 );plot(x,y3);subplot(2,2,4);plot(x,y4)(2)n=2;x=sin(t);y1=sin(2*t+0);y2=sin(2*t+pi/3);y3=sin(2*t+pi/2);y4=s in(2*t+pi);subplot(2,2,1);plot(x,y1);subplot(2,2,2);plot(x,y2);su bplot(2,2,3);plot(x,y3);subplot(2,2,4);plot(x,y4)注:本题好像题目本身就有问题,因为“t”取值不明,所以运行不了,画不出图来。

转化为符号式来画图也是不可行的。

(纯粹个人意见,可能我想错了方向,会做的同学请上传一下正确的做法)12、求解多项式x3-7x2+2x+40的根。

>> r=[1 -7 2 40];>> p=roots(r);13、符号函数绘图法绘制函数x=sin(3t)cos(t),y=sin(3t)sin(t)的图形,t 的变化范围为[0,2]。

>> syms t>> ezplot(sin(3*t)*cos(t),sin(3*t)*sin(t),[0,pi])14、设,求x=sym('x'); y=(sin(x))^4+(cos(x))^4;diff(y,10)15、dx x x ⎰-632)9(x=sym('x');int((sqrt((9-x^2)^3)/x^6),x)16、⎰+213xx dx x=sym('x');int(x+x^3,x,1,2)17、求级数的和: ∑∞=+122n n n sym(‘n ’);symsum(n+2/2^n,n,1,inf)18、利用函数int 计算二重不定积分x=sym('x'); y=sym('y');z=(x+y)*exp(-x*y);a=int(z,x);int(a,y)19、试求出如下极限。

(1)x x x x 1)93(lim +∞→; (2)11lim 00-+→→xy xy y x ;dxdy e y x xy ⎰⎰-+)((1)>> syms x;f=(3^x+9^x)^(1/x);l=limit(f,x,inf)l =9(2)>> syms x y;f=x*y/(sqrt(x*y+1)-1);limit(limit(f,x,0),y,0) ans =2(3)>> syms x y;f=(1-cos(x^2+y^2))*exp(x^2+y^2)/(x^2+y^2);limit(limit(f,x,0),y,0) ans =20、已知参数方程⎩⎨⎧-==t t t y t x sin cos cos ln ,试求出x y d d 和3/22d d π=t x y >> symst;x=log(cos(t));y=cos(t)-t*sin(t);diff(y,t)/diff(x,t)ans =-(-2*sin(t)-t*cos(t))/sin(t)*cos(t)>> f=diff(y,t,2)/diff(x,t,2);subs(f,t,sym(pi)/3)ans =3/8-1/24*pi*3^(1/2)21、假设⎰-=xy t t e y x f 0d ),(2,试求222222y f y x f x f y x ∂∂+∂∂∂-∂∂>> syms x y t >> s=int(exp(-t^2),t,0,x*y);>> x/y*diff(f,x,2)-2*diff(diff(f,x),y)+diff(f,y,2)ans =2*x^2*y^2*exp(-x^2*y^2)-2*exp(-x^2*y^2)-2*x^3*y*exp(-x^2*y^2)22试求出下面的极限。

(1)⎥⎦⎤⎢⎣⎡-++-+-+-∞→1)2(1161141121lim 2222n n ; (2))131211(lim 2222ππππn n n n n n n ++++++++∞→ >> syms k n;symsum(1/((2*k)^2-1),k,1,inf)ans =1/2>> limit(symsum(1/((2*k)^2-1),k,1,n),n,inf)ans =1/2(2)>> limit(n*symsum(1/(n^2+k*pi),k,1,n),n,inf)ans =123、假设一曲线数据点为x=0:2:4*pi y=sin(x).*exp(-x/5)试将x的间距调成,并用下列方法进行内插:(1)线性内插法(method=’linear’)(2)样条内插法(method=’spline’)(3)三次多项式内插法(method=’cubic’)(4)多项式拟合法:直接利用6次多项式去通过7个数据点请将这些内插法的结果及原先的数据点画在同一个图上24、(15分)某一过程中通过测量得到:编程完成以下内容:(1) 分别采用三阶和四阶多项式对数据进行拟合;(提示:采用polyfit进行多项式拟合;调用格式为p = polyfit(t,y,n),n为多项式阶数,p为得到的多项式系数)(2) 比较拟合效果,要求把图形窗口分成两个子窗口,子窗口1绘制出原始测量值和三阶多项式拟合后的曲线,子窗口2绘制出原始测量值和四阶多项式拟合后的曲线;七、(15分)t = [0 ];y = [ ]; % 1分p1 = polyfit(t,y,3); % 1分p2 = polyfit(t,y,4); % 1分x = [0::5];y1 = polyval(p1,x); % 1分y2 = polyval(p2,x); % 1分subplot(1,2,1); % subplot 语句格式写对1分plot(t,y,'o',x,y1); % 也可使用hold on命令,正确画出第一个子图 2分subplot(1,2,2);plot(t,y,'o',x,y2); % 正确画出第二个子图 2分25、阅读以下程序并在指定位置上写注释(6分)t=(0::2)*pi;x=sin(t);y=cos(t);z=cos(2*t);plot3(x,y,z,'r-',x,y,z,'bd') %___(1)_绘制一条红色连续曲线和蓝色菱形离散点view([-82,58]) %___(2)__以方位角-82度,俯角58度观察视图box on %显示坐标轴的矩形框legend('图形','视角') %__ (3)_标注图例______hold on %__(4)_保持图形_____x=-4:4;y=x;[X,Y]=meshgrid(x,y); %__(5)_生成平面网格坐标矩阵__Z=X.^2+Y.^2;surf(X,Y,Z); %__ (6)_绘制三维曲面_26、编写一个M 函数文件fun_es(x),计算如下函数:)sin(5.023/x x e y x -=,其中参数可以为标量,也可以为向量。

相关主题