Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

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

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

3 Book S. 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 求方程 3x 4 +7x 3 +9x 2 -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 1Introduction to MATLAB 2MATLAB Basics 3Branching Statements and Program Design 4Loops 5User-Defined Functions 6Complex Data, Character Data, and Additional Plot Types 7Sparse Arrays, Cell Arrays, and Structures 8Input/Output Functions 9Handle Graphics 10Graphical User Interfaces

13 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 Chapter 1 Introduction to MATLAB

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 Introduction MATLAB----short for MATrix LABoratory A Huge Program Note:  More than 1000 functions in basic MATLAB Compared: C language----about 300 Fortran-77----about 50 Compared: C language----about 300 Fortran-77----about 50  Various Toolkits Example: Communication Toolbox, Filter Design Toolbox, Image Processing Toolbox… 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.

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 1.3.1 MATLAB Desktop Workspace Browser Command Window Current Directory Browser Command History Window To view or change the current directory Help Browser

21 Launch Pad 1.3.1 MATLAB Desktop

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

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

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

25 1.3.4 The Launch Pad

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

27

28 1.3.6 Figure Windows

29 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 1.3.7 The MATLAB Workspace

30 1.3.8 The Workspace Browser

31 Use the Help Browser –Selecting the Help icon –Typing helpdesk or helpwin in the Command window 1.3.9 Getting Help

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

33

34 Type demo or 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) 1.3.10 A Few Important Commands

35 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 1.3.11 The MATLAB Search Path

36 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 1.3.11 The MATLAB Search Path

37 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 1.4 Using MATLAB as a Scratchpad

38 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

39 Quiz(P18) 1~8 Exercises(P19) 1~8 Homework


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

Similar presentations


Ads by Google