Introduction to Matlab
Matlab is a computer application that simplifies many complex mathematical tasks.
The name Matlab stands for "matrix laboratory".
Matlab has many functions and "Toolboxes" to help in various applications.
(It is suggested that the student follow along by opening a Matlab window while going through this tutorial.)
For NIU CEET Matlab is found on most computers in the Engineering Computer Laboratory. Clicking on the Matlab icon will open Matlab and give an initial prompt.
Initial Matlab prompt:
Values for variables can be entered directly with the keyboard. Variables could include scalars, vectors, or matrices
Scalars - type variable name, equals, and value
a = 2.0
Typing the variable name will give its value
A result of 2.0 should be displayed.
Vectors - elements of array are in square brackets separated by comas
Note: Matab distinguishes between upper and lower case letters!
Matrix - rows of an matrix are separated by semicolons or line breaks
C = [10,11,12; 20,21,22
Equations - use standard symbols and notation
Transpose - use prime ' (apostrophe) to transpose a vector or matrix
Typing a semicolon (;) at the end of the line keeps echo from appearing
Laplace Transfer Functions
Polynomials represented as arrays
4s3+3s2+2s+1 (polynomial expression)
Y=[4,3,2,1] (Matlab representation)
Transfer function - ratio of polynomials of same order
X=[0,30,20,10] (Matlab representation of numerator)
Can enter a transfer function using tf command
Example type :
Note: Transfer functions can also be entered using different forms.
Matlab has many analysis functions already available.
Useful functions for beginners are step and bode
Step response (response to unit step input)
Bode - generates a bode plot of the transfer function
Note: Each of these functions can be entered using different forms
Often want to repeat same operation
Can enter commands in text file with ".m" suffix
Typing file name will execute the commands
(file must be in Matlab path)
Try creating an M file. In File menu choose New; M-file
In text editor window type:
Save file as mystep.m
In Matlab window type:
A step response should appear.
You can save the data you generated in a binary ".mat" file.
This can be done using the save command
Form: save filename
This will save all variables in the workspace in file "filename.mat"
Specific variables only can be saved by typing the variable names after the filename.
Saved data can be retrieved using the load command
Form: load filename
Try saving your data, quitting Matlab, restarting Matlab, and reloading your data.
Matlab has built in help command: Gives help on specific functions
Form: help name
Example 1: help bode (help on using bode plots)
Example 2: help help (help on using help command)
Other sources for help
From MathWorks (Creators of Matlab)
From Mathtools,a general technical computing portal with many Matlab links