Get 1 week of unlimited access
Class Notes (1,035,018)
US (406,439)
U of M (6,985)
ENGR (63)
Lecture 1

# ENGR 101 Lecture Notes - Lecture 1: Standard Deviation, Normal Distribution

5 pages33 viewsFall 2017

Department
Engineering
Course Code
ENGR 101
Professor
Jeffrey Ringenberg
Lecture
1

This preview shows page 1. to view the full 5 pages of the document.
'whos'&lists%in%alphabetical%order%the%names,%sizes,%and%types%of%all%the%variables%
in%the%workspace.%
'char'&(character)&refers%to%the%letters,%single%quotes%('')%
Strings refer%to%words%("")%
ones(m,n)%creates%a%m%*%n%matrix%of%zeroes%
ones(m)%same,%but%uses%m%for%both%rows%and%columns%
Each%column%sum%=%each%row%sum%=%each%diagonal%sum%
o
Creates%a%new%matrix%based%on%repeating%matrix%A%a%certain%number%of%times%in%
the%x%and%y%direction
o
repmat(A,%xTimes,%yTimes)%
Creates%a%new%matrix%with%the%same%elements%as%A,%but%the%requested%number%
of%rows%and%columns.%The%dimension%must%match%with%the%original%number%of%
elements%in%A.%
o
reshape(A,%numRows,%numCols)%
Numel(x)%yields%the%#%of%elements%in%x%
Length(x)%yields%the%number%of%elements%along%the%longest%dimension%of%x%
Size(x)%yields%a%vector%with%the%#%of%elements%along%each%dimension%of%x%
"Array%operations"%work%with%array%element-by-element
Vector%indexing
o
Code%duplication%occurs%when%you%have%more%than%one%of%code%that%does%the%same%
thing
what's%inside.%
Is%an%algorithm%that%returns%data%to%the%caller,%and%operates%independently%of%
the%caller.%
o
Ex.%sqrt%function.%
o
The%interface%of%a%functions%describes%how%we%use%it
o
Functions&
Ex.%sum%function%
o
Many%work%column%by%column:%
o
Functions%with%matrices:
Name%-what%is%the%function%called?
§
Parameters%-variables%used%to%pass%dat%into%the%function%as%input
§
Return%variables%-a%list%of%variables%whose%values%will%be%returned%
back%to%the%outside%word%as%the%output%of%a%fucntion
§
Defines%how%we%interact%with%the%funciton%
An interface that%specifies%how%it%must%be%used%by%other%code
o
A%function%call%takes%in%arguments%that%correspond%to%the%parameters%of%the%
function
o
The%arguments%could%be%expressions,%they%do%not%have%variables
o
We%write%code%that%uses%the%parameters%to%calculate%
An implementation with%code%that%makes%it%work%behind%the%scenes
o
Every%function%has%two%major%pieces:
Code%is%vectorized%if%it%can%work%with%vectors%of%data%just%as%well%as%scalars
It%uses%a%compound%return%to%give%us%both%a%sorted%version%of%the%vector%and%a%
vector%of%sorted%indices.%
o
Write%"ascend"%or%"descend"
o
The%sort&function&works%with%column%vectors
Ex.%
K%=%find(X)%-returns%the%indices%of%the%array%x%that%point%to%nonzero%elements.%If%
non%is%found,%find%returns%an%empty%matrix.%
o
The%find&function&converts%a%logical%index%matrix%into%a%regular%index%matrix.%
A = [1,0,4,5,0; 0,3,1,2,0; 3,0,2,0,0; 1,5,3,3,5];
y = find(A)
(it%displayed:)
y%=
%%%%%1
%%%%%3
%%%%%4
%%%%%6
%%%%%8
%%%%%9
%%%%10
%%%%11
%%%%12
%%%%13
%%%%14
%%%%16
%%%%20
The%all&function&returns%true%if%ALL%elements%of%an%array%are%true.%If%even%one%element%
is%false,%it%returns%false.%
Will%produce%a%matrix%of%that%size%containing%random%samples
o
Randn()%function%samples%from%a%standard%normal%distribution%(mean%=%0%and%stddev%=%
1)
Returns%average%value%of%a%data%set
o
Mean&
Returns%the%median%value%of%the%data%set;%the%median%is%the%middle%value%of%the%
dataset.%It%is%used%because%the%media%is%more%resistant%to%outliners%than%the%
mean%of%the%same%dataset.%
o
Median&
A%metric%to%measure%the%variation%of%the%normal%distribution%of%the%data%set.%
o
Standard&deviation&
Another%metric%to%measure%the%variation%of%the%normal%distribution%of%a%data%
set.%Also,%the%variance%of%any%distribution%is%equal%to%the%square%of%the%standard%
deviation.
o
Variance&
Will%sort%a%group%of%numbers%in%a%matrix%X.%The%second%parameter%'direction'%is%
either%'ascend'%or%'descend'.%
o
Sort(x,&'direction')&
The%randperm&function&scrambles%numbers%in%the%vector%
They%should%be%called%from%scripts,%the%command%window,%or%other%functions.%
Functions%run%a%group%of%commands%with%a%given%input.%
The%numel()&function%returns%the%number%of%elements,%n,%in%array%A,%equivalent%to%
prod(size(A));%
Functions
Wednesday,% September% 27,%2017
9:48%AM

