Aerospace Practicum

Introduction to MATLAB Lecture #1

Based on Chapter 15 of Engineering Fundamentals: An Introduction to Engineering

By: Saeed Moaveni © 2005 Nelson

Students provided with a copy of Chapter 15

0: Comments on Blackboard and Homework Submission

Laboratory homework assignment #1 due by 11am on Friday, January 18, 2013

1: Basic Ideas

Open/Launch MATLAB

Menu Bar

Current Directory

Launch Pad Window

Command Window

Command History Window

Moving window outside desktop and returning to default view

Show how to type some basic commands

x=5

y=2

x+y

2*x+3*x/y

z=3*y^2

use up arrow to retrieve commands or select and drag from command history window

clc: clears contents of the command window, but does not erase variables that are in current memory

clear: erases all variables from current memory

Generating a range of values

x=0:25:100

x=0:5:100

countdown=5:-1:0

Matrix Operations

Go to Example 15.4

  • Show examples of matrix addition ([A]+[B]=[B]+[A]), multiplication ([A][B]≠[B][A]), transpose and how to find the determinant

Go to Example 15.5

  • Briefly discuss how matrices may be used to solve a series of linear equations
  • How to find the transpose and inverse of a matrix by hand.
  • Emphasize how time consuming this is by hand and how quickly MATLAB can do it.

Element by element operation

  • Briefly discuss how multiplication of two matrices differs in the element by element method. [A][B]=[B][A] in the element by element method.
  • Emphasize that when using ‘.’, not matrix operation anymore.

format: allows you to display values in certain ways

disp: used to display text or values. Rarely used, often you can just type in the variable name, but disp will leave off the name.

fprintf: also a display command that allows you to print text and/or values with a desired number of digits. \n and \t are line breaks and tabs, respectively

Example 15.1

Comment on %g and other forms that may be used

Using help

How to launch help

Begin Here (if extra time, have students explore here)

Getting Started with MATLAB

Lists of MATLAB functions

MATLAB Demos (if extra time, have students explore here)

Quick reference help: type ‘help’ followed by any command. Very useful.

help format

help fprintf

Example 14.1

Make sure that students save this file, because the results will be used to practice plotting later.

SKIP EXAMPLE 14.2

saving the workspace

directory location

opening and working in a MATLAB script or m-file window

2: Using MATLAB Functions (Page 409)

Emphasize that MATLAB contains a very large selection of functions and that they can be found in the help browser (which also has a .pdf file of all the functions).

Example 15.2

Fortrigonometric functions in Tables 15.7 and 15.8 be sure to emphasize that the argument must be in radians and show how to convert to degrees (perhaps first give the students a chance to try to figure it out if you are doing well on time).

Example 14.4

Logical Operators Table 15.10

Example 14.5 (if time is going well)

3. Plotting with MATLAB

Example 15.3

Demonstrate that this can also be solved with elementary calculus, but emphasize how quickly it can be done with MATLAB also, and that more complicated problems that do not lend themselves to straightforward mathematical analysis are often solved in MATLAB in a similar fashion. Give them some time to follow through this section and see how far they can get on the line and plot style options.

help plot is always useful if you forget the syntax

Example 14.6

This example uses data they should have saved earlier in the session

SKIP 15.4, but mention that MATLAB and EXCEL are compatible and data can be transferred readily between the two. Mention that Section 15.4 is there for them if they need it for future reference.

If you get through all of this give them some time to explore MATLAB on their own and investigate the help browser that is available. If demos are available, have them spend some time going through the demos.

1