10
IT1005 Lab session on week 6 (2 nd meeting)

IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Embed Size (px)

Citation preview

Page 1: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

IT1005

Lab session on week 6(2nd meeting)

Page 2: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Lab 2 - Recap

• By now, you must ensure that you are familiarwith Matlab environments:– Matlab main window, M-File Editor, Command Window,

Workspace, Figure Window, Docking, etc.– Matlab debugger, breakpoint, stepping functions, looking at

workspace during stepping, ‘go to cursor’, adjusting program based on the error messages, etc.

• Remember that you can always just select Matlab codes using ‘Select tool’ in Adobe Acrobat, then do copy-paste to Matlab rather than typing it all again.– For lab assignments, for trying codes in lecture notes, etc.

Page 3: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Symbols and Keyboard LocationsSymbol English Name Keyboard Location Matlab example

: Colon SHIFT+two keys on the left of [Enter] A = 1:5

; Semicolon Two keys on the left of [Enter] A = [1;2;3]

` Apostrophe 1 One key on the left of key 1 NOT valid!

‘ Apostrophe 2 One key on the left of [Enter] A = ‘hello’

[] Square bracket Above [Enter] A = [1 2 3]

& Ampersand SHIFT+key 7 true && true

| Bar SHIFT+one key above [ENTER] false || true

~ Tilde SHIFT+one key one the left of key 1 ~ false

The other keys should be quite straightforward…

http://en.wikipedia.org/wiki/Keyboard_layout#US

Page 4: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Review on Array/Vector/Matrix

• Creation– mat = [], repmat, ones, zeros, eye, diag, rand, etc

• Accessing elements/indexing (index start from 1!)– mat(indices), the usage of ‘:’, mat([indices1 … indicesn])

• Manipulation: add, edit, delete row/col, sort, find– mat(:,x) = y

• Operation: +, -, *, /, .*, ./– matA op matB, mat op scalar (scalar expansion)

• Multidimensional array: 3-D…– We seldom go beyond 3D…

Page 5: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Quick Test

• Simple test to about array:1. Create an array of size 4*5 with all ‘1’ (then all ‘0’).

1. Try repmat, manual creation, using [1;1;1;1]*[1 1 1 1 1] =)

2. Compute this: [1 2] .* [2 1] = [3 4] [2 1]

1. Change .* to *, ./, /, +, or -

3. Create this array [1 2 3; 4 5 6; 7 8 9],then perform these operations:

1. Change the 2nd row to 100 90 80!2. Change the 3rd col to 20 10 0!3. Change the main diagonal to all zeros!

Page 6: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Relational and Logical Operations

• Matlab relational operations– <, >, <=, >=, ==, ~=– relational operations on array the result is array– floating-point imprecision use eps

• Logical operators– &, |, ~, &&, ||– short circuit

Page 7: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Quick Test

• Simple test to about relational/logical operations:– How to make these statements produce ans = 1– You can only supply ONE single operator

or MATLAB function to replace ‘…’1. 10+30*2-5/4 … 2*5-102. sin(pi) == 0?3. … ( [10 20 30] / 10 ... [1 2 3] )4. 10 > 20 ... 5 … 25. 10 > 5 … 5 > 26. … … 10 > 20 && 5 < 2 …

Page 8: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Lab 3 – Free and Easy Time

• Now, you are free to explore Matlab,especially to find answers for Lab 3

• For those who have done Lab 3, try this extra challenges!The solution is at the end of this session– There is a land of size 3m*5m– The height of each square meter on that land is known:

[1 2 3 4 5; 2 3 4 5 6; 7 7 7 7 7] above sea level (denoted in meter).– A house of size 3*5 is going to be built there.– Before building it, the land must be leveled!– We want the land to have height 5m above sea level.– Question: what is the minimum amount of soil (in cubic meter) that

must be added (or perhaps removed) in order to make this land flat? – Hint: explore array operations, Matlab function ‘sum’, and ‘mesh’ or ‘surf’!

Page 9: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Lab 3 Marking + Midterm Test

• I will be away– @ Jakarta, Indonesia during mid semester break– 22 Feb night – 2 March

• Lab 3 marks will be available on 3 or 4 March.– Will not be as fast as Lab 0/1 last week.

• If you have any questions, try IVLE forum first,ask your class mates, or ask Colin.– I will occasionally check my emails from home,

but will not be able to reply that fast!– Or ask on Monday morning, before your Mid-term exam!

Page 10: IT1005 Lab session on week 6 (2 nd meeting). Lab 2 - Recap By now, you must ensure that you are familiar with Matlab environments: – Matlab main window,

Remember This!

• E-mail answers to: stevenhalim at gmail.com• With subject header:

– “IT1005-LabGroupID” “FullName”,• e.g. IT1005-7A StevenHalim

– Mr Gmail will sort your emails for me =)

• Try to submit your answers ONCE– Do not submit again to fix some minor mistakes!

• Shorter (but correct) answers ~ better marks =)• Remember, I have ~100 emails/week !