MATLAB第一章作业答案
MATLAB作业1 参考答案
MATLAB 作业1参考答案1 、在你的机器上安装MATLAB 语言环境,并键入demo 命令,由给出的菜单系统和对话框原型演示程序,领略MATLAB 语言在求解数学问题方面的能力与方法。
【求解】略.2、启动MATLAB 环境,并给出语句tic, A=rand(500); B=inv(A); norm(A*B-eye(500)),toc ,试运行该语句,观察得出的结果,并利用help 命令对你不熟悉的语句进行帮助信息查询,逐条给出上述程序段与结果的解释。
【求解】在MATLAB 环境中感触如下语句,则可以看出,求解500500⨯随机矩阵的逆,并求出得出的逆矩阵与原矩阵的乘积,得出和单位矩阵的差,得出范数。
一般来说,这样得出的逆矩阵精度可以达到1210-。
>> tic, A=rand(500); B=inv(A); norm(A*B-eye(500)), tocans =1.2333e-012Elapsed time is 1. seconds.3、试用符号元素工具箱支持的方式表达多项式5432()34236f x x x x x x =+++++,并令11s x s -=+,将f(x) 替换成s 的函数。
【求解】可以先定义出f 函数,则由subs() 函数将x 替换成s 的函数>> syms s x;f=x^5+3*x^4+4*x^3+2*x^2+3*x+6;F=subs(f,x,(s-1)/(s+1)) F =(s-1)^5/(s+1)^5+3*(s-1)^4/(s+1)^4+4*(s-1)^3/(s+1)^3+2*(s-1)^2/(s+1)^2+3*(s-1)/(s+1)+6syms x sx=(s-1)./(s+1);y=x.^5+3*x.^4+4*x.^3+2*x.^2+3*x+6;ysimple(y)y=19 - (72*s^4 + 120*s^3 + 136*s^2 + 72*s + 16)/(s + 1)^54、用MATLAB 语句输入矩阵A 和B123414233241432141322314,234123324114324132234114j j j j j j j j A B j j j j j j j j ++++⎡⎤⎡⎤⎢⎥⎢⎥++++⎢⎥⎢⎥==⎢⎥⎢⎥++++⎢⎥⎢⎥++++⎣⎦⎣⎦前面给出的是4 ×4 矩阵,如果给出A(5; 6) = 5 命令将得出什么结果?【求解】用课程介绍的方法可以直接输入这两个矩阵>> A=[1 2 3 4; 4 3 2 1; 2 3 4 1; 3 2 4 1]A =1 2 3 44 3 2 12 3 4 13 24 1若给出A(5,6)=5 命令,虽然这时的行和列数均大于B 矩阵当前的维数,但仍然可以执行该语句,得出>> A(5,6)=5A =1 2 3 4 0 04 3 2 1 0 02 3 4 1 0 03 24 1 0 00 0 0 0 0 5复数矩阵也可以用直观的语句输入>> B=[1+4i 2+3i 3+2i 4+1i; 4+1i 3+2i 2+3i 1+4i;2+3i 3+2i 4+1i 1+4i; 3+2i 2+3i 4+1i 1+4i];B =1.0000 + 4.0000i2.0000 +3.0000i 3.0000 + 2.0000i4.0000 + 1.0000i4.0000 + 1.0000i 3.0000 + 2.0000i 2.0000 + 3.0000i 1.0000 + 4.0000i2.0000 +3.0000i 3.0000 + 2.0000i4.0000 + 1.0000i 1.0000 + 4.0000i3.0000 + 2.0000i 2.0000 + 3.0000i4.0000 + 1.0000i 1.0000 + 4.0000i5、假设已知矩阵A ,试给出相应的MATLAB 命令,将其全部偶数行提取出来,赋给B 矩阵,用A =magic(8) 命令生成A 矩阵,用上述的命令检验一下结果是不是正确。
MATLAB第一章作业答案
第一章 M A T L A B 概况与基本操作1.选择题(每题2分,共20分):(1)最初的MATLAB 核心程序是采用D 语言编写的。
A.PASCALB.CC.BASICD.FORTRAN(2)即将于2011年9月发布的MATLAB 新版本的编号为C 。
A.MATLAB 2011RaB.MATLAB 2011RbC.MATLAB R2011bD.MATLAB R2011a(3)在默认设置中,MATLAB 中的注释语句显示的颜色是B 。
A.黑色B.绿色C.红色D.蓝色(4)如果要以科学计数法显示15位有效数字,使用的命令是A 。
A.format long eB.format longC.format long gD.format long d(5)在命令窗口新建变量a 、b ,如果只查看变量a 的详细信息,使用的命令为A 。
A.whos aB.who aC.whoD.whos(6)如果要清除工作空间的所有变量,使用的命令为C 。
A.clearB.clear allC.两者都可D.两者都不可(7)在创建变量时,如果不想立即在命令窗口中输出结果,可以在命令后加上B 。
A.冒号B.分号C.空格D.逗号(8)如果要重新执行以前输入的命令,可以使用D 键。
A.下箭头↓B.右箭头→C.左箭头←D.上箭头↑(9)如果要查询函数det 的功能和用法,并显示在命令窗口,应使用命令C 。
A.docB.lookforC.helpD.三者均可(10)如果要启动Notebook 文档,下列D 操作是可行的。
A.在命令窗口输入notebook 命令B.在命令窗口输入notebook filename 命令C.在Word 中启动M-book 文档D.三者均可2.填空题(每空1分,共20分):(1)MATLAB 是matrix 和laboratory 两个单词前三个字母的组合,意为“矩阵实验室”,它的创始人是Cleve Moler 和Jack Little 。
matlab1-8章课后作业
MATLAB基础教程 1~8章作业Matlab第一章1.阐述Matlab的功能Matlab作为一种高级计算软件,是进行算法开发、数据可视化、数据分析以及数值计算的交互式应用开发环境,已被广泛应用于不同领域。
Matlab的基本功能包括:数学计算功能、图形化显示功能、M语言编程功能、编译功能、图形用户界面开发功能、Simulink 建模仿真功能、自动代码生成功能。
Matlab第二章1.创建double的变量,并进行计算。
(1) a=87,b=190,计算 a+b、a-b、a*b。
(2)创建 uint8 类型的变量,数值与(1)中相同,进行相同的计算。
>> a=87,b=190a =87b =190>> a+bans =277>> a-bans =-103>> a*bans =16530>> c=uint8(87), d=uint8(190)c =87d =190>> c+dans =255>> c-dans =>> c*dans =2552.计算(1)sin(60)(2)e^3(3)cos(3π/4)>> sind(60)ans =0.8660>> exp(3)ans =20.0855>> cos(3*pi/4)ans =-0.70713.设u=2,v=3,计算:(1)(2)(3)>> u=2;>> v=3;>> 4*u*v/log(v)ans =21.8457>> (exp(u)+v)^2/(v^2-u)ans =15.4189>> sqrt(u-3*v)/(u*v)ans =0 + 0.4410i4.计算如下表达式:(1)(2)>> (3-5*i)*(4+2*i)ans =22.0000 -14.0000i>> sin(2-8*i)ans =1.3553e+003 +6.2026e+002i5.判断下面语句的运算结果。
MATLAB作业1 参考答案-推荐下载
3、试用符号元素工具箱支持的方式表达多项式 f (x) x5 3x4 4x3 2x2 3x 6 ,并 Nhomakorabea令x
s 1
,将f(x)
s 1
替换成s
的函数。
【求解】可以先定义出f 函数,则由subs() 函数将x 替换成s 的函数
>> syms s x;f=x^5+3*x^4+4*x^3+2*x^2+3*x+6;F=subs(f,x,(s-1)/(s+1))
end 其中,前者语句结构简单,但适用范围更广,允许使用矩阵型x,后者只能使用向量型的 x,但不能处理矩阵问题。
63
7、用数值方法可以求出 S 2i 1 2 4 8 262 263 ,试不采用循环的形式求 i0
出 和式的数值解。由于数值方法采用double 形式进行计算的,难以保证有效位数字,所以结 果不一定精确。试采用符号运算的方法求该和式的精确值。 【求解】用符号运算的方式可以采用下面语句 >> sum(sym(2).^[1:63]) ans = 18446744073709551614 由于结果有19 位数值,所以用double 型不能精确表示结果,该数据类型最多表示16 位有 效数字。其实用符号运算方式可以任意保留有效数字,例如可以求200 项的和或1000 项的 和可以由下面语句立即得出。 >> sum(sym(2).^[1:200]) ans = 3213876088517980551083924184682325205044405987565585670602750 >> sum(sym(2).^[1:1000]) 第一种方法 i=0; s=0; for i=0:63
(完整版)汽车理论课后作业答案MATLAB
汽车理论作业 MA TLAB 过程010203040506070809010050001000015000汽车驱动力与阻力平衡图u a /km.h -1F /N10203040506070809010002468101214加速度倒数-速度曲线图u1/a0102030405060708090100102030405060u/(km/h)P /k W汽车功率平衡图10203040506070809010012141618202224最高档等速百公里油耗曲线Ua/(km/h)Q s /L2324252627282912131415161718燃油积极性-加速时间曲线燃油经济性(qs/L)动力性--原地起步加速时间 (s t /s )源程序:《第一章》m=3880; g=9.8; r=0.367; x=0.85; f=0.013; io=5.83; CdA=2.77; If=0.218; Iw1=1.798; Iw2=3.598; Iw=Iw1+Iw2;ig=[6.09 3.09 1.71 1.00]; %变速器传动比 L=3.2; a=1.947; hg=0.9; n=600:1:4000;T=-19.313+295.27*n/1000-165.44*(n/1000).^2+40.874*(n/1000).^3-3.8445*(n/1000).^4; Ft1=T*ig(1)*io*x/r;%计算各档对应转速下的驱动力Ft2=T*ig(2)*io*x/r;Ft3=T*ig(3)*io*x/r;Ft4=T*ig(4)*io*x/r;u1=0.377*r*n/(io*ig(1));u2=0.377*r*n/(io*ig(2));u3=0.377*r*n/(io*ig(3));u4=0.377*r*n/(io*ig(4));u=0:130/3400:130;F1=m*g*f+CdA*u1.^2/21.15;%计算各档对应转速下的驱动阻力F2=m*g*f+CdA*u2.^2/21.15;F3=m*g*f+CdA*u3.^2/21.15;F4=m*g*f+CdA*u4.^2/21.15;figure(1);plot(u1,Ft1,'-r',u2,Ft2,'-m',u3,Ft3,'-k',u4,Ft4,'-b',u1,F1,'-r',u2,F2,'-m',u3,F3,'-k',u4,F4,'-b','LineWidth',2)title('汽车驱动力与阻力平衡图');xlabel('u_{a}/km.h^{-1}')ylabel('F/N')gtext('F_{t1}')gtext('F_{t2}')gtext('F_{t3}')gtext('F_{t4}')gtext('F_{f}+F_{w}')%由汽车驱动力与阻力平衡图知,他们无交点,u4在最大转速时达到最大umax=u4(3401)Ft1max=max(Ft1);imax=(Ft1max-m*g*f)/(m*g)disp('假设是后轮驱动');C=imax/(a/L+hg*imax/L) % 附着率delta1=1+(Iw1+Iw2)/(m*r^2)+If*ig(1)*r^2*io^2*x/(m*r^2);delta2=1+(Iw1+Iw2)/(m*r^2)+If*ig(2)*r^2*io^2*x/(m*r^2);delta3=1+(Iw1+Iw2)/(m*r^2)+If*ig(3)*r^2*io^2*x/(m*r^2);delta4=1+(Iw1+Iw2)/(m*r^2)+If*ig(4)*r^2*io^2*x/(m*r^2);a1=(Ft1-F1)/(delta1*m); %加速度a2=(Ft2-F2)/(delta2*m);a3=(Ft3-F3)/(delta3*m);a4=(Ft4-F4)/(delta4*m);h1=1./a1; %加速度倒数h2=1./a2;h3=1./a3;h4=1./a4;figure(2);plot(u1,h1,u2,h2,u3,h3,u4,h4,'LineWidth',2); title('加速度倒数-速度曲线图');xlabel('u')ylabel('1/a')gtext('1/a1')gtext('1/a2')gtext('1/a3')gtext('1/a4')%由加速度倒数-速度曲线图可知u1min=min(u1);u1max=max(u1);u2min=u1max;u2min=min(u2);u2max=max(u2);u3min=u2max;u3max=max(u3);u4min=u3max;u4max=70;x1=[];x2=[];x3=[];x4=[];y=3401;for i=1:3401;if u3(i)<=u3min;x1=[i];endendq1=max(x1);ua3=u3(q1:y);a3=h3(q1:y);for i=1:3401;if u4(i)<=u4min;x2=[i];elseif u4(i)<=u4max;x3=[i];endendq2=max(x2);q3=max(x3);ua4=u4(q2:q3);a4=h4(q2:q3);s1=trapz(h2,u2 ); %二挡运行时间s2=trapz(ua3,a3);s3=trapz(ua4,a4);s=[s1 s2 s3];disp('积分得')t=sum(s)*1000/3600 %总时间《第二章》Pe1=Ft1.*u1./3600;%计算各档对应转速下的功率Pe2=Ft2.*u2./3600;Pe3=Ft3.*u3./3600;Pe4=Ft4.*u4./3600;P1=F1.*u1./(3600*x);%计算各档对应的各个车速下的行驶功率P2=F2.*u2./ (3600*x);P3=F3.*u3./ (3600*x);P4=F4.*u4./ (3600*x);figure(3);plot(u1,Pe1,'-r',u2,Pe2,'-m',u3,Pe3,'-k',u4,Pe4,'-b',u1,P1,'k',u2,P2,'k',u3,P3,'k', u4,P4,'k','linewidth',2);gtext('Pe1')gtext('Pe2')gtext('Pe3')gtext('Pe4')xlabel('u/(km/h)');ylabel('P/kW');title('汽车功率平衡图');n=[815 1207 1614 2012 2603 3006 3403 3804];Ua=[];Ua=0.377*r*n./(io*ig(4))ft=[];ft=m*g*f+(2.77/21.15)*Ua.^2;%计算各转速对应的各个车速下的行驶阻力Pe(1)=ft(1).*Ua(1)./(3600*x);%计算各转速对应的各个车速下的行驶阻力功率Pe(2)=ft(2).*Ua(2)./(3600*x);Pe(3)=ft(3).*Ua(3)./(3600*x);Pe(4)=ft(4).*Ua(4)./(3600*x);Pe(5)=ft(5).*Ua(5)./(3600*x);Pe(6)=ft(6).*Ua(6)./(3600*x);Pe(7)=ft(7).*Ua(7)./(3600*x);Pe(8)=ft(8).*Ua(8)./(3600*x)B0=[1326.8 1354.7 1284.4 1122.9 1141.0 1051.2 1233.9 1129.7];B1=[-416.46 -303.98 -189.75 -121.59 -98.893 -73.714 -84.478 -45.291];B2=[72.739 36.657 14.525 7.0035 4.4763 2.8593 2.9788 0.7113];B3=[-5.8629 -2.0533 -0.51184 -0.18517 -0.091077 -0.05138 -0.047449 -0.00075215];B4=[0.17768 0.043072 0.0068164 0.0018555 0.00068906 0.00035032 0.00028230-0.000038568];b1=(B0(1))+(B1(1)*Pe(1))+(B2(1)*Pe(1)^2)+(B3(1)*Pe(1)^3)+(B4(1)*Pe(1)^4);b2=(B0(2))+(B1(2)*Pe(2))+(B2(2)*Pe(2)^2)+(B3(2)*Pe(2)^3)+(B4(2)*Pe(2)^4);b3=(B0(3))+(B1(3)*Pe(3))+(B2(3)*Pe(3)^2)+(B3(3)*Pe(3)^3)+(B4(3)*Pe(3)^4);b4=(B0(4))+(B1(4)*Pe(4))+(B2(4)*Pe(4)^2)+(B3(4)*Pe(4)^3)+(B4(4)*Pe(4)^4);b5=(B0(5))+(B1(5)*Pe(5))+(B2(5)*Pe(5)^2)+(B3(5)*Pe(5)^3)+(B4(5)*Pe(5)^4);b6=(B0(6))+(B1(6)*Pe(6))+(B2(6)*Pe(6)^2)+(B3(6)*Pe(6)^3)+(B4(6)*Pe(6)^4);b7=(B0(7))+(B1(7)*Pe(7))+(B2(7)*Pe(7)^2)+(B3(7)*Pe(7)^3)+(B4(7)*Pe(7)^4);b8=(B0(8))+(B1(8)*Pe(8))+(B2(8)*Pe(8)^2)+(B3(8)*Pe(8)^3)+(B4(8)*Pe(8)^4);p=0.7;Qs=[];Qs(1)=(Pe(1)*b1)/(1.02*Ua(1).*p*g);Qs(2)=(Pe(2)*b2)/(1.02*Ua(2).*p*g);Qs(3)=(Pe(3)*b3)/(1.02*Ua(3).*p*g);Qs(4)=(Pe(4)*b4)/(1.02*Ua(4).*p*g);Qs(5)=(Pe(5)*b5)/(1.02*Ua(5).*p*g);Qs(6)=(Pe(6)*b6)/(1.02*Ua(6).*p*g);Qs(7)=(Pe(7)*b7)/(1.02*Ua(7).*p*g);Qs(8)=(Pe(8)*b8)/(1.02*Ua(8).*p*g);M=polyfit(Ua,Qs,2);UA=0.377*r*600/(ig(4)*io):1:0.377*r*4000/(ig(4)*io);%UA表示车速QS=polyval(M,UA);%QS表示油耗figure(4);plot(UA,QS,'linewidth',2);title('最高档等速百公里油耗曲线');xlabel('Ua/(km/h)');ylabel('Qs/L');《第三章》io=[5.17 5.43 5.83 6.17 6.33];Va=0.377*r*n(7)./(io.*ig(4));Ps=46.9366;disp('假设以最高档,较高转速(n取3401 ),最经济负荷(即90%负荷大约 46.9366Kw)行驶时油耗')qs=[];qs(1)=(Ps*b7)/(1.02*Va(1).*p*g);qs(2)=(Ps*b7)/(1.02*Va(2).*p*g);qs(3)=(Ps*b7)/(1.02*Va(3).*p*g);qs(4)=(Ps*b7)/(1.02*Va(4).*p*g);qs(5)=(Ps*b7)/(1.02*Va(5).*p*g);st=[ 17.5813 16.2121 14.5126 13.3775 12.9185];%加速时间:(这里以最高档〈四档〉、速度由0加速到94.93Km/h 的时间)因与题1.3第三问求法相同,这里不在累述,可直接有计算机求得:figure(5);plot(qs,st,'+','linewidth',2)hold on plot(qs,st,); gtext('5.17') gtext('5.43') gtext('5.83') gtext('6.17') gtext('6.33')title('燃油积极性-加速时间曲线'); xlabel('燃油经济性(qs/L)');ylabel('动力性--原地起步加速时间 (st/s)');《第四章》 4-31)前轴利用附着系数为:gf zh b zL +=βϕ后轴利用附着系数为: ()gr zh a zL --=βϕ1空载时:g h b L -=βϕ0=413.0845.085.138.095.3-=-⨯所以0ϕϕ>空载时后轮总是先抱死。
数字图像处理及应用(MATLAB)第1章习题答案
第一章:习题与思考题参考答案1-1 什么是数字图像? 数字图像处理有哪些特点?数字图像是将连续的模拟图像经过离散化处理后变成计算机能够辨识的点阵图像。
数字图像处理具有以下特点:(1)处理精度高,再现性好。
(2)易于控制处理效果。
(3)处理的多样性。
(4)数字图像中各个像素间的相关性大,压缩的潜力很大。
(5)图像数据量庞大。
(6) 占用的频带较宽。
(7) 图像质量评价受主观因素的影响。
(8)图像处理技术综合性强。
1-2 数字图像处理的目的及主要内容。
一般而言,对图像进行处理主要有以下三个方面的目的(1) 提高图像的视感质量,以达到赏心悦目的目的。
(2) 提取图像中所包含的某些特征或特殊信息,以便于计算机分析。
(3) 对图像数据进行变换、编码和压缩,以便于图像的存储和传输。
数字图像处理的主要研究内容:根据其主要的处理流程与处理目标大致可以分为图像信息的描述、图像信息的处理、图像信息的分析、图像信息的编码以及图像信息的显示等几个方面。
如:图像数字化、图像增强、图像几何变换、图像复原、图像重建、图像隐藏、图像正交变换、图像编码、图像分析等。
1-3 数字图像处理的主要应用图像处理技术广泛用于众多的科学与工程领域,主要有:(1)生物医学领域中的应用(2)工业应用(3)遥感航天中的应用(4)军事、公安领域中的应用(5)其他应用,例如:图像的远距离通信;多媒体计算机系统及应用;服装试穿显示;办公自动化、现场视频管理1-4 在理想情况下获得一幅数字图像时,采样和量化间隔越小,图像的画面效果越好,当一幅图像的数据量被限定在一个范围内时,如何考虑图像的采样和量化使得图像的质量尽可能好。
一般,当限定数字图像的大小时, 为了得到质量较好的图像可采用如下原则: (1)对缓变的图像,应该细量化,粗采样,以避免假轮廓。
(2)对细节丰富的图像,应细采样,粗量化,以避免模糊(混叠)。
1-5 想想在你的工作和生活中,遇见过哪些数字化设备?它们的主要用途是什么?主要有以下几种数字化设备:(1) 图像采集卡通常图像采集卡安装于计算机主板扩展槽中,通过主机发出指令,将某一帧图像静止在存储通道中,即采集或捕获一帧图像,然后可对图像进行处理或存盘。
matlab课后习题答案(1-9章)
1 数字1.5e2,1.5e3 中的哪个与1500相同吗?1.5e32 请指出如下5个变量名中,哪些是合法的?abcd-2xyz_33chan a 变量ABCDefgh 2、5是合法的。
3 在MATLAB 环境中,比1大的最小数是多少? 1+eps4 设 a = -8 , 运行以下三条指令,问运行结果相同吗?为什么?w1=a^(2/3) w2=(a^2)^(1/3) w3=(a^(1/3))^2w1 = -2.0000 + 3.4641i ;w2 = 4.0000 ;w3 =-2.0000 + 3.4641i 5 指令clear, clf, clc 各有什么用处?clear 清除工作空间中所有的变量。
clf 清除当前图形。
clc 清除命令窗口中所有显示。
第二章1 说出以下四条指令产生的结果各属于哪种数据类型,是“双精度”对象,还是“符号”符号对象?3/7+0.1双; sym(3/7+0.1)符; sym('3/7+0.1') 符;; vpa(sym(3/7+0.1)) 符;2 在不加专门指定的情况下,以下符号表达式中的哪一个变量被认为是自由符号变量. sym('sin(w*t)'),sym('a*exp(-X)'),sym('z*exp(j*th)') symvar(sym('sin(w*t)'),1) w a z3 (1)试写出求三阶方程05.443=-x 正实根的程序。
注意:只要正实根,不要出现其他根。
(2)试求二阶方程022=+-a ax x 在0>a 时的根。
(1)reset(symengine)syms x positive solve(x^3-44.5) ans =(2^(2/3)*89^(1/3))/2(2)求五阶方程022=+-a ax x 的实根 syms a positive %注意:关于x 的假设没有去除 solve(x^2-a*x+a^2)Warning: Explicit solution could not be found. > In solve at 83 ans =[ empty sym ]syms x clear syms a positivesolve(x^2-a*x+a^2) ans =a/2 + (3^(1/2)*a*i)/2 a/2 - (3^(1/2)*a*i)/24 观察一个数(在此用@记述)在以下四条不同指令作用下的异同。
matlab课后习题及答案详解
matlab课后习题及答案详解第1章练习题1.安装matlab时,在选择组件窗口中哪些部分必须勾选,没有勾选的部分以后如何补安装?在安装matlab时,安装内容由选择组件窗口中个复选框是否被勾选来决定,可以根据自己的需要选择安装内容,但基本平台(即matlab选项)必须安装。
第一次安装没有选择的内容在补安装时只需按照安装的过程进行,只是在选择组件时只勾选要补装的组件或工具箱即可。
2.matlab操作方式桌面存有几个窗口?如何并使某个窗口瓦解桌面沦为单一制窗口?又如何将瓦解过来的窗口再次置放至桌面上?与其他计算机语言相比较,matlab语言注重的特点就是什么?matlab系统由那些部分共同组成?在matlab操作桌面上有五个窗口,在每个窗口的右上角有两个小按钮,一个是关闭窗口的close按钮,一个是可以使窗口成为独立窗口的undock按钮,点击undock按钮就可以使该窗口脱离桌面成为独立窗口,在独立窗口的view菜单中选择dock……菜单项就可以将独立的窗口重新防止的桌面上。
matlab具备功能强大、使用方便、输出简便、库函数多样、开放性弱等特点。
matlab系统主要由开发环境、matlab数学函数库、matlab语言、图形功能和应用程序接口五个部分组成。
3.如何设置当前目录和搜寻路径,在当前目录上的文件和在搜寻路径上的文件存有什么区别?命令历史窗口除了可以观测前面键入的命令外,除了什么用途?当前目录可以在当前目录浏览器窗口左上方的输入栏中设置,搜索路径可以通过选择操作桌面的file菜单中的setpath菜单项来完成。
在没有特别说明的情况下,只有当前目录和搜索路径上的函数和文件能够被matlab运行和调用,如果在当前目录上有与搜索路径上相同文件名的文件时则优先执行当前目录上的文件,如果没有特别说明,数据文件将存储在当前目录上。
命令历史窗口除了用作查阅以前键入的命令外,还可以轻易执行命令历史窗口中选取的内容、将选取的内容拷贝到剪贴板中、将选取内容轻易拷贝到m文件中。
915204-MATLAB程序设计与应用-第1章 MATLAB系统环境_习题答案
第1章 MATLAB系统环境习题1一、选择题1.最初的MA TLAB核心程序是采用()语言编写的。
AA.FORTRAN B.C C.BASIC D.PASCAL2.2016年3月发布的MA TLAB版本的编号为()。
BA.MA TLAB 2016Ra B.MA TLAB R2016aC.MATLAB 2016Rb D.MA TLAB R2016b3.下列选项中能反应MA TLAB特点的是()。
DA.算法最优B.不需要写程序C.程序执行效率高D.编程效率高4.当在命令行窗口执行命令时,如果不想立即在命令行窗口中输出结果,可以在命令后加上()。
CA.冒号(:)B.逗号(,)C.分号(;)D.百分号(%)5.如果要重新执行以前输入的命令,可以使用()。
DA.左移光标键(←)B.右移光标键(→)C.下移光标键(↓)D.上移光标键(↑)6.MA TLAB命令行窗口中提示用户输入命令的符号是()。
BA.> B.>> C.>>> D.>>>>7.plot(x,y)是一条()命令。
CA.打印B.输出C.绘图D.描点8.以下两个命令行的区别是()。
A>> x=5,y=x+10>> x=5,y=x+10;A.第一个命令行同时显示x和y的值,第二个命令行只显示x的值B.第一个命令行同时显示x和y的值,第二个命令行只显示y的值C.第一个命令行只显示x的值,第二个命令行同时显示x和y的值D.第一个命令行只显示y的值,第二个命令行同时显示x和y的值9.下列命令行中,输出结果与其他3项不同的是()。
DA.>> 10+20+... B.>> ...30 10+20+30C.>> 10+20+30%5 D.>> %10+20+3010.下列选项中,不是MATLAB帮助命令的是()。
CA.lookfor B.lookfor –all C.search D.help二、填空题1.MA TLAB一词来自的缩写。
MATLAB第1-8章答案
第1章一、思考题4. (1) B=A(2:5,1:2:5)(2)A(7)=[](3) A=A+30(4)size(A)(5) t(find(t==0))=eps(6)t=reshape(x,3,4)(7)abs('matlab')(8)char(93)5. A=[97,67,34,10;-78,75,65,5;32,5,-23,-59;0,-12,54,7](1) B=A(1:3,:)C=A(:,1:2)D=A(2:4,3:4)E=B*C(2)A(find(A>=50 & A<=100))二、实验题1.x=-74/180*pi;y=-27/180*pi;sin(x*x+y*y)/sqrt(tan(abs(x+y)))+pi2.a=-3.0:0.1:3.0;exp(-0.3*a).*sin(a+0.3)3.x=[2,4;-0.45,5];log(x+sqrt(1+x.*x))/24. A=[3,54,2;34,-45,7;87,90,15];B=[1,-2,67;2,8,74;9,3,0]; (1)A*Bans =129 432 41977 -407 -1052402 591 12489A.*Bans =3 -108 13468 -360 518783 270 0(2) A^3ans =-28917 240246 -4368137883 -259101 27669171333 252504 38673A.^3ans =27 157464 839304 -91125 343658503 729000 3375(3)A/Bans =-5.8845 5.3549 -0.20286.3554 -5.6596 4.3293-6.6325 6.2078 9.0241B/Aans =30.2855 19.2643 -8.561433.4394 21.1547 -9.3974-0.7443 -0.3938 0.2830(4)[A,B]ans =3 54 2 1 -2 6734 -45 7 2 8 7487 90 15 9 3 0[A([1,3],:);B^2]ans =3 54 287 90 15600 183 -81684 282 72615 6 8255.a=1+2i;b=3+4i;c=exp(pi*i/6)c =0.8660 + 0.5000ic+a*b/(a+b)ans =1.6353 + 1.8462i第2章一、思考题3.s=0;for n=0:63s=s+2^n;enddisp(s)n=0:63;s=sum(2.^n)二、实验题1.x=input('输入一个四位整数:');y=[fix(x/1000),mod(fix(x/100),10),mod(fix(x/10),10),mod(x,10)] z=mod((y+7),10)x=z(3)*1000+z(4)*100+z(1)*10+z(2)2.gh=input('输入工号');h=input('输入工时');dj=84;if h>120gz=dj*120+1.15*dj*(h-120);elseif h<60gz=dj*h-700;elsegz=dj*h;endformat bank;display([gh,gz])3.循环结构n=input('input n:');s=0;for k=1:ns=s+1/k^2;enddisplay(sqrt(s*6))向量运算n=input('input n:');k=1:n;display(sqrt(sum(1./k.^2)*6))4.y=0;k=0;while y<3k=k+1;y=y+1/(2*k-1);enddisplay([k-1,y-1/(2*k-1)])5.x0=0;x=1;k=0;a=input('a=');b=input('b=');while abs(x-x0)>=1e-5 && k<500x0=x;x=a/(b+x0);k=k+1;enddisplay([k,x]);display([(-b+sqrt(b^2+4*a))/2,(-b-sqrt(b^2+4*a))/2]);6.y=fun(40)/(fun(30)+fun(20))(1)函数文件fun.mfunction f=fun(n)f=n+log(n^2+5);(2)函数文件fun.mfunction f=fun(n)a=1:n;f=sum(a.*(a+1));第3章一、思考题4.t=0:0.01:1.5;y=sqrt(3)/2*exp(-4*t).*sin(4*sqrt(3)*t+pi/3);5.x=-10:0.01:10;y=linspace(-6,6,size(x,2))z=x.^3+3*x.*y.^2;plot3(x,y,z)6.x=100:100:400;y=100:100:400;z=[636,697,624,478;698,712,630,478;680,674,598,412;662,626,552,334]; [X,Y]=meshgrid(x,y);mesh(X,Y,z)二、实验题1.(1)x=-10:0.01:10;plot(x,x-x.^3/3/2)(2)plot(x,exp(-x.*x/2)/2/pi)(3)x=-8:0.01:8;plot(x,sqrt((64-x.*x)/2))(4)t=0:pi/100:6*pi;plot(t.*sin(t),t.*cos(t))2. (1)x1=linspace(0,1,100);y1=2*x1-0.5;t=linspace(0,pi,100);x=sin(3*t).*cos(t);y=sin(3*t).*sin(t);plot(x1,y1,'r-',x,y,'b:');text(0.4,1,'y=2x-0.5');text(-0.4,0.5,'x=sin(3t)cos(t)');text(-0.4,0.3,'y=sin(3t)sin(t)');(2)subplot(1,2,1);scatter(x1,y1,10)title('y=2x-0.5');subplot(1,2,2);scatter(x,y,10)3.subplot(1,21);x=1:1:100; y=sin(1./x);plot(x,y)subplot(1,2,2);fplot('sin(1/x)',[1,100])4.subplot(2,2,1);bar(t,y);subplot(2,2,2);stairs(t,y);subplot(2,2,3);stem(t,y)subplot(2,2,4);semilogy(t,y);5.theta=linspace(-pi,pi,100);ro=5.*cos(theta)+4;polar(theta,ro);fi=linspace(0,2*pi,100);a=1r=a.*(1+cos(fi));polar(fi,r);6.t=0:pi/20:2*pi;x=exp(-t./20).*cos(t);y=exp(-t./20).*sin(t);z=t; plot3(x,y,z);t=0:0.01:1;x=t;y=t.^2;z=t.^3;plot3(x,y,z);7.x=-30:0.1:0;y=0:0.1:30;[x,y]=meshgrid(x,y);z=10.*sin(sqrt(x.^2+y.^2))./sqrt(1+x.^2+y.^2); meshc(x,y,z);8.x=linspace(-3,3,100);y=linspace(-3,3,100);[x y]=meshgrid(x,y);fxy=-5./(1+x.^2+y.^2);i=find(abs(x)<=0.8 & abs(y)<=0.5);fxy(i)=NaN;surf(x,y,fxy)9.u=linspace(1,10,100);v=linspace(-pi,pi,100);[u,v]=meshgrid(u,v);x=3.*u.*sin(v);y=2.*u.*cos(v);z=4*u.^2;x=3*u.*sin(v);y=2*u.*cos(v);z=4*u.^2;surf(x,y,z);shading interp;light('position',[1,0,1]);10.t=0:pi/100:2*pi;y=sin(t);comet(t,y)第4章一、思考题5.(1)A=eye(3);(2)C=100+(200-100)*rand(5,6);(3)D=1+sqrt(0.2)*randn(1,500);(4)E=ones(size(A));(5)A=A+30*eye(size(A));(6)B=diag(diag(A))二、实验题1.P=pascal(5);H=hilb(5);Dp=det(P);Dh=det(H);Kp=cond(P);Kh=cond(H);P矩阵的性能更好,因为Kp较小2.A=[1,-1,2,3;0,9,3,3;7,-5,0,2;23,6,8,3]B=[3,pi/2,45;32,-76,sqrt(37);5,72,4.5e-4;exp(2),0,97]A1=diag(A);B1=diag(B);A2=triu(A);B2=triu(B);A3=tril(A);B3=tril(B);rA=rank(A);rB=rank(B);nA=norm(A);nb=norm(B);cA=cond(A);cB=cond(B);3.A=[31,1,0;-4,-1,0;4,-8,-2];[V,D]=eig(A);4.A=diag([-1,-1,-1,-1],-1)+diag([-1,-1,-1,-1],1)+diag([2,2,2,2,2]) b=[1,0,0,0,0]';x1=inv(A)*b;x2=A\b;[L,U]=lu(A);x3=U\(L\b);[Q,R]=qr(a);[Q,R]=qr(A);x4=R\(Q\b)R=chol(A);x5=R\(R'\b)5.B=sparse(A);x1=inv(B)*b;x2=B\b;[L,U]=lu(B);x3=U\(L\b);第5章一、思考题3.A=randn(10,5);mean(A)std(A)max(max(A))min(min(A))sum(A,2)sum(sum(A))sort(A,1)sort(A,2,'descend')二、实验题1.A=rand(1,30000);mean(A)std(A)max(A)min(A)size(find(A>0.5))/size(A)2.h=[466,715,950,1422,1635];w=[7.04,4.28,3.40,2.52,2.13];hh=[500,900,1500];ww=interp1(h,w,hh,'spline')3.x=linspace(1,10,50);y=log(x);f=polyfit(x,y,5);yy=polyval(f,x);plot(x,y,'r-',x,yy,'g.')4.N=64; % 采样点数T=5; % 采样时间终点t=linspace(0,T,N); % 给出N个采样时间ti(I=1:N) x=3*exp(-t); % 求各采样点样本值xdt=t(2)-t(1); % 采样周期f=1/dt; % 采样频率(Hz)X=fft(x); % 计算x的快速傅立叶变换XF=X(1:N/2+1); % F(k)=X(k)(k=1:N/2+1) f=f*(0:N/2)/N; % 使频率轴f从零开始plot(f,abs(F),'-*') % 绘制振幅-频率图xlabel('Frequency');ylabel('|F(k)|')5.(1)p1=[1 2 0 0 7];p2=[1 -2];p3=[1 0 0 5 1];p12=conv(p1,p2);p=p12+[zeros(1,size(p12,2)-size(p3,2)),p3];roots(p)(2)A=[-1,4,3;2,1,5;0,5,6];Px=polyval(p,A)Pxm=polyvalm(p,A)6.(1)z=fzero('3*x-sin(x)+1',0)(2)建立函数文件myfun.mfunction F=myfun(X)x=X(1);y=X(2);F(1)=x*x+y*y-9;F(2)=x+y-1;在命令窗口中输入以下命令:x=fsolve(@myfun,[3,0]',optimset('Display','off')) 第6章一、思考题2.fx=inline('1./(1+x.^2)');[I,n]=quad(fx,-100000,100000,1e-3);[I,n]=quadl(fx,-100000,100000,1e-3);x=-100000:0.01:100000;y=1./(1+x.*x);trapz(x,y);3.(1)fx=inline('-2*y+2*x*x+2*x');[t,y]=ode23(fx,[0,0.5],1)(2)fx=inline('y-exp(x)*cos(x)');[t,y]=ode23(fx,[0,3],1)二、实验题1.for x=1:3fx=[x,x^2,x^3;1,2*x,3*x;0,2,6*x];diff(fx)end2.(1)x=0:0.01:1;y=x.^10+10.^x+1./log10(x);dy=diff(y)/0.01;(2)x=0:0.01:1;y=log(1+x);dy=diff(y,2)/0.01;plot(x(1:99),dy)3.(1)fx=inline('x.^2.*sqrt(2*x.*x+3)');quad(fx,1,5)(2)fx=inline('x./sin(x).^2');quad(fx,pi/4,pi/3)(3)fx=inline('abs(cos(x+y))');dblquad(fx,0,pi,0,pi)(4)syms x y ;fx=x*y;int(int(fx,y^2,y+2),-1,2)x 的积分区间为【0,2】时fx=inline('x.*y');dblquad(fx,0,2,-1,2)4.x=0.3:0.2:1.5;y=[0.3895,0.6598,0.9147,1.1611,1.3971,1.6212,1.8325]; trapz(x,y)5.(1)yp=inline('-(1.2+sin(10*x))*y');[t,y]=ode23(yp,[0,5],1);(2)令''3,,21y x y x y x ='==,则可写出原方程的状态方程形式:123233221sin 31)1(2cos 5cos x tx x t t t x x x x x +--++='='='⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡+⎥⎥⎥⎦⎤⎢⎢⎢⎣⎡⎥⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎢⎣⎡+-+-=⎥⎥⎥⎥⎦⎤⎢⎢⎢⎢⎣⎡'''t x x x t t t x x x cos 00)1(2cos 51sin 311000103212321 建立函数文件ztfun.mfunction y=ztfun(t,x)b=[0;0;cos(t)];y=[0,1,0;0,0,1;-1/(3+sin(t)),-1,5*cos(2*t)/(t+1)^2]*x+b; 解微分方程组[t,y]=ode23(@ztfun,[0,5],[1;0;2]);6.建立函数文件ztfun.mfunction yy=ztfun(t,y)yy=[y(2)*y(3);-y(1)*y(3);-0.51*y(1)*y(2)];解微分方程组[t,y]=ode23(@ztfun,[0,5],[0;1;1])第7章一、思考题3.(1)数值积分fx=inline('exp(x).*(1+exp(x)).^2');quad(fx,0,log(2))符号积分f=sym('exp(x)*(1+exp(x))^2');v=int(f,0,log(2));eval(v)(2)略二、实验题1.A=sym('[1,2,3;x,y,z;3,2,1]')rank(A)inv(A)det(A)2.(1) y=sym('sqrt(x+sqrt(x+sqrt(x)))');y1=diff(y)y2=diff(y,'x',2)(2) syms x y;fxy=sin(x^2*y)*exp(-x^2-y);diff(diff(fxy,x),y)3.(1) syms xint(1/(1+x^4))(2) syms x tint((-2*x*x+1)/(2*x*x-3*x+1)^2,x,cos(t),exp(2*t)) 4.syms n xsymsum(1/(2*n+1)/(2*x+1)^(2*n+1),n,0,inf)symsum(1/(2*n+1)/(2*x+1)^(2*n+1),n,0,5)5.(1) syms xtaylor((exp(x)+exp(-x))/2,5,0)(2) syms a xtaylor(exp(-5*x)*sin(3*x+pi/3),5,a)6.(1)x=solve(sym('x^3+a*x+1=0'))(2) [x y]=solve(sym('sqrt(x^2+y^2)-100=0,3*x+5*y-8=0'))7. 方程转化为: π21'11't y y y y -=+=⎩⎨⎧符号解[y1,y11]=dsolve('Dy=y1,Dy1+y=1-t^2/pi','y(-2)=5,y1(-2)=5','t') 数值解编写函数文件ztfun.mfunction yy=ztfun(t,y)yy=[y(2);1-t^2/pi-y(1)];在命令窗口输入以下命令[t,y]=ode45(@ztfun,[-2,7],[-5;5]);t=linspace(-2,7,49)y2=y8.[x,y]=dsolve('Dx=3*x+4*y,Dy=-4*x+3*y','x(0)=0,y(0)=1')。
MATLAB第一章作业答案
M A T L A B第一章作业答案(共5页)--本页仅作为文档封面,使用时请直接删除即可----内页可以根据需求调整合适字体及大小--第一章M A T L A B概况与基本操作1.选择题:(1)最初的MATLAB核心程序是采用A语言编写的。
(2)即将于2011年9月发布的MATLAB新版本的编号为D。
2011Ra 2011Rb R2011a R2011b(3)在默认设置中,MATLAB中的注释语句显示的颜色是D。
A.黑色B.蓝色C.红色D.绿色(4)如果要以科学计数法显示15位有效数字,使用的命令是B。
long long e long g long d(5)在命令窗口新建变量a、b,如果只查看变量a的详细信息,使用的命令为B。
a a(6)如果要清除工作空间的所有变量,使用的命令为 C 。
all C.两者都可 D.两者都不可(7)在创建变量时,如果不想立即在命令窗口中输出结果,可以在命令后加上D。
A.冒号B.逗号C.空格D.分号(8)如果要重新执行以前输入的命令,可以使用B键。
A.下箭头↓B.上箭头↑C.左箭头←D.右箭头→(9)如果要查询函数inv的相关信息,并显示在命令窗口,应使用命令A。
D.三者均可(10)如果要启动Notebook文档,下列D操作是可行的。
A.在命令窗口输入notebook命令B.在命令窗口输入notebook filename命令C.在Word中启动M-book文档D.三者均可2.填空题:(1)MATLAB是MATrix和LABoratory两个单词前三个字母的组合,意为“矩阵实验室”,它的创始人是Cleve Moler和Jack Little。
(2)在MATLAB的默认设置中,关键字显示的字体为蓝色,命令、表达式、计算结果显示的字体为黑色,字符串显示的字体为紫色,注释显示的字体为绿色,错误信息显示的字体为红色。
(3)在命令窗口中,输出结果显示为各行之间添加空行的命令为format compact,各行之间不添加空行的命令为format compact。
MATLAB课后题答案整理
第一章1.利用MATLAB 的帮助功能分别查询inv 、plot 、max 、round 等函数的功能及用法。
Help+函数2.简述MATLAB 的主要功能。
①数值计算和符号计算功能。
②绘图功能。
③编程语言功能。
④扩展功能。
3.help 命令和lookfor 命令有何区别?Help 命令只搜索出那些与关键字完全匹配的结果,lookfor 命令对搜索范围内的M 文件进行关键字搜索,条件比较宽松。
Lookfor 命令只对M 文件的第一行进行关键字搜索。
若在lookfor 命令后加上-all 选项,则可对M 文件进行全文搜索。
第二章1(1))1034245.01(26-⨯+⨯=ww=sqrt(2)*(1+0.34245*10^(-6)) w = 1.4142(2)ac b e abc c b a x ++-+++=)tan(22ππ,其中a=3.5,b=5,c=-9.8。
a=3.5;b=5;c=-9.8;x=(2*pi*a+(b+c)/(pi+a*b*c)-exp(2))/(tan(b+c)+a) x =0.9829(3)])48333.0()41[(22απβππα---=y ,其中α=3.32,β=-7.9。
a=3.32;b=-7.9;y=2*pi*a^2*((1-pi/4)*b-(0.8333-pi/4)*a) y = -128.4271(4))1ln(2122t t e z t ++=,其中t=]65.05312[--i 。
t=[2,1-3i;5,-0.65];z=0.5*exp(2*t)*log(t+sqrt(1+t.*t)) z = 1.0e+004 * 0.0048 + 0.0002i 0.0048 - 0.0034i1.58992.0090 - 1.3580i2.已知]023352138[],7613870451[--=--=B A 求下列表达式的值。
(1)B A 6+和I B A +-2。
MATLAB程序设计知到章节答案智慧树2023年广西科技大学
MATLAB程序设计知到章节测试答案智慧树2023年最新广西科技大学第一章测试1.当在命令行窗口执行命令时,如果不想立即在命令行窗口中输出结果,可以在命令后加上()。
参考答案:分号(;)2.MATLAB命令行窗口中提示用户输入命令的符号是()。
参考答案:>> ;3.fix(264/100)+mod(264,10)*10的值是()。
参考答案:424.下列可作为MATLAB合法变量名的是()。
参考答案:xyz_2a。
5.在命令行窗口输入下列命令后,x的值是()。
>> clear>> x=i*j参考答案:-1;6.建立矩阵时,不同行的元素之间用()分隔。
参考答案:分号;7.输入字符串时,要用()将字符序列括起来。
参考答案:' ';8.最初的MATLAB核心程序是采用()语言编写的。
参考答案:FORTRAN;9.下列选项中能反应MATLAB特点的是()。
参考答案:编程效率高。
10.如果要重新执行以前输入的命令,可以使用()。
参考答案:上移光标键(↑)。
11.plot(x,y)是一条()命令。
参考答案:绘图;12.以下两个命令行的区别是()。
>> x=5,y=x+10>> x=5,y=x+10;参考答案:第一个命令行同时显示x和y的值,第二个命令行只显示x的值;13.下列选项中,不是MATLAB帮助命令的是()。
参考答案:search;14.下列数值数据表示中错误的是()。
参考答案:2e;15.下列语句中错误的是()。
参考答案:x=y=3;16.已知s='显示"hello"',则s的元素个数是()。
参考答案:9;17.建立矩阵时,同一行的元素之间用()分隔。
参考答案:空格;;逗号;18.在当前文件夹和搜索路径中都有fpp.m文件,那么在命令行窗口输入fpp时,下列说法错误的是()。
参考答案:先执行当前文件夹的fpp.m文件,再执行搜索路径中的fpp.m文件;;先执行搜索路径中的fpp.m文件,再执行当前文件夹的fpp.m文件;;执行搜索路径中的fpp.m文件;19.内存变量文件是二进制格式文件,扩展名为.mat。
Matlab 第一章习题解答
4.>> help opsOperators and special characters.Arithmetic operators.plus - Plus +uplus - Unary plus +minus - Minus -uminus - Unary minus -mtimes - Matrix multiply *times - Array multiply .*mpower - Matrix power ^power - Array power .^mldivide - Backslash or left matrix divide \mrdivide - Slash or right matrix divide /ldivide - Left array divide .\rdivide - Right array divide ./kron - Kronecker tensor product kronRelational operators.eq - Equal ==ne - Not equal ~=lt - Less than <gt - Greater than >le - Less than or equal <=ge - Greater than or equal >=Logical operators.relop - Short-circuit logical AND &&relop - Short-circuit logical OR ||and - Element-wise logical AND &or - Element-wise logical OR |not - Logical NOT ~xor - Logical EXCLUSIVE ORany - True if any element of vector is nonzeroall - True if all elements of vector are nonzeroSpecial characters.colon - Colon :paren - Parentheses and subscripting ( ) paren - Brackets [ ]paren - Braces and subscripting { }punct - Function handle creation @punct - Decimal point .punct - Structure field access .punct - Parent directory ..punct - Continuation ...punct - Separator ,punct - Semicolon ;punct - Comment %punct - Invoke operating system command !punct - Assignment =punct - Quote 'transpose - Transpose .'ctranspose - Complex conjugate transpose 'horzcat - Horizontal concatenation [,]vertcat - Vertical concatenation [;]subsasgn - Subscripted assignment ( ),{ },.subsref - Subscripted reference ( ),{ },.subsindex - Subscript indexBitwise operators.bitand - Bit-wise AND.bitcmp - Complement bits.bitor - Bit-wise OR.bitmax - Maximum floating point integer.bitxor - Bit-wise XOR.bitset - Set bit.bitget - Get bit.bitshift - Bit-wise shift.Set operators.union - Set union.unique - Set unique.intersect - Set intersection.setdiff - Set difference.setxor - Set exclusive-or.ismember - True for set member.See also arith, relop, slash, function_handle.arithArithmetic operators.+ Plus.X + Y adds matrices X and Y. X and Y must have the samedimensions unless one is a scalar (a 1-by-1 matrix).A scalar can be added to anything.- Minus.X - Y subtracts matrix X from Y. X and Y must have the samedimensions unless one is a scalar. A scalar can be subtractedfrom anything.* Matrix multiplication.X*Y is the matrix product of X and Y. Any scalar (a 1-by-1 matrix) may multiply anything. Otherwise, the number of columns of X must equal the number of rows of Y..* Array multiplicationX.*Y denotes element-by-element multiplication. X and Ymust have the same dimensions unless one is a scalar.A scalar can be multiplied into anything.^ Matrix power.Z = X^y is X to the y power if y is a scalar and X is square. If y is aninteger greater than one, the power is computed by repeatedmultiplication. For other values of y the calculationinvolves eigenvalues and eigenvectors.Z = x^Y is x to the Y power, if Y is a square matrix and x is a scalar,computed using eigenvalues and eigenvectors.Z = X^Y, where both X and Y are matrices, is an error..^ Array power.Z = X.^Y denotes element-by-element powers. X and Ymust have the same dimensions unless one is a scalar.A scalar can operate into anything.RelopRelational operators.< > Relational operators.The six relational operators are <, <=, >, >=, ==, and ~=.A <B does element by element comparisons between A and Band returns a matrix of the same size with elements set to logical1 (TRUE) where the relation is true and elements set to logical 0(FALSE) where it is not. A and B must have the same dimensions(or one can be a scalar).& Element-wise Logical AND.A &B is a matrix whose elements are logical 1 (TRUE) where both A and B have non-zero elements, and logical 0 (FALSE) where either has a zero element. A and B must have the same dimensions (or one can be a scalar).&& Short-Circuit Logical AND.A &&B is a scalar value that is the logical AND of scalar A and B.This is a "short-circuit" operation in that MATLAB evaluates B onlyif the result is not fully determined by A. For example, if A equals0, then the entire expression evaluates to logical 0 (FALSE), regard-less of the value of B. Under these circumstances, there is no needto evaluate B because the result is already known.| Element-wise Logical OR.A |B is a matrix whose elements are logical 1 (TRUE) where eitherA orB has a non-zero element, and logical 0 (FALSE) where both have zero elements. A and B must have the same dimensions (or one canbe a scalar).|| Short-Circuit Logical OR.A ||B is a scalar value that is the logical OR of scalar A and B.This is a "short-circuit" operation in that MATLAB evaluates B onlyif the result is not fully determined by A. For example, if A equals1, then the entire expression evaluates to logical 1 (TRUE), regard-less of the value of B. Under these circumstances, there is no needto evaluate B because the result is already known.~ Logical complement (NOT).~A is a matrix whose elements are logical 1 (TRUE) where A has zero elements, and logical 0 (FALSE) where A has non-zero elements.xor Exclusive OR.xor(A,B) is logical 1 (TRUE) where either A or B, but not both, isnon-zero. See XOR.Relational operators.< > Relational operators.The six relational operators are <, <=, >, >=, ==, and ~=.A <B does element by element comparisons between A and Band returns a matrix of the same size with elements set to logical1 (TRUE) where the relation is true and elements set to logical 0(FALSE) where it is not. A and B must have the same dimensions(or one can be a scalar).& Element-wise Logical AND.A &B is a matrix whose elements are logical 1 (TRUE) where both A and B have non-zero elements, and logical 0 (FALSE) where either has a zero element. A and B must have the same dimensions (or one can be a scalar).&& Short-Circuit Logical AND.A &&B is a scalar value that is the logical AND of scalar A and B.This is a "short-circuit" operation in that MATLAB evaluates B onlyif the result is not fully determined by A. For example, if A equals0, then the entire expression evaluates to logical 0 (FALSE), regard-less of the value of B. Under these circumstances, there is no needto evaluate B because the result is already known.| Element-wise Logical OR.A |B is a matrix whose elements are logical 1 (TRUE) where eitherA orB has a non-zero element, and logical 0 (FALSE) where both have zero elements. A and B must have the same dimensions (or one canbe a scalar).|| Short-Circuit Logical OR.A ||B is a scalar value that is the logical OR of scalar A and B.This is a "short-circuit" operation in that MATLAB evaluates B onlyif the result is not fully determined by A. For example, if A equals1, then the entire expression evaluates to logical 1 (TRUE), regard-less of the value of B. Under these circumstances, there is no needto evaluate B because the result is already known.~ Logical complement (NOT).~A is a matrix whose elements are logical 1 (TRUE) where A has zeroelements, and logical 0 (FALSE) where A has non-zero elements.xor Exclusive OR.xor(A,B) is logical 1 (TRUE) where either A or B, but not both, isnon-zero. See XOR.SlashMatrix division.\ Backslash or left division.A\B is the matrix division of A into B, which is roughly thesame as INV(A)*B , except it is computed in a different way.If A is an N-by-N matrix and B is a column vector with Ncomponents, or a matrix with several such columns, thenX = A\B is the solution to the equation A*X = B computed byGaussian elimination. A warning message is printed if A isbadly scaled or nearly singular. A\EYE(SIZE(A)) produces theinverse of A.If A is an M-by-N matrix with M < or > N and B is a columnvector with M components, or a matrix with several such columns,then X = A\B is the solution in the least squares sense to theunder- or overdetermined system of equations A*X = B. Theeffective rank, K, of A is determined from the QR decompositionwith pivoting. A solution X is computed which has at most Knonzero components per column. If K < N this will usually notbe the same solution as PINV(A)*B. A\EYE(SIZE(A)) produces ageneralized inverse of A./ Slash or right division.B/A is the matrix division of A into B, which is roughly thesame as B*INV(A) , except it is computed in a different way.More precisely, B/A = (A'\B')'. See \../ Array right division.B./A denotes element-by-element division. A and Bmust have the same dimensions unless one is a scalar.A scalar can be divided with anything..\ Array left division.A.\B. denotes element-by-element division. A and Bmust have the same dimensions unless one is a scalar.A scalar can be divided with anything.function_FUNHANDLE = @FUNCTION_NAME returns a handle to the named function, FUNCTION_NAME. A function handle is a MATLAB value that provides a means of calling a function indirectly. You can pass functionhandles in calls to other functions (which are often called functionfunctions). You can also store function handles in data structures forlater use (for example, as Handle Graphics callbacks). A functionhandle is one of the standard MATLAB data types. Its class is'function_handle'.FUNHANDLE = @(ARGLIST)EXPRESSION constructs an anonymous function and returns a handle to that function. The body of the function, to theright of the parentheses, is a single MATLAB expression. ARGLIST is acomma-separated list of input arguments. Execute the function bycalling it by means of the returned function handle, FUNHANDLE. Formore information on anonymous functions, see "Types of Functions" inthe MATLAB Programming documentation.To call the function referred to by a function handle value, use ordinaryparenthesis notation. That is, specify the function handle variablefollowed by a comma-separated list of input arguments enclosed inparentheses. For example, HANDLE(ARG1, ARG2, ...). To call afunction_handle with no arguments, use empty parenthesis, e.g.,HANDLE().Example 2, below, shows how to make a call using a function handlethat has been passed as an argument.When you evaluate a function handle to a subfunction or privatefunction, that subfunction or private function is always executed whenthe function handle is called. When you evaluate a function handle toa built-in or ordinary function, an appropriate method may be selectedinstead of the built-in or ordinary function.With one exception, function handles can be manipulated and operated on inthe same manner as other MATLAB values, including assignment to variablesand inclusion in cells and structs. The exception is that you cannotconstruct a function_handle array. The reason is that the parenthesisnotation for values of this class is used to call a function, not toindex an array. To achieve the effect of an array of function handles,use cells, e.g., write "A = {@sin, @cos}" rather than "A = [@sin, @cos]".Of course, you need to index A with braces: "A{i}".Function handles enable you to:Pass a function reference to another function.Reduce the number of files that define your functions.Improve performance in repeated operations.Ensure reliability when evaluating functions.Note on Backward Compatibility:In R12 and R13, you could form arrays of function handles, and parenthesisnotation meant indexing into such an array. To call the function referredto by a function_handle value, you needed to use the FEVAL command. In R14,it is not necessary to use FEVAL (and this command will likely be deprecatedin a future release). Now, a function_handle variable, when followed by (...)'s,calls the associated function, and passes the arguments in parenthesis to it.This is faster than calling the function_handle using FEVAL.This change is not backward compatible, and R14 has a transitionstrategy that will leave almost all R12 & R13 programs working:o Constructing a non-scalar array of functions handles is only awarning, not an error.o Parenthesis notation on a non-scalar function handle meanssubscripting, just as in R13, while the same notation on scalarfunction handles means function call, as described above.Thus, incompatibility can arise only if you construct a scalar array offunction handles and actually index it, necessarily with an index of 1.Example 1 - Construct a handle, f, to the HUMPS function, and pass thishandle to FMINBND. (MATLAB maps a specific implementation of the HUMPS function to the handle f at the time the handle is created, and not atthe time f is called.)f = @humps;x = fminbnd(f,1,2);Example 2 - Call a function by means of the function handle, h, thatwas passed as an argument.function trigPlot(h, val)if isa(h, 'function_handle') % Verify that h is a function handle.A = h(val); % Call the function mapped to handle h.plot(A) % Plot the resulting data.endCall the function, passing the handle generated by @cos:trigPlot(@cos, -pi:0.01:pi)See also func2str, str2func, functions.Reference page in Help browserdoc function_handlehandleReference page in Help browserdoc function_handleFUNHANDLE = @FUNCTION_NAME returns a handle to the named function,FUNCTION_NAME. A function handle is a MATLAB value that provides ameans of calling a function indirectly. You can pass functionhandles in calls to other functions (which are often called functionfunctions). You can also store function handles in data structures forlater use (for example, as Handle Graphics callbacks). A functionhandle is one of the standard MATLAB data types. Its class is'function_handle'.FUNHANDLE = @(ARGLIST)EXPRESSION constructs an anonymous function and returns a handle to that function. The body of the function, to theright of the parentheses, is a single MATLAB expression. ARGLIST is acomma-separated list of input arguments. Execute the function bycalling it by means of the returned function handle, FUNHANDLE. Formore information on anonymous functions, see "Types of Functions" inthe MATLAB Programming documentation.To call the function referred to by a function handle value, use ordinaryparenthesis notation. That is, specify the function handle variablefollowed by a comma-separated list of input arguments enclosed inparentheses. For example, HANDLE(ARG1, ARG2, ...). To call afunction_handle with no arguments, use empty parenthesis, e.g.,HANDLE().Example 2, below, shows how to make a call using a function handlethat has been passed as an argument.When you evaluate a function handle to a subfunction or privatefunction, that subfunction or private function is always executed whenthe function handle is called. When you evaluate a function handle toa built-in or ordinary function, an appropriate method may be selectedinstead of the built-in or ordinary function.With one exception, function handles can be manipulated and operated on inthe same manner as other MATLAB values, including assignment to variablesand inclusion in cells and structs. The exception is that you cannotconstruct a function_handle array. The reason is that the parenthesisnotation for values of this class is used to call a function, not toindex an array. To achieve the effect of an array of function handles,use cells, e.g., write "A = {@sin, @cos}" rather than "A = [@sin, @cos]".Of course, you need to index A with braces: "A{i}".Function handles enable you to:Pass a function reference to another function.Reduce the number of files that define your functions.Improve performance in repeated operations.Ensure reliability when evaluating functions.Note on Backward Compatibility:In R12 and R13, you could form arrays of function handles, and parenthesisnotation meant indexing into such an array. To call the function referredto by a function_handle value, you needed to use the FEVAL command. In R14, it is not necessary to use FEVAL (and this command will likely be deprecatedin a future release). Now, a function_handle variable, when followed by (...)'s,calls the associated function, and passes the arguments in parenthesis to it.This is faster than calling the function_handle using FEVAL.This change is not backward compatible, and R14 has a transitionstrategy that will leave almost all R12 & R13 programs working:o Constructing a non-scalar array of functions handles is only awarning, not an error.o Parenthesis notation on a non-scalar function handle meanssubscripting, just as in R13, while the same notation on scalarfunction handles means function call, as described above.Thus, incompatibility can arise only if you construct a scalar array offunction handles and actually index it, necessarily with an index of 1.Example 1 - Construct a handle, f, to the HUMPS function, and pass thishandle to FMINBND. (MATLAB maps a specific implementation of the HUMPS function to the handle f at the time the handle is created, and not atthe time f is called.)f = @humps;x = fminbnd(f,1,2);Example 2 - Call a function by means of the function handle, h, thatwas passed as an argument.function trigPlot(h, val)if isa(h, 'function_handle') % Verify that h is a function handle.A = h(val); % Call the function mapped to handle h.plot(A) % Plot the resulting data.endCall the function, passing the handle generated by @cos:trigPlot(@cos, -pi:0.01:pi)See also func2str, str2func, functions.Reference page in Help browserdoc function_handle>> a=exp(1)a =2.7183>>>> A=piA =3.1416eπe=2.718282>> 2.718282^pians =23.1407>> 2.718282.^pians =23.1407πe>> pi^2.718282ans =22.4592或者 :>> pi.^2.718282ans =22.4592>>c=2.718282.^pi ; d=pi^2.718282 >>c<dans=>>c>dans=1>> rand(3,3)ans =0.8147 0.9134 0.2785 0.9058 0.6324 0.5469 0.1270 0.0975 0.9575>> A=rand(3,3)A =0.9649 0.9572 0.1419 0.1576 0.4854 0.4218 0.9706 0.8003 0.9157 >> A=rand(3,3);>> B=inv(A)B =-0.4740 3.7530 -3.3939 -1.3356 0.8875 0.3148 2.0968 -4.4272 3.9447 >> C=B*AC =1.0000 0.0000 0 -0.0000 1.0000 0.0000 0 -0.0000 1.0000 >> A=rand(3,3)A =0.3922 0.7060 0.0462 0.6555 0.0318 0.0971 0.1712 0.2769 0.8235 >> B=inv(A)B =0.0019 1.5730 -0.18561.4471 -0.8716 0.0217-0.4871 -0.0339 1.2457>> C=B*AC =1.0000 0 0.00000.0000 1.0000 00 -0.0000 1.0000>> D=B.*AD =0.0007 1.1106 -0.00860.9486 -0.0277 0.0021-0.0834 -0.0094 1.0258>> E=sqrt(C)>> F=abs(E)Short 3位整数4位小数的定点数>> format short>> A=rand(3,3)A =0.6948 0.0344 0.76550.3171 0.4387 0.79520.9502 0.3816 0.1869long 2位整数14位小数的定点数>> format long>> A=rand(3,3)A =0.489764395788231 0.709364830858073 0.679702676853675 0.445586********* 0.754686681982361 0.655098003973841 0.646313********* 0.276025076998578 0.162611735194631 short e 5个数字的浮点数,其中1位整数4位小数>> format short e>> A=rand(3,3)A =1.1900e-001 3.4039e-001 7.5127e-0014.9836e-0015.8527e-001 2.5510e-0019.5974e-001 2.2381e-001 5.0596e-001long e 16个数字的浮点数,其中1位整数15位小数short g 显示5个数字,自动选择定点数和浮点数>> format short g>> A=rand(3,3)A =0.69908 0.54722 0.257510.8909 0.13862 0.840720.95929 0.14929 0.25428long g显示15个数字,自动选择定点数和浮点数>> format long g>> A=rand(3,3)A =0.814284826068816 0.349983765984809 0.6160446761466390.243524968724989 0.196595250431208 0.4732888489027290.929263623187228 0.251083857976031 0.351659507062997 7.>> x=1:1:100;>> s=solve('x^2+sin(x)+ln(x)')s =-1.3901004146053480595845249400739-.98288867543926874105777377916614*i >>8.>> A=1;>> omega=4*pi;>> t=0:0.01:1;>> phi=0.1*pi;>> x=A*sin(omega*t+phi);>> plot(t,x)>> A=2;>> omega=[2*pi; 4*pi]; >> t=0:0.01:1;>> phi=0.1*pi;>> x=A*sin(omega*t+phi); >> plot(t,x)>> A=2;>> omega=[2*pi; 4*pi]; >> t=0:0.01:1;>> c=omega*t;>> phi=0.1*pi;>> x=A*sin(c+phi);>> plot(t,x(1,:),t,x(2,:))>> A=2;>> omega=[2*pi; 4*pi]; >> t=0:0.01:1;>> c=omega*t;>> phi=0.1*pi;>> x=A*sin(c+phi);>> plot(t,x(1,:),'r',t,x(2,:),'b')8、t=[0:0.1:2*pi];A1=5;A2=3;w1=2;w2=4;x1=A1*sin(w1*t+pi/3);x2=A2*sin(w2*t+pi/4);plot(t,x1,'-r',t,x2,'-b');01234567-5-4-3-2-1123459.1)>> 3+5i/(1+i)ans =5.5000 + 2.5000i2)>> sin(4+5*i)ans =-56.1623 -48.5025i3)>> 2.718282^(3+2*i)ans =-8.3585 +18.2637i4)>> 10^(3+2*i)ans =-1.0701e+002 -9.9426e+002i5)shx=(e x-e-x)/2chx=(e x+e-x)/2th= shx / chx>> (2.718282^(3+2*i)-2.718282^(-(3+2*i)))/2 ans =-4.1689 + 9.1545i10.>> A=[]A =[]>>>> B=zeros(3,3)B =0 0 00 0 00 0 0>> C=cell(3)C =[] [] [][] [] [][] [] []>>11.>> tril(ones(3,3),0) ans =1 0 01 1 01 1 1>> triu(ones(3,3),0) ans =1 1 10 1 10 0 1>> magic(3)ans =8 1 63 5 74 9 2>> tril(magic(3)) ans =8 0 03 5 04 9 2>> triu(magic(3)) ans =8 1 60 5 70 0 2or>> A=magic(3)A =8 1 63 5 74 9 2>> B=tril(A)B =8 0 03 5 04 9 2>> C=triu(A)C =8 1 60 5 70 0 2or>> A=magic(3)A =8 1 63 5 74 9 2>> B=tril(magic(3))B =8 0 03 5 04 9 2>> C=triu(magic(3))C =8 1 60 5 70 0 2 Exercise:1.>> A=magic(3)A =8 1 63 5 74 9 2 >> a=tril(A)a =8 0 03 5 04 9 2 >> b=triu(A)b =8 1 60 5 70 0 2b =8 1 60 5 70 0 2 2.>> c=sum(A)c =15 15 15 >> d=sum(A')d =15 15 15 >> sum(diag(A)) ans =15>> sum(diag(A')) ans =153.>> A=magic(3)A =8 1 63 5 74 9 2>> f=diag(A)f =852>> g=(A')g =8 3 4 1 5 9 6 7 24.>> h=fliplr(A)h =6 1 87 5 3 2 9 4>> i=flipud(A)i =4 9 2 35 7 8 1 6>> j=rot90(A)j =6 7 2 1 5 9 8 3 4 5.>> k=sort(A,1)k =3 1 24 5 68 9 7>> l=sort(A,2)l =1 6 83 5 72 4 96. ?a,b 对矩阵c,d,e dui 元素f,g 对矩阵h,i,j 对矩阵k 对矩阵12.>> A=[2 8 10; 11 3 7; 6 9 4]; >> B=[12 9 4; 5 2 21; 8 4 6]; >> C=A*BC =144 74 236203 133 149149 88 237>> A\Cans =12.0000 9.0000 4.0000 5.0000 2.0000 21.0000 8.0000 4.0000 6.0000>> C/Bans =2.0000 8.0000 10.0000 11.00003.0000 7.0000 6.0000 9.00004.0000>>>> D=A.*BD =24 72 4055 6 14748 36 2413.>> A=diag(1:4)A =1 0 0 00 2 0 00 0 3 00 0 0 4>> D=diag(1:5)D =1 0 0 0 0 02 0 0 0 0 03 0 0 0 0 04 0 0 0 0 0 5>> A=diag(1:3)A =1 0 00 2 00 0 3>> V=[1 2 3]V =1 2 3>> diag(V,1)ans =0 1 0 00 0 2 00 0 0 30 0 0 0>> diag(V,-1)ans =0 0 0 01 0 0 00 2 0 00 0 3 0>> diag(V,2)ans =0 0 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 13.>> A=diag(1:4)A =1 0 0 00 2 0 00 0 3 00 0 0 4>> D=diag(1:5)D =1 0 0 0 0 02 0 0 0 0 03 0 0 0 0 04 0 0 0 0 0 5>> A=diag(1:3)A =1 0 00 2 00 0 3>> V=[1 2 3]V =1 2 3>> diag(V,1)ans =0 1 0 00 0 2 00 0 0 30 0 0 0>> diag(V,-1)ans =0 0 0 01 0 0 00 2 0 00 0 3 0>> diag(V,2)ans =0 0 1 0 00 0 0 2 00 0 0 0 30 0 0 0 00 0 0 0 015.>> x1=[-1 0 1 -1];>> y1=[0 1 0 0];>> x2=[-1 0 1 -1];>> y2=[0 i 0 0];>> plot(x1,y1,'r:+',x2,imag(y2),'g:o')plot(x1,y1,'r:+','LineWidth',2, x2,imag(y2),'g:o','LineWidth',5)>> x1=[-1 0 1 -1];>> y1=[0 1 0 0];>> plot(x1,y1,'r:+','LineWidth',3)>> x2=[-1 0 1 -1];>> y2=[0 i 0 0];>> plot(x2,imag(y2),'g:O','LineWidth',5)>> x1=[-1 0 1 -1];>> y1=[0 1 0 0];>> x2=[-1 0 1 -1];>> y2=[0 i 0 0];plot(x1,y1,'r:+', x2,imag(y2),'g:O')1616.>> t=-10*pi:pi/250:10*pi;>> comet3(8*cos(t),4*sqrt(2)*sin(t),-4*sqrt(2)*sin(t))17>> fplot('cos(tan(pi*x))',[0 2*pi])fplot('cos(tan(pi*x))',[0 2*pi],'+-')>> fplot('cos(tan(pi*x))',[0 2*pi],'o')18>> ezplot('exp(y)+cos(x)/x+y=0',[-3,3])ezplot('exp(y)+cos(x)/x+y=0',[-4,4])>> ezplot('exp(y)+cos(x)/x+y=0')19 >> s=[0:8];t=[0:5*pi];>> [s,t]=meshgrid(s,t);>> x=exp(-s).*cos(t);>> y=exp(-s).*sin(t);>> z=t;>> surf(x,y,z)>> s=[0:1:8];t=[0:pi/60:5*pi];>> [s,t]=meshgrid(s,t);>> x=exp(-s).*cos(t);>> y=exp(-s).*sin(t);>> z=t;>> surf(x,y,z)20subplot(1,2,1);[X0,Y0,Z0]=sphere(20);X=2*X0;Y=3*Y0;Z=4*Z0+1;surf(X,Y,Z);axis equalsubplot(1,2,2)t=-1:0.1:1;[X,Y,Z]=cylinder(1+t.^2,20);%形成旋转曲面 surf(X,Y,Z);-2024-2220>> subplot(1,1,1);>> ellipsoid(0,0,1,2,3,4)>> [x,y,z]=ellipsoid(0,0,1,2,3,4); >> surf(x,y,z);>> [x,y,z]=ellipsoid(0,0,1,2,3,4); >> surf(x,y,z);>> colormap copper>> [x,y,z]=ellipsoid(0,0,1,2,3,4); >> surf(x,y,z);>> colormap copper>> t=[-1:0.1:1];>> [X,Y,Z]=cylinder(1+t.^2);>> [X,Y,Z]=ellipsoid(0,0,1,2,3,4); >> surf(X,Y,Z)21x=-5:0.1:5;y=0:0.1:10;[X,Y]=meshgrid(x,y); z=X.^2.*Y + sqrt(Y)./X; mesh(X,Y,z);>> ezmesh('x^2*y+sqrt(y)/x',[-5,5,0,10])>> ezsurf('x^2*y+sqrt(y)/x',[-5,5,0,10])。
MATLAB习题参考答案
第1章 MATLAB简介1、MA TLAB的主要特点有:①语言简洁,编程效率高。
②人机界面友善,交互性好。
③绘图功能强大,便于数据可视化。
④学科众多、领域广泛的MATLAB工具箱。
⑤源程序的开放性。
MATLAB的典型应用领域有:①自动控制②汽车③电子④仪器仪表⑤生物医学⑥信号处理⑦通信等。
2、填空题⑴命令窗口、命令历史窗口、当前目录窗口⑵查阅、保存、编辑⑶清除图形窗、清除命令窗口中显示内容、清除MATLAB工作空间中保存的变量。
3、如果想查看某一变量具体内容或者对其修改操作,可以在工作空间中双击该变量名称,可以打开数组编辑器,在数组编辑器中可以查看变量的具体内容,也可以对其修改。
如果想删除MATLAB内存中的变量,可以在工作空间中选中该变量,然后利用工作空间窗口的菜单命令或工具条中的快捷图标进行删除。
4、1+2+3+4+5+... (+ 后面可以直接跟...,也可以在+和...中加一个空格。
)6+7+8+91+2+3+4+5 ... (5后面必须跟一个空格,不能直接跟...,否则报错,这在预置一个+6+7+8+9 大数组时很重要。
)第2章矩阵与数值数组1、填空题:⑴非数、无穷大、机器零阈值,浮点数相对精度,eps= 2.2204e-016。
⑵全下标、单下标。
2、阅读程序题:(本题主要考察数组的寻访、赋值和简单运算,提示:带;的语句不显示结果)⑴ans =2 3 7Sa =102030A =1 20 5 30 910 4 6 8 10⑵ A =1 3 5 7 9 11 13 152 4 6 8 10 12 14 16ans =1 5 9 132 6 10 143 7 11 154 8 12 16A =0 0 5 7 0 0 13 152 4 0 0 10 12 0 0⑶ ans =-1 -46 4ans =3 05 -2ans =3 69 12ans =3 69 123、A=magic(4);L=A<10L =0 1 1 01 0 0 11 1 1 01 0 0 14、省略。
matlab第一章习题集合及答案
MATLAB 多多练 赋值语句 例1-3:在命令窗口键入:1+2*3+6/2键入a=2;b=3;c=4;totle=a*b+c 例:当π+=1x 时,计算表达式 的值,并将结果赋给变量y ,然后显示出结果。
在MATLAB 命令窗口分别输入命令:x=sqrt(1+pi); y=(exp(x)+log(abs(sin(x)^2-sin(x*x))))/(x-5*i) %计算表达式的值变量的管理 例1-4:who;%显示目前工作空间的变量名whos %显示变量名,变量大小,数据类型等save myfilename %MATLAB 将产生一个名为myfilename.mat 的文件,文件中保存了当前工作空间的所有变量save mydata a b %MATLAB 将产生一个名为mydata.mat 的文件,文件中保存了当前工作空间的变量 a 和 b.clear %把当前工作空间清空22e ln sin sin 5x x x x i+--who %结果没有任何变量显示load myfilename %把文件myfilename.mat中的变量装入当前工作空间load mydata % 把mydata.mat中的内容装入MATLAB工作空间:数据的输出格式例1-5:x=215/6;format long; %16位十进制xformat short e; %五位十进制数加指数xformat long e; %16位十进制数加指数xformat hex %16位十六进制数xformat bank %两位小数xformat + %正、负或零xformat rat %分数近似xformat short %4位小数,默认格式xformat compact %紧凑格式xformat loose %默认格式x矩阵的生成例1-6:直接输入法:[1 2 3][1;2;3]x=[-1.3 sqrt(3) (1+2+3)/5*4]在命令窗口键入:A=[1 0 3 -1;2 1 0 2]键入:B=[4 1 0;-1 1 3;2 0 1;1 3 4]C=3+4i %输入复数D=[1+2i 3+4i;5+6i 7+8i]%输入复数[1 3;5 7]+[2 4;6 8]*i%输入复数*号不可少利用M文件建立矩阵例1-7(1)启动MATLAB的M-file编辑器,并输入待建矩阵mydata=[1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9;2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9;3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9];(2)把输入的内容保存(设文件名为matfund.m)。
MATLAB语言基础与应用(第二版)第1章 习题答案
第1章习题与答案1.1 MA TLAB桌面主要有哪些窗口构成?这些窗口主要功能是什么?请参考1.3节1.2计算下列表达式(1) 3+6 (2) sin(1+i)(3) (1+2i)×(2-i) (4) 2×4+3解答:(1) >> 3+6ans = 9(2) >> sin(1+i)ans = 1.2985 + 0.6350i(3) >> (1+2*i)*(2-i)ans = 4.0000 + 3.0000i(4) >> 2*4+3ans = 111.3借助“help”函数了解“meshgrid”函数的意义。
解答:>> help meshgridmeshgrid Cartesian grid in 2-D/3-D space[X,Y] = meshgrid(xgv,ygv) replicates the grid vectors xgv and ygv toproduce the coordinates of a rectangular grid (X, Y). The grid vectorxgv is replicated numel(ygv) times to form the columns of X. The gridvector ygv is replicated numel(xgv) times to form the rows of Y.[X,Y,Z] = meshgrid(xgv,ygv,zgv) replicates the grid vectors xgv, ygv, zgvto produce the coordinates of a 3D rectangular grid (X, Y, Z). The gridvectors xgv,ygv,zgv form the columns of X, rows of Y, and pages of Zrespectively. (X,Y,Z) are of size numel(ygv)-by-numel(xgv)-by(numel(zgv).[X,Y] = meshgrid(gv) is equivalent to [X,Y] = meshgrid(gv,gv).[X,Y,Z] = meshgrid(gv) is equivalent to [X,Y,Z] = meshgrid(gv,gv,gv).The coordinate arrays are typically used for the evaluation of functionsof two or three variables and for surface and volumetric plots.meshgrid and NDGRID are similar, though meshgrid is restricted to 2-Dand 3-D while NDGRID supports 1-D to N-D. In 2-D and 3-D the coordinates output by each function are the same, the difference is the shape of theoutput arrays. For grid vectors xgv, ygv and zgv of length M, N and Prespectively, NDGRID(xgv, ygv) will output arrays of size M-by-N whilemeshgrid(xgv, ygv) outputs arrays of size N-by-M. Similarly,NDGRID(xgv, ygv, zgv) will output arrays of size M-by-N-by-P whilemeshgrid(xgv, ygv, zgv) outputs arrays of size N-by-M-by-P.Example: Evaluate the function x*exp(-x^2-y^2)over the range -2 < x < 2, -4 < y < 4,[X,Y] = meshgrid(-2:.2:2, -4:.4:4);Z = X .* exp(-X.^2 - Y.^2);surf(X,Y,Z)Class support for inputs xgv,ygv,zgv:float: double, singleinteger: uint8, int8, uint16, int16, uint32, int32, uint64, int64 See also surf, slice, ndgrid.Overloaded methods:codistributed/meshgridgpuArray/meshgridReference page in Help browserdoc meshgrid1.4通过帮助浏览器窗口了解函数sin和cos。
matlab课后练习习题及答案详解
matlab课后习题及答案详解第1章MATLAB概论与其余计算机语言对比较,MATLAB语言突出的特色是什么?MATLAB拥有功能强盛、使用方便、输入简捷、库函数丰富、开放性强等特色。
MATLAB系统由那些部分构成?MATLAB系统主要由开发环境、MATLAB数学函数库、MATLAB语言、图形功能和应用程序接口五个部分组成。
安装MATLAB时,在选择组件窗口中哪些部分一定勾选,没有勾选的部分此后怎样补安装?在安装MATLAB时,安装内容由选择组件窗口中个复选框能否被勾选来决定,能够依据自己的需要选择安装内容,但基本平台(即MATLAB选项)一定安装。
第一次安装没有选择的内容在补安装时只要依据安装的过程进行,不过在选择组件时只勾选要补装的组件或工具箱即可。
MATLAB操作桌面有几个窗口?怎样使某个窗口离开桌面成为独立窗口?又怎样将离开出去的窗口从头搁置到桌面上?在MATLAB操作桌面上有五个窗口,在每个窗口的右上角有两个小按钮,一个是封闭窗口的Close按钮,一个是能够使窗口成为独立窗口的Undock 按钮,点击Undock按钮就能够使该窗口离开桌面成为独立窗口,在独立窗口的view菜单中选择Dock,,菜单项就能够将独立的窗口从头防备的桌面上。
怎样启动M文件编写/调试器?在操作桌面上选择“成立新文件”或“翻开文件”操作时,M文件编写/调试器将被启动。
在命令窗口中键入edit命令时也能够启动M文件编写/调试器。
储存在工作空间中的数组能编写吗?怎样操作?储存在工作空间的数组能够经过数组编写器进行编写:在工作空间阅读器中双击要编写的数组名翻开数组编写器,再选中要改正的数据单元,输入改正内容即可。
命令历史窗口除了能够察看前方键入的命令外,还有什么用途?命令历史窗口除了用于查问从前键入的命令外,还能够直接履行命令历史窗口中选定的内容、将选定的内容拷贝到剪贴板中、将选定内容直接拷贝到M文件中。
怎样设置目前目录和搜寻路径,在目前目录上的文件和在搜寻路径上的文件有什么差别?目前目录能够在目前目录阅读器窗口左上方的输入栏中设置,搜寻路径能够经过选择操作桌面的file菜单中的SetPath菜单项来达成。
MATLAB习题参考答案(胡良剑
第一章 MATLAB 入门4、求近似解解:>> x=-2:0.05:2;y=x.^4-2.^x两个近似解:y1=f(-0.85)= -0.0328; y2=f(1.250)= 0.0630第二章 MATLAB 编程与作图1、 设x 是数组,求均值和方差解:函数文件如下:function [xx,s]=func1(x)n=length(x);xx=sum(x)/n;s=sqrt((sum(x.^2)-n*xx^2)/(n-1));命令窗口:>> x=[1 2 3 4 5];[xx,s]=func1(x)2、求满足的最小m 值 100)1ln(0>+∑=m n n s=0;n=0;while(s<=100)s=s+log(1+n);n=n+1;endn,s3、用循环语句形成Fibonacci 数列,....4,3,,12121=+===−−k F F F F F k k k 。
并验证极限2511+→−k k F F (提示:计算至两边误差小于精度1e-8为止) 解: 求Fibonacci 数列的函数文件:function f=fun(n)if n<=2f=1;elsef=fun(n-1)+fun(n-2);end验证极限的函数文件:function [k,a]=funTest(e)a=abs(1-(1+sqrt(5))/2);k=2;while(a>e)k=k+1;a=abs(fun(k)/fun(k-1)-(1+sqrt(5))/2);end命令行:>> [k,a]=funTest(10^-8)k =21a =9.7719e-009或者M 文件如下:clear; F(1)=1;F(2)=1;k=2;x=0;e=1e-8; a=(1+sqrt(5))/2;while abs(x-a)>ek=k+1; F(k)=F(k-1)+F(k-2); x=F(k)/F(k-1);enda,x,k4、分别用for 和while 循环结构编写程序,求出∑==610123i i K ,并考虑一种避免循环语句的程序设计,比较各种算法的运行时间。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
第一章M A T L A B概况与基本操作1.选择题:(1)最初的MATLAB核心程序是采用A语言编写的。
(2)即将于2011年9月发布的MATLAB新版本的编号为D。
2011Ra 2011Rb R2011a R2011b(3)在默认设置中,MATLAB中的注释语句显示的颜色是D。
A.黑色B.蓝色C.红色D.绿色(4)如果要以科学计数法显示15位有效数字,使用的命令是B。
long long e long g long d(5)在命令窗口新建变量a、b,如果只查看变量a的详细信息,使用的命令为B。
a a(6)如果要清除工作空间的所有变量,使用的命令为 C 。
all C.两者都可 D.两者都不可(7)在创建变量时,如果不想立即在命令窗口中输出结果,可以在命令后加上D。
A.冒号B.逗号C.空格D.分号(8)如果要重新执行以前输入的命令,可以使用B键。
A.下箭头↓B.上箭头↑C.左箭头←D.右箭头→(9)如果要查询函数inv的相关信息,并显示在命令窗口,应使用命令A。
D.三者均可(10)如果要启动Notebook文档,下列D操作是可行的。
A.在命令窗口输入notebook命令B.在命令窗口输入notebook filename命令C.在Word中启动M-book文档D.三者均可2.填空题:(1)MATLAB是MATrix和LABoratory两个单词前三个字母的组合,意为“矩阵实验室”,它的创始人是Cleve Moler和Jack Little。
(2)在MATLAB的默认设置中,关键字显示的字体为蓝色,命令、表达式、计算结果显示的字体为黑色,字符串显示的字体为紫色,注释显示的字体为绿色,错误信息显示的字体为红色。
(3)在命令窗口中,输出结果显示为各行之间添加空行的命令为format compact,各行之间不添加空行的命令为format compact。
备注:本题布置给大家时有一点小错误,现在予以更正。
(4)在MATLAB中,各种标点符号的作用是不同的。
例如,空格的作用是分隔数组中每一行的各个元素,逗号的作用是分隔数组中每一行的各个元素或不同的命令,分号的作用是分隔数组中的各行或控制命令执行结果是否在命令窗口显示,冒号的作用是生成一维数组或显示全部元素,百分号的作用是注释行的开头,…的作用是把相邻两行的语句连接为一个命令,感叹号的作用是执行操作系统命令。
3.先建立自己的工作目录,再将自己的工作目录设置到MATLAB搜索路径下。
请写出操作步骤或用Matlab命令实现。
用help命令能查询到自己的工作目录吗解:操作步骤:(1)在Windows环境中建立一个工作目录,如:c:\mywork;(2)启动MATLAB,在File菜单中选择Set Path…命令,显示出如下图的对话框:(3)选择Add Folder…按钮,又显示出如下图的对话框:(4)在该对话框中找到c:\mywork文件夹,选择确定按钮。
(5)返回步骤(2)的对话框,选择Save按钮,然后选择Close按钮,关闭对话框。
(注意:选择Save和Close按钮的次序不能错,如果先选择Close按钮,就会直接关闭对话框,而不会将你的工作目录添加到搜索路径中。
采用这种方法设置的工作路径是永久性的,只要不在步骤(2)的对话框中选择Remove按钮移除该文件夹,那么你在该文件夹中保存的文件MATLAB总能找到。
4.利用MATLAB的帮助功能分别查询inv、plot、max、round等函数的功能及用法。
解:所使用的命令分别为help invINV Matrix inverse.INV(X) is the inverse of the square matrix X.A warning message is printed if X is badly scaled ornearly singular.See also SLASH, PINV, COND, CONDEST, LSQNONNEG, LSCOV.Overloaded functions or methods (ones with the same name in other directories)help gf/help lti/help idmodel/help atom/help ndlft/help ufrd/help umat/help uss/help sym/Reference page in Help browserdoc invhelp plotPLOT Linear plot.PLOT(X,Y) plots vector Y versus vector X. If X or Y is a matrix,then the vector is plotted versus the rows or columns of the matrix, whichever line up. If X is a scalar and Y is a vector, disconnected line objects are created and plotted as discrete points vertically at X.PLOT(Y) plots the columns of Y versus their index.If Y is complex, PLOT(Y) is equivalent to PLOT(real(Y),imag(Y)).In all other uses of PLOT, the imaginary part is ignored.Various line types, plot symbols and colors may be obtained withPLOT(X,Y,S) where S is a character string made from one elementfrom any or all the following 3 columns:b blue . point - solidg green o circle : dottedr red x x-mark -. dashdotc cyan + plus -- dashed m magenta * star (none) no liney yellow s squarek black d diamondw white v triangle (down)^ triangle (up)< triangle (left)> triangle (right)p pentagramh hexagramFor example, PLOT(X,Y,'c+:') plots a cyan dotted line with a plus at each data point; PLOT(X,Y,'bd') plots blue diamond at each data point but does not draw any line.PLOT(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by the (X,Y,S) triples, where the X's and Y's are vectors or matrices and the S's are strings.For example, PLOT(X,Y,'y-',X,Y,'go') plots the data twice, with a solid yellow line interpolating green circles at the data points. The PLOT command, if no color is specified, makes automatic use of the colors specified by the axes ColorOrder property. The default ColorOrder is listed in the table above for color systems where the default is blue for one line, and for multiple lines, to cyclethrough the first six colors in the table. For monochrome systems, PLOT cycles over the axes LineStyleOrder property.If you do not specify a marker type, PLOT uses no marker.If you do not specify a line style, PLOT uses a solid line.PLOT(AX,...) plots into the axes with handle AX.PLOT returns a column vector of handles to lineseries objects, one handle per plotted line.The X,Y pairs, or X,Y,S triples, can be followed byparameter/value pairs to specify additional propertiesof the lines. For example, PLOT(X,Y,'LineWidth',2,'Color',[.6 0 0])will create a plot with a dark red line width of 2 points.Examplex = -pi:pi/10:pi;y = tan(sin(x)) - sin(tan(x));plot(x,y,'--rs','LineWidth',2,...'MarkerEdgeColor','k',...'MarkerFaceColor','g',...'MarkerSize',10)See also PLOTTOOLS, SEMILOGX, SEMILOGY, LOGLOG, PLOTYY, PLOT3, GRID,TITLE, XLABEL, YLABEL, AXIS, AXES, HOLD, LEGEND, SUBPLOT, SCATTER, PLOT3.Overloaded functions or methods (ones with the same name in other directories) help SimTimeseries/help timeseries/help phytree/help channel/help cfit/help darray/help fints/help iddata/help idfrd/help idmodel/help idnlarx/help idnlhw/help cgrules/help localavfit/help localmod/help localmulti/help xregarx/help xregmodel/help xregtransient/help xregtwostage/help mdevtestplan/help sweepset/help cgdatasetnode/help mpc/help rfckt/help frd/help dspdata/help dtree/help ntree/help wdectree/help edwttree/help rwvtree/help wvtree/Reference page in Help browserdoc plothelp maxhelp round备注:后两个命令的执行结果这里就不再显示出来了,同学们可以自己执行一下。