




已阅读5页,还剩31页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Introduction to MATLAB 7for Engineers William J. Palm III,An Overview of MATLAB吳煒 (Wei Wu) Department of Chemical Engineering National Yunlin University of Science and TechnologyYunlin 640, Taiwan, R.O.C.,The default MATLAB Desktop. Figure 1.11,1-2,More? See pages 6-7.,Entering Commands and Expressions,Press the key once to see the previous entry, and so on.Press the Enter key to execute the command.,An Example Session 8/10ans = 0.8000 5*ansans = 4 r=8/10r = 0.8000 rr = 0.8000 s=20*rs = 16,Scalar Arithmetic Operations Table 1.11,Symbol Operation MATLAB form,exponentiation: ab ab*multiplication: aba*b/right division: a/b a/bleft division: b/a ab+addition: a + ba + b-subtraction: a - ba - b,Examples of Precedence 8 + 3*5ans = 23 8 + (3*5)ans = 23(8 + 3)*5ans = 554212 8/4*2ans = 04212 8/(4*2)ans = 3,(continued ),Examples of Precedence (continued) 3*42 + 5ans = 53(3*4)2 + 5ans = 14927(1/3) + 32(0.2)ans = 527(1/3) + 320.2ans = 5271/3 + 320.2ans = 11,The Assignment Operator =,Typing x = 3 assigns the value 3 to the variable x.We can then type x = x + 2. This assigns the value 3 + 2 = 5 to x. But in algebra this implies that 0 = 2.In algebra we can write x + 2 = 20, but in MATLAB we cannot.In MATLAB the left side of the = operator must be a single variable.The right side must be a computable value.,Commands for managing the work session Table 1.13,1-10,CommandDescription,clcClears the Command window.clearRemoves all variables from memory.clear v1 v2 Removes the variables v1 and v2 from memory.,(continued ),Commands for managing the work sessionTable 1.13 (continued)whoLists the variables currently in memory.whosLists the current variables and sizes, and indicates if they have imaginary parts.:Colon; generates an array having regularly spaced elements.,Comma; separates elements of an array.;Semicolon; suppresses screen printing; also denotes a new row in an array.Ellipsis; continues a line.,Special Variables and Constants Table 1.14,Command Description,ansTemporary variable containing the most recent answer.epsSpecifies the accuracy of floating point precision.i,jThe imaginary unit -1.InfInfinity.NaNIndicates an undefined numerical result.piThe number p.,Complex Number Operations The number c1 = 1 2i is entered as follows: c1 = 12i. An asterisk is not needed between i or j and a number, although it is required with a variable, such as c2 = 5 i*c1. Be careful. The expressions y = 7/2*iand x = 7/2i give two different results: y = (7/2)i = 3.5iand x = 7/(2i) = 3.5i.,Numeric Display Formats Table 1.15,Command Description and Example,format shortFour decimal digits (the default); 13.6745.format long16 digits; 17.27484029463547.format short eFive digits (four decimals) plus exponent; 6.3792e+03.format long e16 digits (15 decimals) plus exponent; 6.379243784781294e04.,Arrays The numbers 0, 0.1, 0.2, , 10 can be assigned to the variable u by typing u = 0:0.1:10. To compute w = 5 sin u for u = 0, 0.1, 0.2, , 10, the session is; u = 0:0.1:10; w = 5*sin(u); The single line, w = 5*sin(u), computed the formulaw = 5 sin u 101 times.,1-15,Array Index u(7)ans = 0.6000w(7)ans = 2.8232 Use the length function to determine how many values are in an array.m = length(w)m = 101,Polynomial Roots To find the roots of x3 7x2 + 40x 34 = 0, the session isa = 1,-7,40,-34;roots(a)ans = 3.0000 + 5.000i 3.0000 - 5.000i 1.0000The roots are x = 1 and x = 3 5i.,1-17,Some Commonly Used Mathematical Functions Table 1.31,Function MATLAB syntax1,exexp(x)xsqrt(x)ln xlog(x)log10 xlog10(x)cos xcos(x)sin xsin(x)tan xtan(x)cos-1 xacos(x)sin-1 x asin(x)tan-1 xatan(x),1The MATLAB trigonometric functions use radian measure.,A graphics window showing a plot. Figure 1.31,Some MATLAB plotting commands Table 1.33 (continued)plot(x,y)Generates a plot of the array y versus the array x on rectilinear axes.title(text)Puts text in a title at the top of the plot.xlabel(text)Adds a text label to the horizontal axis (the abscissa).ylabel(text)Adds a text label to the vertical axis (the ordinate).,Solution of Linear Algebraic Equations6x + 12y + 4z = 707x 2y + 3z = 52x + 8y 9z = 64 A = 6,12,4;7,-2,3;2,8,-9;B = 70;5;64;Solution = ABSolution = 3 5 -2The solution is x = 3, y = 5, and z = 2.,The MATLAB Command window with the Editor/Debugger open. Figure 1.41,1-29,Example of a Script FileProblem:The speed v of a falling object dropped with no initial velocity is given as a function of time t by v = gt.Plot v as a function of t for 0 t tf, where tf is the final time entered by the user.,1-36,(continued ),Example of a Script File (continued)% Program falling_speed.m:% Plots speed of a falling object.% Created on March 1, 2004 by W. Palm% Input Variable:% tf = final time (in seconds)% Output Variables:% t = array of times at which speed is % computed (in seconds)% v = array of speeds (meters/second)%,(continued ),Example of a Script File (continued)% Parameter Value:g = 9.81; % Acceleration in SI units% Input section:tf = input(Enter final time in seconds:);%,(continued ),Example of a Script File (continued)% Calculation section:dt = tf/500;% Create an array of 501 time values.t = 0:dt:tf;% Compute speed values.v = g*t;% Output section:Plot(t,v),xlabel(t (s),ylabel(v m/s),The MATLAB Help Browser. Figure 1.51,1-42,Help Functions,help funcname: Displays in the Command window a description of the specified function funcname.lookfor topic: Displays in the Command window a brief description for all functions whose description includes the specified key word topic.doc funcname: Opens the Help Browser to the reference page for the specified function funcname, providing a description, additional remarks, and examples.,1-43,More? See pages 38-43.,Relational operators Table 1.61,1-44,RelationalMeaningoperator,Greater than.=Greater than or equal to.=Equal to.=Not equal to.,The if Statement The general form of the if statement isif expressioncommandselseif expressioncommandselsecommandsendThe else and elseif statements may be omitted if not required.,1-48,1-49,Suppose that we want to compute y such that,154x + 10if x 910x + 10if 0 x 910if x = 9y = 15*sqrt(4x) + 10elseif x = 0y = 10*x + 10elsey = 10endNote that the elseif statement does not require a separate end statement.,y =,More? See pages 47-48.,LoopsThere are two types of explicit loops in MATLAB; the for loop, used when the number of passes is known ahead of time, and the while loop, used when the looping process must terminate when a specified condition is satisfied, and thus the number of passes is not known in advance.,1-50,A simple example of a for loop ism = 0;x(1) = 10;for k = 2:3:11 m = m+1; x(m+1) = x(m) + k2;endk takes on the values 2, 5, 8, 11. The variable m indicates the index of the array x. When the loop is finished the array x will have the values x(1)=14,x(2)=39,x(3)=103,x(4)=224.,1-51,A simple example of a while loop isx = 5;k = 0;while x 25 k = k + 1; y(k) = 3*x; x = 2*x-1;end The loop variable x is initially assigned the value 5, and it keeps this value until the statement x = 2*x - 1 is encountered the first time. Its value then changes to 9. Before each pass through the loop, x is checked to see if its value is less than 25. If so, the pass is made. If not, the loop is skipped.,1-52,Example of a for LoopWrite a script file to compute the sum of the first 15 terms in the series 5k2 2k, k = 1, 2, 3, , 15.total = 0;for k = 1:15 total =
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 二零二五年度大型发电机组进口贸易合同
- 高三试卷:山东省临沂市2025届高三上学期教学质量检测考试暨期中考试(九五联考)数学
- 2025版现代农业大棚建设与租赁一体化服务合同
- 二零二五年度房屋修缮维修工程合同协议
- 2025版光纤熔接设备性能检测与认证合同
- 2025版场地地质环境调查与监测服务合同下载
- 2025版学术论文翻译服务合同范本正规范本
- 2025版新能源电池产品销售与服务合同范本
- 二零二五年度长租公寓融资租赁协议
- 2025版房屋租赁合同范本(含租赁物维修基金及物业管理费用)
- 艺术课程标准(2022年版)
- 卫生部手术分级目录(2023年1月份修订)
- 电荷及其守恒定律、库仑定律巩固练习
- YC/T 199-2006卷烟企业清洁生产评价准则
- YY 0666-2008针尖锋利度和强度试验方法
- GB/T 6663.1-2007直热式负温度系数热敏电阻器第1部分:总规范
- GB/T 5184-1996叉车挂钩型货叉和货叉架安装尺寸
- GB/T 19355.2-2016锌覆盖层钢铁结构防腐蚀的指南和建议第2部分:热浸镀锌
- 小沈阳《四大才子》欢乐喜剧人台词
- 机械制造技术基础(课程精完整版)课件
- 护士注册健康体检表下载【可直接打印版本】
评论
0/150
提交评论