Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

MATLAB REVIEW/TUTORIAL

Chemical Reaction Engineering CBE 40445


Aug 29

Matlab Basics

What does Matlab stand for? Access


Can

access Matlab from both UNIX and PCs in ND clusters Can buy student version from OIT Applications Requested & Approved for Fall 2008
MATLAB

7.6

Can

use Matlab compatible program (i.e. octave http://www.gnu.org/software/octave/ )

Matlab Basics

Things you should remember


Matlab

command window Command line (>>) Can execute commands directly from command line >> a = [ 1 2 ; 2 1 ] 1 2 a 2 1
Perform

arithmatic, trigonometric, and exponential operations

Can

execute program files

Matlab Basics

5 arithmetic operators ( + , - , * , / , ^ ) Elementary Matlab functions


exp(x),

sqrt (x), log(x), log10(x), abs(x)

Trigonometric functions
sin(x),

cos(x), tan(x), etc.

Go through example commands in Matlab

Matlab Basics - Programs

Important things to remember


Variable names are cAse seNSitiVe All variables are stored until program exits or clear function is used Format of numerical value output can be changed with format command

Format short long Format short e/f/g

Scientific notation, floating point, or whichever makes more sense

Semi-colons suppress system response

You can change Matlabs default formats if you want

Matlab Basics - Programs

Why do we write programs?


When

you need more than one line of code When program will be used again When a permanent record is desired When occasional upgrading will be required When substantial debugging will be required When you want or need to transfer to another person (a.k.a to your teacher!)

Structured Programming

Refers to the organization and format of a program Organization: how do we complete a task?
Input:

read values from a source Process: calculate/manipulate numbers Decide: choose a path based on a requirement Output: present result(s)

Matlab Basics - Programs

What to include on your program


Purpose Name

Date

originated Date revised Description of input/output: number, meaning, type, etc. Descriptive comments throughout!

Description Example
%******************************************************* % Purpose: MATLAB Tutorial % Name: Dr. Jes Anderson % Date originated: Aug. 18, 2008 % Date revised: Aug. 29, 2008 % Description: Remind students of basic matlab operations % and programming skills % %*******************************************************

Matlab Basics - Programming


Example 1 Program basics Example 2 Vector and matrices review Example 3 Creating graphs Example 4 Functions Example 5 Systems of Equations Example 6 Integrals and ODEs

Example 1: Program Basics


Go to Matlab Important skills


Start Stop Help Clear

Example 2: Vectors and Matrices


Go to m.file Important skills


Transpose Perform

operations on matrices/vectors Perform operations on elements of matrices/vectors (dot operations)


Must

be performed on matrices of same order

Find

size, diagonal, change elements of matrices/vectors

Example 3: Plotting

Go to Matlab Important skills


Plot

in both 2D and 3D Apply axis labels, titles, legends Change output colors/shapes/etc. Make new figures or subplots within figures **Be able to communicate your data to others!!!

Creating Graphs Misc.

Some more plot customization commands to type before plot() or plot3() figure(n) opens a new figure window subplot(m,n,p) divides a single figure window into an m x n grid and puts your next command in the pth spot grid on/off displays a grid hold on/off superimposes plots

You might also like