
Lecture 3
Lecture 3
Creating
Creating M-files
M-files
Programming tools:
Programming tools:
Input/output
Input/output
(assign/graph-&-display)
(assign/graph-&-display)
Repetition (for)
Repetition (for)
Decision (if)
Decision (if)
© 2007 Daniel Valentine. All rights reserved. Published by
Elsevier.

Review
Review
Arrays
Arrays
–List of numbers in brackets
List of numbers in brackets
A comma or space separates numbers (columns)
A comma or space separates numbers (columns)
A semicolon separates row
A semicolon separates row
–Zeros and ones Matrices:
Zeros and ones Matrices:
zeros()
zeros()
ones()
ones()
–Indexing
Indexing
(row,column)
(row,column)
–Colon Operator:
Colon Operator:
Range of Data first:last or first:increment:last
Range of Data first:last or first:increment:last
–Manipulating Arrays & Matrices
Manipulating Arrays & Matrices
Transpose
Transpose

Input
Input
Examples of input to arrays:
Examples of input to arrays:
–Single number array & scalar: 1 × 1
Single number array & scalar: 1 × 1
>>
>> a = 2
a = 2
–Row array & row vector:
Row array & row vector: 1 × n
1 × n
>>
>> b = [1 3 2 5]
b = [1 3 2 5]
–Column array & column vector: n x 1
Column array & column vector: n x 1
>>
>> b = b’
b = b’ % This an application of the transpose.
% This an application of the transpose.
–Array of n rows x m columns & Matrix: n × m
Array of n rows x m columns & Matrix: n × m
>>
>> c = [1 2 3; 4 5 6; 7 6 9]
c = [1 2 3; 4 5 6; 7 6 9] % This example is 3 x 3.
% This example is 3 x 3.

Basic elements of a program
Basic elements of a program
Input
Input
–Initialize, define or assign numerical values to
Initialize, define or assign numerical values to
variables.
variables.
Set of command expressions
Set of command expressions
–Operations applied to input variables that lead
Operations applied to input variables that lead
to the desired result.
to the desired result.
Output
Output
–Display (graphically or numerically) result.
Display (graphically or numerically) result.

An example of technical computing
An example of technical computing
Let us consider using the hyperbolic tangent
Let us consider using the hyperbolic tangent
to model a down-hill section of a snowboard
to model a down-hill section of a snowboard
or snow ski facility.
or snow ski facility.
Let us first examine the hyperbolic tangent
Let us first examine the hyperbolic tangent
function by executing the command:
function by executing the command:
>>
>> ezplot(
ezplot( ‘tanh(x)’
‘tanh(x)’ )
)
We get the following graph:
We get the following graph: