




免费预览已结束,剩余11页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Introduction to MATLABMATLAB (short for Matrix Laboratory) is a special-purpose computer program optimized to perform engineering and scientific calculations. It started life has a program designed to perform matrix mathematics, but over the years it has grown into a flexible computing system capable of solving essentially any technical problem.The MATLAB program implements the MATLAB programming language and provides an extensive library of predefined functions that make technical programming tasks easier and more efficient. This book introduces the MATLAB language and shows how to use it to solve typical technical problems.MATLAB is a huge program, with an incredibly rich variety of functions. Even the basic version of MATLAB without any toolkits is much richer than other technical programming languages. There are more than 1000 functions in the basic MATLAB product alone,and the toolkits extend this capability with many more functions in various specialties. This book makes no attempt to introduce the user to all of MALTLABs own tools to locate the correct function for a specific purpose from the enormous choice available.Advantages of MATLAB MATLAB has many advantages compared with conventional computer languages for technical problem solving. Among them are the following:1. Ease of UseMATLAB is an interpreted language, like many versions of Basic. Like Basic, it is very easy to use. The program can be used as a scratch pad to evaluate expressions typed at the command line, or it can be used to execute large prewritten programs. Programs may be easily written and modified with the built-in integrated development environment, and debugged with the MATLAB debugger. Because the language is so easy to use, it is ideal for educational use, and for the rapid prototyping of new programs. Many program development tools are provided to make the program easy to use. a workspace browser, and extensive demos.2. Platform independence MATLAB is supported on many different computer systems, providing a large measure of platform independence. At the time of this writing, the language is supported on windows 9x/NT/2000 and many different versions of UNIX. Programs written on any platform will run on all of the other platforms, and data files written on any platform may be read transparently on any other platforms, AS a result,Programs written in MATLAB can migrate to new platforms when the needs of the user change.3. Predefined FunctionsMATLAB comes complete with an extensive library of predefined functions that provide tested and prepackaged solutions to many basic technical tasks. For example, suppose that you are writing a program that must calculate the statistics associated with an input data set. In most languages, you would need to write your own subroutines or functions to implement calculations such as the arithmetic mean, standard deviation, median, and so forth. These and hundreds of other functions are built right into the MATLAB language, making your job much easier.In addition to the large library of functions built into the basic MATLAB language, many special-purpose toolboxes are available to help solve complex problems in specific areas. For example, a user can buy standard toolboxes to solve problems in Signal Processing, Control Systems, Communications, Image Processing, and Neural Networks, among many others. There is also an extensive collection of free user-contributed MATLAB programs that are shared through the MATLAB Web site.4. Device-Independent PlottingUnlike most other computer languages, MATLAB has many integral plotting and imaging commands. The plots and images can be displayed on any graphical output device supported by the computer on which MATLAB is running. This capability makes MATLAB an outstanding tool for visualizing technical data.5. Graphical User InterfaceMATLAB includes tools that allow a programmer to interactively construct a graphical user interface (GUI) for his or her program. With this capability, the programmer can design sophisticated data analysis programs that can be operated by relatively inexperienced users.6. MATLAB CompilerMATLABs flexibility and platform independence is achieved by compiling MATLAB programs into a device-independence p-code, and then interpreting the p-code instructions at run time. This approach is similar to that used by Microsoft is Visual Basic language. Unfortunately, the resulting programs can sometimes execute slowly because the MATLAB code is interpreted rather than compiled. We will point out features that tend to slow program execution when we encounter them. A separate MATLAB compiler is available. This compiler can compile a MATLAB program into a true executable that runs faster than the interpreted code. It is a great way to convert a prototype MATLAB program into an executable suitable for sale and distribution to users.Disadvantages of MATLAB MATLAB has two principal disadvantages. The first is that it is an interpreted language, and therefore can execute more slowly than compiled languages. This problem can be mitigated by properly structuring the MATLAB program and by the use of the MATLAB compiler to compile the final MATLAB program before distribution and general use.The second disadvantage is cost: A full copy of MATLAB is 5 to 10 times more expensive than a conventional C or Fortran compiler. This relatively high cost is more than offset by the reduced time required for an engineer or scientist to create a working program, so MATLAB is cost-effective for businesses. However, it is too expensive for most individuals to consider purchasing. Fortunately, there is also an inexpensive Student Edition of MATLAB, which is a great tool for students wanting to learn the language. The Student Edition of MATLAB is essentially identical to the full edition.With the introduction of branches and loops, our programs are going to become more complex, and it will get easier to make mistakes. To help avoid programming errors, we will introduce a formal program design procedure based on the technique known as top-down design. We will also introduce a common algorithm development tool known as pseudo code.Introduction To Top-Down Design TechniquesSuppose that you are an engineer working in industry, and that you need to write a program to solve some problem. How do you begin? When given anew problem, there is a natural tendency to sit down at a keyboard and start programming without “wasting” a lot of time thinking about the problem first. It is often possible to get away with this “on the fly” approach to programming for very small problems, such as many of the examples in this book. In the real world, however, problems are larger, and a programmer attempting this approach will become hopelessly bogged down. For larger problems, it pays to completely think out the problem and the approach you are going to take to it before writing a single line of code. We introduce a formal program design process in this section, and then apply that process to every major application developed in the remainder of the book. For some of the simple examples that we will be doing, the design process will seem like overkill; however, as the problems that we solve get larger and larger, the process becomes more and more essential to successful programming.When I was an undergraduate, one of my professors was fond of saying, “programming is easy. It is knowing what to program that is hard.” his point was forcefully driven home to me after I left university and began working in industry on larger scale software projects. I found that the most difficult port of my job was to understand the problem I was trying to solve. Once I really understood the problem, it became easy to break the problem apart into smaller, more easily manageable pieces with well-defined functions, and then to tackle those pieces one at a time.Top-down design is the process of starting with a large task and breaking it down into smaller, more easily understandable pieces, which perform a portion of the desired task. Each subtask may in turn be subdivided into smaller subtasks if necessary. Once the program is divided into small pieces, each piece can be coded and tested independently. We do not attempt to combine the subtasks into a complete task until each of the subtasks has been verified to work properly by itself.The concept of top-down design is the basis of our formal program design process. We will now introduce the details of the process, which is illustrated in figure 1 the steps involved are:1. Clearly state the problem that you are trying to solve.Programs are usually written to fill some perceived need, but that need may not be articulated clearly by the person requesting the program. For example, a user may ask for a program to solve a system of simultaneous linear equations. This request is not clear enough to allow a programmer to design a program to meet the need; he or she must first know much more about the problem to be solved. Is the system of equations to be solved real or complex? What is the maximum number of equations and unknown that the program must handle? Are there any symmetry in the equations that might be exploited to make the task easier? The program designer will have to talk with the user requesting the program, and the two of them will have come up with a clear statement of exactly what they are trying to accomplish. A clear statement of the problem will prevent misunderstandings, and it will also help the program designer to properly organize his or her thoughts. In the example we were describing, a proper statement of the problem might have been: Figure 1Design and write a program to solve a system of simultaneous linear equations having real coefficients and with up to 20 equations in 20 unknowns.2. Define the inputs required by the program and the outputs to be produced by the program.The inputs to the program and the outputs produced by the program must be specified so that the new program will properly fit into the overall processing scheme. In this example, the coefficients of the equations to be solved are probably in some pre-existing order, and our new program needs to be able to read them in that order. And our new program needs to be able to read them in that order. Similarly, it needs to produce the answers required by the programs that may follow it in the overall processing scheme, and to write out those answers in the format needed by the programs following it.3. Design the algorithm that you intend to implement in the program.An algorithm is a step-by-step procedure for finding the solution to a problem. It is at this stage in the process that top-down design techniques come into play. The designer looks for logical divisions within the problem, and divides it up into subtasks along those lines. This process is called decomposition. If the subtasks are large, the designer can break them up into even smaller sub-tasks. This process continues until the problem has been divided into many small pieces, each of which does a simple, clearly understandable job.After the problem has been decomposed into small pieces, each piece is further refined through a process called stepwise refinement. In stepwise refinement, a designer starts with a general description of what the piece of code should do, and then defines the functions of the piece in greater and greater detail until they are specific enough to be turned into MATLAB statements. Stepwise refinement is usually done with pseudo code, which will be described in the next section.It is often helpful to solve a simple example of the problem by hand during the algorithm development process. If the designer understands the steps that he or she went through in solving the problem by hand, then he or she will be better able to apply decomposition and stepwise refinement to the problem.4. Turn the algorithm into MATLAB statements.If the decomposition and refinement process was carried out properly, this step will be very simple. All the programmer will have to do is to replace pseudo code with the corresponding MATLAB statements on a one-for-one basis.5. Test the resulting MATLAB programThis step is the real killer. The components of the program must first be tested individually, if possible, and then the program as a whole must be tested. When testing a program, we must verify that it works correctly for all legal input data sets. It is very common for a program to be written, tested with some standard data set, and released for use, only to find that it produces the wrong answers (or crashes) with a different input data set. If the algorithm implemented in a program includes different branches, we must test all of the possible branches to confirm that the program operates correctly under every possible circumstance.Large programs typically go through a series of tests before they are released for general use (see Figure 2). The first stage of testing is sometimes called unit testing. During unit testing, the individual subtasks of the program are tested separately to confirm that they work correctly. After the unit testing is completed, the program goes through a series of builds, during which the individual subtasks are combined to produce the final program. The first build of the program typically includes only a few of the subtasks. It is used to check the interactions among those subtasks and the functions performed by the combinations of the subtasks. In successive builds, more and more subtasks are added, until the entire program is complete. Testing is performed on each build, and any errors(bugs) detected are corrected before moving on to the next build. Figure 2MATLAB 介绍MATLAB (矩阵实验室的简称)是一种专业的计算机程序,用于工程科学的矩阵数学运算。但在以后的几年内,它逐渐发展为一种极其灵活的计算体系,用于解决各种重要的技术问题。MATLAB 程序执行MATLAB 语言,并提供了一个极其广泛的预定义函数库,这样就使得技术工作变得简单高效。本书将介绍MATLAB 语言,并向大家展示如何运用它去解决经典的技术问题。MATLAB 是一个庞大的程序,拥有难以置信的各种丰富的函数;即使基本版本的MATLAB 语言拥有的函数也比其他的工程编程语言要丰富的多。基本的MATLAB 语言已经拥有了超过1000 多个函数,而它的工具包带有更多的函数,由此扩展了它在许多专业领域的能力。本书无意将MATLAB 的所有函数介绍给大家,而是让大家掌握编写调试和优化程序的基本功,还有一些重要函数的子集。所以从大量可利用的函数中筛选出你所需要的函数就显得尤为重要。MATLAB 的优点MATLAB 语言相对于传统的科技编程语言有诸多的优点。主要包括:1.易用性MATLAB 是种解释型语言,就像各种版本的BASIC。和BASIC 一样,它简单易用程序可用作便笺簿求打在命令行处表达式的值,也可执行预先写好的大型程序。在MATLAB 集成开发环境下,程序可以方便的编写,修改和调试。这是因为这种语言极易使用,对于教育应用和快速建立新程序的原型,它是一个理想的工具。许多的编程工具使得 MATLAB 十分简单易用。这些工具包括:一个集成的编译/调试器,在线文件手册,工作台和扩展范例。2.平台独立性MATLAB 支持许多的操作系统,提供了大量的平台独立的措施。在本书编写的时侯, windows98/2000/NT 和许多版本的UNIX 系统都支持它。在一个平台上编写的程序,在其它平台上一样可以正常运行,在一个平台上编写的数据文件在其它平台上一样可以编译。因此用户可以根据需要把MATLAB 编写的程序移植到新平台。3.预定义函数MATLAB 带有一个极大的预定义函数库,它提供了许多已测试和打包过的基本工程问题的函数。例如,假设你正在编写一个程序,这个程序要求你必须计算与输入有关的统计量。在许多的语言中,你需要写出你所编数组的下标和执行计算所需要的函数,这些函数包括其数学意义,中值,标准误差等。像这样成百上千的函数已经在MATLAB 中编写好,所以让编程变得更加简单。除了植入MATLAB 基本语言中的大量函数,还有许多专用工具箱,以帮助用户解决在具体领域的复杂问题。例如,用户可以购买标准的工具箱以解决在信号处理,控制系统,通信,图象处理,神经网络和其他许多领域的问题。4.机制独立的画图与其他语言不同,MATLAB 有许多的画图和图象处理命令。当MATLAB 运行时,这些标绘图和图片将会出现在这台电脑的图像输出设备中。此功能使得MATLAB 成为一个形象化技术数据的卓越工具。5.用户图形界面MATLAB 允许程序员为他们的程序建立一个交互式的用户图形界面。利用MATLAB 的这种功能,程序员可以设计出相对于无经验的用户可以操作的复杂的数据分析程序。6.MATLAB 编译器MATLAB 的灵活性和平台独立性是通过将MATLAB 代码编译成设备独立的P 代码,然后在运行时解释P 代码来实现的。这种方法与微软的VB 相类似。不幸的是,由于MATLAB 是解释性语言,而不是编译型语言,产生的程序执行速度慢。当我们遇到执行速度慢的程序时,我们将会指出其这一特性。MATLAB 的缺点MATLAB 有两个基本的缺点。第一,它是解释型语言,其执行速度要比编译型语言慢得多。这个问题可以通过合理的MATLAB 结构得到缓解,也可以在发行广泛使用前编译出MATLAB 程序。第二,他的费用较高。一个完全版MATLAB 编译器的大小是一个C 语言或Fortan 语言编译器的5 到10倍。但MATLAB 能够节省大量的时间在科技编程方面,故MATLAB 在商业编程过程中是节省成本的。尽管如此,相对于大多数考虑购买的人还是很昂贵的。幸运的是,它有一个价格便宜的学生专用版本,对学生来说它是学习MATLAB 语言的一个重要工具。学生版的MATLAB和完全版的MATLAB 是基本一致的。随着选择和循环介绍,我们的程序也将变得复杂,对于解决问题来说,将会变得简单。为了帮助大家避免在编程过程中出现大量的错误,我们将向大家介绍正式的编程步骤,即自上而下的编程方法。我们也会向大家介绍一些普通的算法开发工具即伪代码。自上而下的编程方法简介假设你是在工厂工作的工程师,为了解决某些问题,你要编写一个程序。你如何开始呢?当遇到一个新问题时,我们的心里会自然而然的产生这样的想法:马上坐在计算机前,开始
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 购买液压拖车合同范本
- 帮带宠物出境合同范本
- 合伙开火锅店合作协议书2篇
- 高压注水泵房配电设备维修技术协议3篇
- 考勤工作心得体会怎么写(范文10篇)
- 指导性案例的题目及答案
- 八月一日讲话参考
- 旅游行业活动策划攻略
- 2025年事业单位工勤技能考试考试题库及参考答案
- CN222980410U 一种静簧与线圈架装配结构及拍合式继电器 (四川宏发电声有限公司)
- 文化政策与法规课件
- 社区社群团购新团长培训案例课件
- 外科学教学课件:食管癌
- 露天矿开采技术课件汇总全套ppt完整版课件最全教学教程整套课件全书电子教案
- 部编人教版九年级上册初中历史 第1课 古代埃及 教案(教学设计)
- 钢结构钢梁计算(PPT33张)
- 幼儿教师——散文诗
- 创伤骨折院前急救ppt课件(PPT 50页)
- DB3302_T 1130-2022建筑垃圾运输管理规范(高清-可复制)
- 锚杆、锚索锚固力计算
- 日语话剧展演策划
评论
0/150
提交评论