ENGR 1181 | MATLAB 2: Introduction to MATLAB
Classroom Guide
ENGR 1181 |MATLAB 2: Introduction to MATLAB
Classroom Guide
Learning Objectives
- Demonstrate proper usage of basic MATLAB features including:
- The Command Window
- Script files
- Other default windows
- Arithmetic operations
- Assigning variables and names
- Built-in functions
- Help command
- Identify the need to translate mathematical notation into proper MATLAB syntax
Textbook Reading
Chapter 1
Topics
This class contains the following topics:
- Introduce the MATLAB interface
- Variables: naming rules & calculations
- Built-in Functions
- Script files and other commands
Outline
Below is an outline of the topics and the order in which they should be covered:
- What is MATLAB?
- MATLAB is a software for numerical computations, visualization, and programming.
- The name MATLAB stands for MATrix LABoratory. The basic data element used in MATLAB in an array (explained later).
- Open MATLAB and describe the display
- Ribbon – useful operations
- Current Directory – list of files
- Workspace – defined variable values
- Command history – displays what has been typed
- Command window – one location to enter commands
- Change the Working Directory
- Current working directory is where files are saved and run from.
- Good idea to change the working directory to the Z: drive when you first start MATLAB
- Show students how to open and save a script file (editor window)
- Save on your laptop or Z: drive
- Save your work as you go!
- Rules for naming script files
- No spaces
- The name cannot start with a numeric value
- No special characters allowed expect for underscore
- Show comments and sectioning
- Useful Programming Commands (Classroom Activity – MAT 02 Intro, Example 4)
- clc
- clear
- disp()
- semicolon (;) to suppress output
- Discuss order of precedence (Classroom Activity – Example 1)
- Rules for naming variablesand calculations with variables (Classroom Activity – Example 2)
- Cannot exceed 63 characters
- Must begin with a letter
- May contain letters, digits, and the underscore character
- No spaces allowed
- MATLAB is case sensitive
- Avoid naming variables with currently defined MATLAB functions (e.g. exp, sin, cos, sqrt, length, etc.)
- Mathematical sense vs. programming language
- Show MATLAB’s pre-defined math functions and how to use them in calculations (Classroom Activity – Example 3)
- Units for trigonometric functions
- sin(x) – radians
- sind(x) – degrees
- pi vs. pi() from Excel
- e^2 vs. exp(2)
- Explain how to save MATLAB script files and command windows as a PDF (print to PDF). Show how to combine PDF files into a single PDF.
- Students will complete Part 1 of the assignment to turn in by the end of class. Once finished, students may start on Part 2 due by the next class. Students will submit Part 1 of the assignment to the Carmen dropbox as a PDF.
1