还剩12页未读,继续阅读
本资源只提供10页预览,全部文档请下载后查看!喜欢就下载吧,查找使用更方便
文本内容:
p44表2-1p46表2-2p53表2-7p77表3-5p47表2-3p126表4-4__TLAB系统的启动与一般的Windows程序一样,启动__TLAB系统有3种常见方法1使用Windows“开始”菜单2运行__TLAB系统启动程序__tlab.exe3利用快捷方式__TLAB系统的退出要退出__TLAB系统,也有3种常见方法1在__TLAB主窗口File菜单中选择Exit__TLAB命令2在__TLAB命令窗口输入Exit或Quit命令3单击__TLAB主窗口的“关闭”按钮在__TLAB系统中使用帮助方式有三1是利用help指令,如果你已知要找的题材topic为何的话,直接键入helptopic所以即使身旁没有使用手册,也可以使用help指令查询不熟悉的指令或是题材之用法,例如helpsqrt2是利用lookfor指令,它可以从你键入的关键字key-word(即使这个关键字并不是__TLAB的指令)列出所有相关的题材,例如lookforcosinelookforsine3是利用指令视窗的功能选单中的Help,从中选取TableofContents(目录)或是Index(索引)常用的产生通用特殊矩阵的函数有zeros产生全0矩阵零矩阵ones产生全1矩阵eye产生单位矩阵rand产生0~1间均匀分布的随机矩阵randn产生均值为0,方差为1的标准正态分布随机矩阵如果需要产生均匀随机数不是介于
[01]区间,可以采用以下步骤将数值从
[01]区间转换到其它区间假设要得到一组数值是介于
[24]区间,我们先产生一组数介于
[01]区间,再将其值乘以2,因为2等于区间上下限的差值4-2接著再加上下限值2,即可得到乱数值是介于
[24]区间例如区间为[ab],a为下限值,b为上限值则算式如下x=b-a*r+a如果需要产生正态随机数值的平均值和方差并非0和1,可以采用以下步骤将平均值和变异数做转换假设要得到一组数值的平均值为b和方差为a,我们先产生一组数r,再将其值乘以方差a接著再加平均值b算式如下x=a*r+b变量命名规则注意函数名的命名规则
1. 变量名的大小写是敏感
2. 变量的第一个字符必须为英文字母
3. 变量名可以包含下连字符、数字,但不能为空格符、标点创建向量的方法
1、直接输入法
2、利用冒号运算创建向量
3、使用函数linspa__和logspa__(利用帮助理解logsap__函数的规则)linspa__abn的冒号表达式的等价形式a:b-a/n-1:b等价A:j表示取A矩阵的第j列全部元素;Ai:表示A矩阵第i行的全部元素;Aij表示取A矩阵第i行、第j列的元素Ai:i+m:表示取A矩阵第i~i+m行的全部元素;A:k:k+m表示取A矩阵第k~k+m列的全部元素,Ai:i+mk:k+m表示取A矩阵第i~i+m行内,并在第k~k+m列中的所有元素矩阵元素的访问x=[12345678;4567891011];%二维2x8矩阵»x3%x的第三个元素ans=2»x
[125]%x的第
一、
二、五个元素ans=143x23%x的第二行第三列的元素ans=6x1:5%x的第前五个元素ans=14253»x10:end%x的第十个元素后的元素ans=869710811»x10:-1:2%x的第十个元素和第二个元素的倒排ans=857463524»xfindx5%x中大于5的元素ans=67869710811»x4=100%给x的第四个元素重新给值x=12345678410067891011»x3=[]%删除第三个元素(不是二维数组)x=Columns1through1214100364758697Columns13through1510811»x16=1%加入第十六个元素x=Columns1through1214100364758697Columns13through16108111矩阵元素全下标和单下标的的转换关系以的矩阵为例,该矩阵的第行第列的元素全下标表示为单下标对复数举证,矩阵转置和数组转置的区别逻辑运算和关系运算利用逻辑运算和关系运算在数组中找到某些符合条件的元素一些基本函数roundx将x值进位至最接近的整数fixx将x值进位至最接近0的整数floorx将x值进位至最接近-∞的整数__ilx将x值进位至最接近∞的整数signx如果x0传回值为-1,如果x=0传回值为0,如果x0传回值为remxy传回x/y的余数,例如rem254的值为1expx指数函数logx以e
2.718282为底的对数函数,及自然对数log10x为10底的对数函数简单的编程
1、编程创建一个5×5的方阵,要求所有的对角线上的元素值为3,对角线右上角的所有元素值为2,对角线左小方的所有元素值为
12、编写程序求[100,200]之间第一个能被21整除的整数
3、一个三位整数各位数字的立方和等于该数本身则称该数为水仙花数输出全部水仙花数例如:
4、利用for循环求1!+2!+3!+4!+5!的值
5、计算分段函数的值
6、写出下列程序的执行结果s=0;a=[121314;151617;181920;212223];fork=as=s+k;enddisps;
7、Fibonacci数组的元素满足Fibonacci规则,();且现要求该数组中第一个大于_____的元素
8、for循环指令来寻求Fibonacc数组中第一个大于_____的元素
9、矩阵矩阵;分别求出矩阵及与中对应元素之间的乘积.
10、利用公式求的近似值直到最后一项小于脚本文件
(1)它只是一串按用户意图排列而成(包括控制流指令在内的)__TLAB指令__
(2)脚本文件运行后,所产生的所有变量都驻留在__TLAB基本工作区间只用用户不使用clear指令加以清除,且__TLAB指令窗不关闭,这些变量就能将一直保存在基本工作区间中基本工作区间岁__TLAB的启动而产生,只用关闭__TLAB时,该基本空间才被删除函数文件
(1)从形式上看,与脚本文件不同,函数文件的第一行总是以“function”引导的“函数申明行”,该行列出函数与外部__的全部输入输出变量2从运行上看,与脚本文件不同,每当函数文件运行,__TLAB就会专门为它开辟一个临时的工作区间,所有中间变量都存放在这个临时函数工作区间当执行完文件最后一条指令或遇到ruturn时,就结束该函数文件的运行,同时该临时函数空间及其所用的中间变量就立即被清除
(3)函数空间随具体M函数文件的被调用而产生,随调用结束而删除,函数空间是相对基本空间__、临时的在__TLAB整个运行期间,可以产生任意多个临时函数空间
(4)__TLAB允许使用比函数定义中较少的输入输出变量,实现对函数的调用
(5)假如在函数文件中,发生对某脚本文件的调用,那么该脚本文件运行产生的所以变量都存放于该函数空间中,而不是存放在基本空间全局变量及局部变量的区别局部变量是存在于函数空间内部的中间变量,产生于该函数的运行过程中,其影响范围也仅限于该函数本身通过global指令,__TLAB允许几个不同的函数空间及基本工作空间共享一个变量,这种背共享的变量称为全局变量,每个希望共享全局变量的函数或__TLAB基本工作空间,必须逐个用global对具体变量加以专门定义没采用global定义的函数或基本工作空间经无权享用全局变量子函数与私有函数的区别p136数据图形的可视化命令含义plot建立向量或矩阵各队队向量的图形loglogx、y轴都取对数标度建立图形semilogxx轴用于对数标度,y轴线性标度绘制图形semilogyy轴用于对数标度,x轴线性标度绘制图形title给图形加标题xlabel给x轴加标记ylabel给y轴加标记text在图形指定的位置上加文本字符串gtext在鼠标的位置上加文本字符串grid打开网格线plotxy’s’字符串s设定曲线颜色和绘图方式subplotmnp——按从左至右,从上至下排列bar––––绘制直方图stem––––绘制火柴杆图polar––––绘制极坐标图pie––––饼图plot3XYZ——XYZ是维数相同的矩阵mesh函数surf函数xlabelx轴;%x轴注解ylabely轴;%y轴注解title余弦函数;%图形标题legendy=cosx;%图形注解gtexty=cosx;%图形注解用鼠标定位注解位置gridon;%显示格线Axis’[xminx__xyminy__x]’以xminx__x设定横轴的下限及上限,以yminy__x设定纵轴的下限及上限Axis’auto’横轴及纵轴依照数据大小的上下限来订定,横轴及纵轴比例是4:3axis’square’横轴及纵轴比例是1:1,将当前图形设置为正方形图形axis’equal’将横轴纵轴的尺度比例设成相同值axis’nor__’l关闭axisequal和axissquare命令的作用axis’off’将纵轴及横轴取消axis’on’恢复纵轴及横轴
1、在[04pi]范围内画sinxcosx在同一个图象中;其中cosx图象用红色小圆圈画.并在函数图上标注“y=sinx”“y=cosx”x轴y轴标题为“正弦余弦函数图象”
2、画椭圆
3、用不同标度在同一坐标内绘制曲线y1=
0.2e-
0.5xcos4πx和y2=2e-
0.5xcosπx
4、采用图形保持,在同一坐标内绘制曲线y1=
0.2e-
0.5xcos4πx和y2=2e-
0.5xcosπx
5、在同一坐标内,分别用不同线型和颜色绘制曲线y1=
0.2e-
0.5xcos4πx和y2=2e-
0.5xcosπx,标记两曲线交叉点
6、在同一坐标中,可以绘制3个同心圆,并加坐标控制
7、画出所表示的三维曲面的取值范围是简单题型
1、写出计算Sin30o的程序语句.填写程序语句sinpi*30/180或sinpi/6若用户想计算的值,那末用户应依次键入以下字符y1=2*sin
0.3*pi/1+sqrt52建立起始值=3增量值=
5.5终止值=44的一维数组x填写程序语句x=3:
5.5:443建立等差一维数组x首项为0末项为项数为15填写程序语句x=linspa__0pi
154、A=Logspa__133A=
[101001000]
5、A=1:9B=A3A7=
[000111000]
6、设A为2×3矩阵建立与矩阵A同样大小的零矩阵解A=[123;456];%产生一个2×3阶矩阵AzerossizeA%产生一个与矩阵A同样大小的零矩阵
7、求一元二次方程ax2+bx+c=0的根程序如下a=inputa=;b=inputb=;c=inputc=;d=b*b-4*a*c;x=[-b+sqrtd/2*a-b-sqrtd/2*a];disp[x1=num2strx1x2=num2strx2];
8、建立随机矩阵1在区间
[2050]内均匀分布的5阶随机矩阵2均值为
0.
6、方差为
0.1的5阶正态分布随机矩阵解x=20+50-20*rand5y=
0.6+sqrt
0.1*randn
59、产生5阶随机方阵A,其元素为
[1090]区间的随机整数,然后判断A的元素是否能被3整除1生成5阶随机方阵AA=fix90-10+1*rand5+102判断A的元素是否可以被3整除P=remA3==0其中,remA3是矩阵A的每个元素除以3的余数矩阵此时,0被扩展为与A同维数的零矩阵,P是进行等于==比较的结果矩阵
10、建立一个字符串向量,然后对该向量做如下处理1取第1~5个字符组成的子字符串2将字符串倒过来重新排列3将字符串中的小写字母变成相应的大写字母,其余字符不变4统计字符串中小写字母的个数(abs和double函数都可以用来获取字符串矩阵所对应的ASCII码数值矩阵相反,char函数可以把ASCII码矩阵转换为字符串矩阵)解ch=‘ABc123d4e56Fg9’;subch=ch1:5%取子字符串revch=chend:-1:1%将字符串倒排k=findch=‘a’ch=‘z’;%找小写字母的位置chk=chk-‘a’-‘A’;%将小写字母变成相应的大写字母charchlengthk%统计小写字母的个数
11、输入一个字符,若为大写字母,则输出其对应的小写字母;若为小写字母,则输出其对应的大写字母;若为数字字符则输出其对应的数值,若为其他字符则原样输出(abs函数可以求实数的绝对值、复数的模、字符串的ASCII码值)c=input请输入一个字符s;ifc=Ac=Zdispcharabsc+absa-absA;elseifc=ac=zdispcharabsc-absa+absA;elseifc=0c=9dispabsc-abs0;elsedispc;end
12、若一个数等于它的各个真因子之和,则称该数为完数,如6=1+2+3,所以6是完数求
[1500]之间的全部完数form=1:500s=0;fork=1:m/2ifremmk==0s=s+k;endendifm==sdispm;endend
13、例8编写函数文件求半径为r的圆的__和周长函数文件如下function[sp]=fcircler%CIRCLEcalculatetheareaandperimeterofacircleofradiir%r圆半径%s圆__%p圆周长s=pi*r*r;p=2*pi*r;
14、利用函数文件,实现直角坐标xy与极坐标ρθ之间的转换函数文件tran.m function[rhotheta]=tranxyrho=sqrtx*x+y*y;theta=atany/x;调用tran.m的命令文件__in
1.m x=inputPleaseinputx=:;y=inputPleaseinputy=:;[rhothe]=tranxy;rhothe
15、画出由函数形成的立体网状图:x=linspa__-2225;%在x轴上取25点y=linspa__-2225;%在y轴上取25点[xxyy]=meshgridxy;%xx和yy都是21x21的矩阵zz=xx.*exp-xx.^2-yy.^2;%计算函数值,zz也是21x21的矩阵meshxxyyzz;%画出立体网状图
16、a=1:2:11;b=2:1:7;a-b4的结果1356810a2|b6的结果100001。