eece 360/460 matlab tutorial jan 2011. outline what is matlab? what is matlab? matlab interface...

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

Post on 31-Dec-2015

216 views

Category:

Documents

2 download

Embed Size (px)

TRANSCRIPT

  • EECE 360/460 Matlab TutorialJan 2011

  • OutlineWhat is Matlab?Matlab InterfaceBasic SyntaxPlotting Graphs Control System ToolboxExamplesUseful Resources

  • Overview of Matlab

  • What is Matlab?Language for technical computingSupports mathematical computation, visualization, and programmingComposed using high-level programming language similar to syntax of C

    For EECE 360 Use Matlab in the assignments

  • Matlab Interface

  • Command Window

    Workspace

    CommandHistoryChange the current directory to the location of your Matlab file at startup

  • Matlab ProgrammingTwo ApproachesCoding in Command WindowGood for short programsCommands must be re-entered each time you run a simulation

    Coding with .m-filesGood for long programsAllows users to save all the commands written in the .m-files

  • Command Window InterfaceWrite your commands here

  • (1) Creating .m-files

    File New M-File

    (2) Opening .m-filesFile Open select the .m-file

  • .m-file InterfaceWrite your commands hereTo run the program, press F5

  • Workspace InterfaceThe workspace provides a summary of the variables

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

  • Syntax ErrorsAll errors are given in the Command Window in redNature of error is explained

  • Examples on Matlab Interface

  • Basic Syntax

  • Basic SyntaxAssignment of VariablesSyntax: Variable = ExpressionExample: A = 1; Use of semi-colonsWith semi-colon suppress outputWithout semi-colon displays output in command windowAdding commentsAdd % before command lineExample: % This is a demo

  • Basic Syntax (contd)Step incrementExample: k = 1:0.1:10k is a row-matrix from 1 to 10 with step size = 0.1Matrix Expression

    Hence, for a 2x2 matrix, the syntax isA = [1 2; 3 4]

    Row-matrixColumn-matrix

  • Basic Syntax (contd)Mathematical (Array) Operators

    Note the dimension of matrix in matrix computationExample: A: 2x1 matrix, B: 2x2 matrixA*B invalid operationB*A valid operationMathematicalMathematical Array

    +Addition-Subtraction*Multiplication/Division^Power

    +Addition-Subtraction.*Multiplication./Division.^Power

  • Basic Syntax (contd)Common Built-in Math Functionssin(x) - sinecos(x) - cosinetan(x) - tangentexp(x) - exponentiallog10(x) base10 logarithmsqrt(x) square rootabs(x) absolute value

    The complete list can be found on pp. 833 of text

  • Examples on Basic Syntax

  • Plotting Graphs

  • Plotting GraphsMatlab allows graphical displays By using the command plotSyntax: plot(x)

    Types of plots

    Syntax: plot(x,-)

    -Solid line--Dashed line:Dotted line-.Dashdot line

  • Plotting Graphs (contd)Labeling GraphsCommonly used Syntax:ylabel(text) label y-axisxlabel(text) label x-axistitle(text) label titlelegend(legend1, length2,) puts legend on current plotgrid on (grid off) add (remove) grid lines to figuresubplot subdivides graphic windowhold on hold the previous plot on the graphic window

  • Example (1)

  • Example (2) subplot(2,2,1)plot(x,r),hold onplot(y,--)subplot(2,2,2)plot(x,r),hold onplot(y,--)subplot(2,2,3)plot(x,r),hold onplot(y,--)subplot(2,2,4)plot(x,r),hold onplot(y,--)

  • Examples onPlotting Graphs

  • Control System Toolbox

  • Overview to the ToolboxModeled control systems as(1) transfer functions (2) zero-pole-gain (3) state-space formCan manipulate both (1) continuous-time system(2) discrete-time systemCan compute and graph(1) time response (2) frequency response

  • Demo (1)Transfer FunctionSyntax: tf(numerator, denomintor)

  • Demo (2)State-space RepresentationSyntax: sys_ss = ss(sys)

  • Demo (3)Finding Poles and ZerosSyntax: z = zero(sys) p = pole(sys)

    Pole-Zero DiagramSyntax: zplane(z,p)

  • Demo (4)Closed-Loop SystemSyntax: CLsys = feedback(sys1,sys2)

  • Demo (5) Step ResponseSyntax: step(sys)

  • Demo (6)Pole-zero cancellationSyntax: sysr = minreal(sys);Impulse ResponseSyntax: impulse(sys)

  • Examples onControl System Toolbox

  • Useful ResourcesAppendix A of Textbook

    End of Chapter Matlab Demo

    http://www.mathworks.com

    ******

View more >