MATLAB Tutorial 1-Machine Learning-Lecture Handout, Exercises of Machine Learning

This lecture notes was distributed for Machine Learning course by Pakistan Institute of Engineering and Applied Sciences, Islamabad (PIEAS). Its main points are: MATLAB, Matrices, Vectors, Variables, Subscript, Notation, Colon, Complex, Numbers, Strings, Polynomials

Typology: Exercises

2011/2012

Uploaded on 07/19/2012

zaraa
zaraa 🇵🇰

6 documents

1 / 110

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Dr. Hanif Durad 2
Lecture Outline (1/2)
Basic MATLAB Operations
Starting MATLAB
Using MATLAB as a calculator
Introduction to variables and functions
Matrices and Vectors: All variables are matrices.
Creating matrices and vectors
Subscript notation
Colon notation
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download MATLAB Tutorial 1-Machine Learning-Lecture Handout and more Exercises Machine Learning in PDF only on Docsity!

Dr. Hanif Durad

Lecture Outline (1/2)

^ Basic MATLAB Operations^ 

Starting MATLAB  Using MATLAB as a calculator  Introduction to variables and functions

^ Matrices and Vectors: All variables are matrices.^ 

Creating matrices and vectors  Subscript notation  Colon notation

Dr. Hanif Durad

Lecture Outline (2/2)

^ Additional Types of Variables^ ^

Complex numbers  Strings  Polynomials

^ Working with Matrices and Vectors^ ^

Some basic linear algebra  Vectorized operations  Array operators

^ Managing the Interactive Environment ^ Plotting

MATLAB Desktop (1/2)

MATLAB Desktop (2/2)  The desktop provides different ways ofinteracting with MATLAB ^ Entering commands in the command window ^ Viewing values stored in variables ^ Editing statements in MATLAB functions andscripts ^ Creating and annotating plots

Dr. Hanif Durad

MATLAB as a Calculator (2/2)

^ Define and use variables>> a = 5a =^5 >> b = 6b =^6 >> c = b/ac =1.

Dr. Hanif Durad

Built-in Variables (1/2)

pi (=

π) and ans are a built-in variables

>> pians =3.1416>> sin(ans/4)ans =0.7071Note: There is no “degrees” mode. All angles are measuredin radians.

Dr. Hanif Durad

Built-in Functions

^ Many standard mathematical functions, such as sin, cos, log, andlog10, are built-in>> log(256)

log(x) computes the natural logarithm of x

ans =5.5452>> log10(256)

log10(x) is the base 10 logarithm

ans =2.4082>> log2(256)

log2(x) is the base 2 logarithm

ans = 8

Ways to Get Help

Dr. Hanif Durad

^ Use on-line help to request info on a specific function>> help sqrt ^ In MATLAB version 6 and later the doc functionopens the on-line version of the manual. This is veryhelpful for more complex commands.>> doc plot ^ Use lookfor to find functions by keywords>> lookfor functionName

^ The help browser opens when you type a doc command:>> doc plot

On-line Help (2/2)

Looking for Functions

Dr. Hanif Durad

^ Syntax:lookfor stringsearches first line of function descriptions for “string”.Example:>> lookfor cosineproducesACOS

Inverse cosine. ACOSH

Inverse hyperbolic cosine. COS

Cosine. COSH

Hyperbolic cosine.

Suppress Output with Semicolon(1/2)

Dr. Hanif Durad

^ Results of intermediate steps can be suppressed withsemicolons.Example: Assign values to x, y, and z, but only displaythe value of z in the command window:>> x = 5;>> y = sqrt(59);>> z = log(y) + x^0.

z =3.

Dr. Hanif Durad

^ Type variable name and omit the semicolon to print the value ofa variable (that is already defined)>> x = 5;>> y = sqrt(59);>> z = log(y) + x^0.25z =3.5341>> yy =7.

( = log(sqrt(59)) + 5^0.25 ) Suppress Output with Semicolon(2/2)

MATLAB Variables Names

Legal variable names:^ ^

Begin with one of a–z or A–Z  Have remaining characters chosen from a–z, A–Z, 0–9, or  Have a maximum length of 31 characters  Should not be the name of a built-in variable, built-in function, or  user-defined function

^ Examples:^ ^

xxxxxxxxx  pipeRadius  widgets_per_box  mySum  mysum

^ Note: mySum and mysum are differentvariables. MATLAB is case sensitive.

Built-in MATLAB Variables(1/2)

Dr. Hanif Durad

Name

Meaning ans^

value of an expression when that expression is not assignedto a variable eps^

floating point precision pi^

π, (3.141492.. .) realmax

largest positive floating point number realmin

smallest positive floating point number Inf^

∞, a number larger than realmax, the result of evaluating 1/0. NaN^

not a number, the result of evaluating 0/