Presentation is loading. Please wait.

Presentation is loading. Please wait.

EECE 360/460 Matlab Tutorial Jan 2011. Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs.

Similar presentations


Presentation on theme: "EECE 360/460 Matlab Tutorial Jan 2011. Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs."— Presentation transcript:

1 EECE 360/460 Matlab Tutorial Jan 2011

2 Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs Plotting Graphs Control System Toolbox Control System Toolbox Examples Examples Useful Resources Useful Resources

3 Overview of Matlab

4 What is Matlab? Language for technical computing Language for technical computing Supports mathematical computation, visualization, and programming Supports mathematical computation, visualization, and programming Composed using high-level programming language Composed using high-level programming language similar to syntax of C similar to syntax of C For EECE 360 For EECE 360 Use Matlab in the assignments Use Matlab in the assignments

5 Matlab Interface

6 Command Window Workspace Command History Change the current directory to the location of your Matlab file at startup

7 Matlab Programming Two Approaches Two Approaches Coding in Command Window Coding in Command Window Good for short programs Good for short programs Commands must be re-entered each time you run a simulation Commands must be re-entered each time you run a simulation Coding with.m-files Coding with.m-files Good for long programs Good for long programs Allows users to save all the commands written in the.m-files Allows users to save all the commands written in the.m-files

8 Command Window Interface Write your commands here

9 (1) Creating.m-files File  New  M- File (2) Opening.m-files File  Open  select the.m-file

10 .m-file Interface Write your commands here To run the program, press F5

11 Workspace Interface The workspace provides a summary of the variables The workspace provides a summary of the variables

12 Command History Interface The Command History stores all the commands entered in the Command Window previously The Command History stores all the commands entered in the Command Window previously No history of.m-files is shown here No history of.m-files is shown here

13 Syntax Errors All errors are given in the Command Window in red All errors are given in the Command Window in red Nature of error is explained Nature of error is explained

14 Examples on Matlab Interface

15 Basic Syntax

16 Assignment of Variables Assignment of Variables Syntax: Variable = Expression Syntax: Variable = Expression Example: A = 1; Example: A = 1; Use of semi-colons Use of semi-colons With semi-colon – suppress output With semi-colon – suppress output Without semi-colon – displays output in command window Without semi-colon – displays output in command window Adding comments Adding comments Add % before command line Add % before command line Example: % This is a demo Example: % This is a demo

17 Basic Syntax (cont’d) Step increment Step increment Example: k = 1:0.1:10 Example: k = 1:0.1:10 k is a row-matrix from 1 to 10 with step size = 0.1 k is a row-matrix from 1 to 10 with step size = 0.1 Matrix Expression Matrix Expression Hence, for a 2x2 matrix, the syntax is Hence, for a 2x2 matrix, the syntax is A = [1 2; 3 4] A = [1 2; 3 4] Row-matrixColumn-matrix

18 Basic Syntax (cont’d) Mathematical (Array) Operators Mathematical (Array) Operators Note the dimension of matrix in matrix computation Note the dimension of matrix in matrix computation Example: A: 2x1 matrix, B: 2x2 matrix Example: A: 2x1 matrix, B: 2x2 matrix A*B  invalid operation B*A  valid operation +Addition -Subtraction *Multiplication /Division ^Power Mathematical+Addition-Subtraction.*Multiplication./Division.^Power Mathematical Array

19 Basic Syntax (cont’d) Common Built-in Math Functions Common Built-in Math Functions sin(x) - sine sin(x) - sine cos(x) - cosine cos(x) - cosine tan(x) - tangent tan(x) - tangent exp(x) - exponential exp(x) - exponential log10(x) – base10 logarithm log10(x) – base10 logarithm sqrt(x) – square root sqrt(x) – square root abs(x) – absolute value abs(x) – absolute value The complete list can be found on pp. 833 of text The complete list can be found on pp. 833 of text

20 Examples on Basic Syntax

21 Plotting Graphs

22 Matlab allows graphical displays Matlab allows graphical displays By using the command plot By using the command plot Syntax: plot(x) Syntax: plot(x) Types of plots Types of plots Syntax: plot(x,’-’) Syntax: plot(x,’-’) - Solid line -- Dashed line : Dotted line -. Dashdot line

23 Plotting Graphs (cont’d) Labeling Graphs Labeling Graphs Commonly used Syntax: Commonly used Syntax: ylabel(‘text’) – label y-axis ylabel(‘text’) – label y-axis xlabel(‘text’) – label x-axis xlabel(‘text’) – label x-axis title(‘text’) – label title title(‘text’) – label title legend(‘legend1’, ‘length2’,…) – puts legend on current plot legend(‘legend1’, ‘length2’,…) – puts legend on current plot grid on (grid off) – add (remove) grid lines to figure grid on (grid off) – add (remove) grid lines to figure subplot – subdivides graphic window subplot – subdivides graphic window hold on – hold the previous plot on the graphic window hold on – hold the previous plot on the graphic window

24 Example (1)

25

26 Example (2) subplot(2,2,1) plot(x,’r’),hold on plot(y,’--’) subplot(2,2,2) plot(x,’r’),hold on plot(y,’--’) subplot(2,2,3) plot(x,’r’),hold on plot(y,’--’) subplot(2,2,4) plot(x,’r’),hold on plot(y,’--’)

27 Examples on Plotting Graphs

28 Control System Toolbox

29 Overview to the Toolbox Modeled control systems as Modeled control systems as (1) transfer functions (2) zero-pole-gain (3) state-space form Can manipulate both Can manipulate both (1) continuous-time system (2) discrete-time system Can compute and graph Can compute and graph (1) time response (2) frequency response

30 Demo (1) Transfer Function Transfer Function Syntax: tf(numerator, denomintor) Syntax: tf(numerator, denomintor)

31 Demo (2) State-space Representation State-space Representation Syntax: sys_ss = ss(sys) Syntax: sys_ss = ss(sys)

32 Demo (3) Finding Poles and Zeros Finding Poles and Zeros Syntax: z = zero(sys) Syntax: z = zero(sys) p = pole(sys) p = pole(sys) Pole-Zero Diagram Pole-Zero Diagram Syntax: zplane(z,p) Syntax: zplane(z,p)

33

34 Demo (4) Closed-Loop System Closed-Loop System Syntax: CLsys = feedback(sys1,sys2) Syntax: CLsys = feedback(sys1,sys2) System 1 System 2 + -

35 Demo (5) Step Response Step Response Syntax: step(sys) Syntax: step(sys)

36

37 Demo (6) Pole-zero cancellation Pole-zero cancellation Syntax: sysr = minreal(sys); Syntax: sysr = minreal(sys); Impulse Response Impulse Response Syntax: impulse(sys) Syntax: impulse(sys)

38

39 Examples on Control System Toolbox

40 Useful Resources Appendix A of Textbook Appendix A of Textbook End of Chapter – Matlab Demo End of Chapter – Matlab Demo http://www.mathworks.com http://www.mathworks.com


Download ppt "EECE 360/460 Matlab Tutorial Jan 2011. Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs."

Similar presentations


Ads by Google