Unlock to view full version

Only half of the first page are available for preview. Some parts have been intentionally blurred.

'whos'&lists%in%alphabetical%order%the%names,%sizes,%and%types%of%all%the%variables%
in%the%workspace.%
'char'&(character)&refers%to%the%letters,%single%quotes%('')%
Strings refer%to%words%("")%
ones(m,n)%creates%a%m%*%n%matrix%of%zeroes%
ones(m)%same,%but%uses%m%for%both%rows%and%columns%
Each%column%sum%=%each%row%sum%=%each%diagonal%sum%
o
magic(s)%creates%an%s%x%s%"magic"%matrix
Creates%a%new%matrix%based%on%repeating%matrix%A%a%certain%number%of%times%in%
the%x%and%y%direction
o
repmat(A,%xTimes,%yTimes)%
Creates%a%new%matrix%with%the%same%elements%as%A,%but%the%requested%number%
of%rows%and%columns.%The%dimension%must%match%with%the%original%number%of%
elements%in%A.%
o
reshape(A,%numRows,%numCols)%
Numel(x)%yields%the%#%of%elements%in%x%
Length(x)%yields%the%number%of%elements%along%the%longest%dimension%of%x%
Size(x)%yields%a%vector%with%the%#%of%elements%along%each%dimension%of%x%
"Array%operations"%work%with%array%element-by-element
Vector%indexing
o
Code%duplication%occurs%when%you%have%more%than%one%of%code%that%does%the%same%
thing
what's%inside.%
Is%an%algorithm%that%returns%data%to%the%caller,%and%operates%independently%of%
the%caller.%
o
Ex.%sqrt%function.%
o
The%interface%of%a%functions%describes%how%we%use%it
o
Functions&
Ex.%sum%function%
o
Many%work%column%by%column:%
o
Functions%with%matrices:
Name%-what%is%the%function%called?
§
Parameters%-variables%used%to%pass%dat%into%the%function%as%input
§
Return%variables%-a%list%of%variables%whose%values%will%be%returned%
back%to%the%outside%word%as%the%output%of%a%fucntion
§
Defines%how%we%interact%with%the%funciton%
An interface that%specifies%how%it%must%be%used%by%other%code
o
A%function%call%takes%in%arguments%that%correspond%to%the%parameters%of%the%
function
o
The%arguments%could%be%expressions,%they%do%not%have%variables
o
We%write%code%that%uses%the%parameters%to%calculate%
An implementation with%code%that%makes%it%work%behind%the%scenes
o
Every%function%has%two%major%pieces:
Code%is%vectorized%if%it%can%work%with%vectors%of%data%just%as%well%as%scalars
It%uses%a%compound%return%to%give%us%both%a%sorted%version%of%the%vector%and%a%
vector%of%sorted%indices.%
o
Write%"ascend"%or%"descend"
o
The%sort&function&works%with%column%vectors
Ex.%
K%=%find(X)%-returns%the%indices%of%the%array%x%that%point%to%nonzero%elements.%If%
non%is%found,%find%returns%an%empty%matrix.%
o
The%find&function&converts%a%logical%index%matrix%into%a%regular%index%matrix.%
A = [1,0,4,5,0; 0,3,1,2,0; 3,0,2,0,0; 1,5,3,3,5];
y = find(A)
(it%displayed:)
y%=
%%%%%1
%%%%%3
%%%%%4
%%%%%6
%%%%%8
%%%%%9
%%%%10
%%%%11
%%%%12
%%%%13
%%%%14
%%%%16
%%%%20
The%all&function&returns%true%if%ALL%elements%of%an%array%are%true.%If%even%one%element%
is%false,%it%returns%false.%
Will%produce%a%matrix%of%that%size%containing%random%samples
o
Randn()%function%samples%from%a%standard%normal%distribution%(mean%=%0%and%stddev%=%
1)
Returns%average%value%of%a%data%set
o
Mean&
Returns%the%median%value%of%the%data%set;%the%median%is%the%middle%value%of%the%
dataset.%It%is%used%because%the%media%is%more%resistant%to%outliners%than%the%
mean%of%the%same%dataset.%
o
Median&
A%metric%to%measure%the%variation%of%the%normal%distribution%of%the%data%set.%
o
Standard&deviation&
Another%metric%to%measure%the%variation%of%the%normal%distribution%of%a%data%
set.%Also,%the%variance%of%any%distribution%is%equal%to%the%square%of%the%standard%
deviation.
o
Variance&
Will%sort%a%group%of%numbers%in%a%matrix%X.%The%second%parameter%'direction'%is%
either%'ascend'%or%'descend'.%
o
Sort(x,&'direction')&
The%randperm&function&scrambles%numbers%in%the%vector%
They%should%be%called%from%scripts,%the%command%window,%or%other%functions.%
Functions%run%a%group%of%commands%with%a%given%input.%
The%numel()&function%returns%the%number%of%elements,%n,%in%array%A,%equivalent%to%
prod(size(A));%
Functions
Wednesday,% September% 27,%2017 9:48%AM