1 / 39

实验安排 本周六和下周六上机时间: 上午: 8 : 30~10 : 00 第一组 上午: 11 : 00~11 : 30 第二组 下午: 14 : 30~16 : 00 第三组

实验安排 本周六和下周六上机时间: 上午: 8 : 30~10 : 00 第一组 上午: 11 : 00~11 : 30 第二组 下午: 14 : 30~16 : 00 第三组. MATLAB 工程应用 MATLAB Engineering Application. 主讲教师:胡章芳 Email: huzf@cqupt.edu.cn 电话: 66129480 光电工程学院 光信息科学 与技术教学部 ( 一教四楼 ). Book S. J. Chapman, MATLAB Programming for Engineers (2nd Edition).

benoit
Télécharger la présentation

实验安排 本周六和下周六上机时间: 上午: 8 : 30~10 : 00 第一组 上午: 11 : 00~11 : 30 第二组 下午: 14 : 30~16 : 00 第三组

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 实验安排 本周六和下周六上机时间: 上午:8:30~10:00 第一组 上午:11:00~11:30 第二组 下午:14:30~16:00 第三组

  2. MATLAB工程应用MATLAB Engineering Application 主讲教师:胡章芳 Email:huzf@cqupt.edu.cn 电话:66129480 光电工程学院 光信息科学 与技术教学部(一教四楼)

  3. BookS. J. Chapman, MATLAB Programming for Engineers(2nd Edition) • Reference • 张志涌等,MATLAB教程-基于6.X版本,北京航空航天大学出版社 • 许波等,MATLAB工程数学应用,清华大学出版社

  4. 引言 算一下你逃作业的风险有多大? • 在本课堂上共有53名学生, • 每次上完课我会抽31名学生的作业进行检查。 • 我总共大概会布置10次作业。 • 请问你至少有一次被抽到的几率是多少?

  5. 引言 解: 1-[(53-31)/53]10 = ? 太简单了! 是不是想赶紧知道问题的答案? • 手算 • 计算器 • 用你刚学过的C语言来算

  6. 引言 C语言求解: main() { float m; m = 1-((53-31)/53.0)^10; printf(“%f”,m); } 要是没有1、2、4、5行就好了…

  7. 引言 matlab语言求解: m = 1-((53-31)/53).^10 可以用这么简单语句完成?

  8. 初识MATLAB • 例1-1 绘制正弦曲线和余弦曲线。x=[0:0.5:360]*pi/180;plot(x,sin(x),x,cos(x)); • 例1-2 求方程 3x4+7x3 +9x2-23=0的全部根。p=[3,7,9,0,-23]; %建立多项式系数向量x=roots(p) %求根

  9. 例1-3 求积分quad('x.*log(1+x)',0,1) • 例1-4 求解线性方程组。a=[2,-3,1;8,3,2;45,1,-9]; b=[4;2;17]; x=inv(a)*b

  10. 本课程总体安排 • 1、本课程由理论(16学时/8次课程)和上机(16学时/8次上机)两部分组成。 • 2、该课程成绩评定:学生成绩由理论考试和平时成绩两部分。实验成绩单独计算(实验考勤+现场操作+实验报告),由器材及实验管理处统一管理。 • 3、平时成绩纪录:迟到一次扣一分,旷课一次扣2分,不交作业一次扣1分,抄作业者一次扣1分。

  11. 答疑安排 • 1 时间:每周一下午 • 2 地点:光电工程学院 光信息科学与技术教学部(一教四楼) • 3 也可采用电话和邮件的形式:66129480 • huzf@cqupt.edu.cn

  12. Content • Introduction to MATLAB • MATLAB Basics • Branching Statements and Program Design • Loops • User-Defined Functions • Complex Data, Character Data, and Additional Plot Types • Sparse Arrays, Cell Arrays, and Structures • Input/Output Functions • Handle Graphics • Graphical User Interfaces

  13. Chapter 1Introduction to MATLAB 1.1 The Advantages of MATLAB 1.2 Disadvantages of MATLAB 1.3 The MATLAB Environment 1.4 Using MATLAB as a Scratchpad 1.5 Summary

  14. Introduction The five parts of MATLAB Development Environment:This is the set of tools and facilities that help you use MATLAB functions and files. The MATLAB Mathematical Function Library. MATLAB Language Graphics: MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. The MATLAB Application Program Interface (API): This is a library that allows you to write C and Fortran programs that interact with MATLAB.

  15. The course makes no attempt to introduce you to all of MATLAB’s functions. Instead, you learn the basics of how to write, debug, and optimize good MATLAB programs with a subset of the most important functions. Introduction • MATLAB----short for MATrix LABoratory • A Huge Program • More than 1000 functions in basic MATLAB Compared: C language----about 300 Fortran-77----about 50 • Various Toolkits Example: Communication Toolbox, Filter Design Toolbox, Image Processing Toolbox… Note:

  16. 1984年,MATLAB第1版(DOS版) 1993年,MATLAB4.0版1994年,MATLAB 4.2版1997年,MATLAB 5.0版1999年,MATLAB 5.3版2000年,MATLAB 6.0版2001年,MATLAB 6.1版2002年,MATLAB 6.5版2004年,MATLAB 7.0版

  17. 1.1 The Advantages of MATLAB • Ease of use • Platform independence • Predefined functions • Device-Independent Plotting • Graphical User Interface • MATLAB Compiler

  18. 1.2 Disadvantages of MATLAB • Can be slow • Reason----MATLAB is an interpreted language • Resolvent----Compile the program before • distribution • Expensive • 5 to 10 times more expensive than C compiler • Cost-effective for businesses

  19. 1.3 MATLAB Environment • Fundamental unit of data----array • MATLAB Desktop • Command Window • Figure Windows • Edit/Debug Window • Command History Window • Launch Pad • Workspace Browser and Array Editor • Help Browser • Current Directory Browser

  20. To view or change the current directory 1.3.1 MATLAB Desktop Command Window Help Browser Workspace Browser Current Directory Browser Command History Window

  21. 1.3.1 MATLAB Desktop Launch Pad

  22. 1.3.2 The Command Window • The command prompt(>>) • Example: Calculate the area of a circle with a radius of 2.5m area = pi * 2.5^2 • π is predefined ,use pi without first declaring • Ellipsis(…),continuing on the next line x1=1+1/2+1/3+1/4… +1/5+1/6; x1=1+1/2+1/3+1/4+1/5+1/6;

  23. 1.3.2 The Command Window • Script file • Combined with a series of commands • Executed by typing file-name in the Command Window • Also known as M-files

  24. 1.3.3 The Command History Window Re-execute----double click with the left mouse button Delete----as shown in upper figure

  25. 1.3.4 The Launch Pad

  26. 1.3.5 The Edit/Debug Window • Create new M-files • “File/New/M-file” • Clicking the Toolbar icon • Open an existing one • “File/Open ” • Clicking the Toolbar icon

  27. 1.3.5 The Edit/Debug Window

  28. 1.3.6 Figure Windows

  29. 1.3.7 The MATLAB Workspace • Workspace----A collection of all the variables and arrays • Some useful commands: • >> whos List variables and arrays in current workspace • >>var1 Determine the content of any variable and array • >>clear var1 var2 … Delete var1 and var2. Simply “clear” deletes all variables

  30. 1.3.8 The Workspace Browser

  31. 1.3.9 Getting Help • Use the Help Browser • Selecting the Help icon • Typinghelpdeskorhelpwinin the Command window

  32. 1.3.9 Getting Help • Command-line oriented way to get help • Type helporhelp fun1in the command window • Search for an exact function name match • Typelookfor command • Search the quick summary information in each function for a match For example: Suppose that you were looking for a function to take the reverse of a matrix. You think that the function name may be “inverse”.

  33. 1.3.10 A Few Important Commands • Typedemoor select “demos” in the Launch Pad • clc----clear the contents of Command Window • clf----clear the contents of Figure Window • clear----clear the variables in the Workspace • ^c (control-c)----abort • !----Invoke operating system command • diary----echo a copy of all input and most output typed in the Command Window to the diary file (diary filename, diary off ,diary on)

  34. 1.3.11 The MATLAB Search Path • Search Path----Be used to find M-files • Enter a name at the MATLAB prompt • Look for the name as a variable • Check to see if it is a built-in function or command • Check to see if it is an M-file in the current directory • Check to see if it is an M-file in any directory in the search path

  35. 1.3.11 The MATLAB Search Path • Programming Pitfalls • Never use a variable with the same name as a MATLAB function or command • Never create an M-file with the same name as a MATLAB function or command • Examine and modify search path • “File/Set Path”, Path Tool,editpath • path command

  36. 1.4 Using MATLAB as a Scratchpad • Using the symbols +,-,*,/,^ • For example Calculate the volume of a cylinder of radius r and length l. >> r=0.1; >> l=0.5; >> V=A*l; >> A=pi*r^2; >> V=A*l V = 0.0157

  37. 1.5 Summary 1.1 The Advantages of MATLAB 1.2 Disadvantages of MATLAB 1.3 The MATLAB Environment 1.4 Using MATLAB as a Scratchpad

  38. Homework • Quiz(P18) 1~8 • Exercises(P19) 1~8

More Related