IT1005 - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

IT1005

Description:

stevenhalim at gmail.com. With EMAIL subject: 'IT1005-LabGroupID' 'FullName' ... Mr Gmail will sort your emails for me =) Wrong subject header will confuse Mr Gmail ... – PowerPoint PPT presentation

Number of Views:104
Avg rating:3.0/5.0
Slides: 13
Provided by: steven45
Category:
Tags: gmail | it1005

less

Transcript and Presenter's Notes

Title: IT1005


1
IT1005
  • Lab session on week 7 (3rd meeting)
  • Welcome back from Mid semester break )
  • (a. k. a Mid test period)

2
Remember This (Again)!
  • E-mail your answers (in Microsoft Word format)
    tostevenhalim at gmail.com
  • With EMAIL subject
  • IT1005-LabGroupID FullName,
  • e.g. IT1005-7A StevenHalim
  • Mr Gmail will sort your emails for me )
  • Wrong subject header will confuse Mr Gmail
  • Try to submit your answers ONCE before deadline!
  • Do not submit again to fix some minor mistakes or
    to reconfirm!
  • Shorter (but correct) answers better marks )
  • Remember, I have 90 emails/week !

3
Violations ?
  • There are several violations for lab 3
  • Mostly by those who do not actually attend my
    classes
  • I have decided that there is no penalty for lab
    3
  • Only late submission get -1 mark (per day)
    penalty.
  • For lab 4 onwards, no more mercy
  • Every violation for this e-mail submission
    mechanismwill result in deduction of 1 mark from
    the offenders marksfor that particular lab.

4
Lab 3 Answers (1)
  • Q1 Operations on Matrix
  • Results
  • 33 matrix ? create array ? change row
  • 024 ? start from 0, increment by 2, stop until
    4, etc.
  • Several options
  • Manual, not advisable, B 0 2pi 4pi or
    B 0 2 4 pi
  • Semi manual, B 02pi4pi or B 024
    pi
  • Assuming A exist B Api or B A.pi (.
    is actually not needed as pi is scalar).
  • Several options, if I am the lecturer, I will ask
    you to list at least 4 ways!
  • Wrong, C 16pi 14pi 12pi , not using
    matrix B as reference!
  • Manual, not advisable, C B(3,3) B(3,2) B(3,1)
    .
  • Use loop/index, C B(3-11,3-11) C
    B(end-11, end-11) or C B(3 2 1,3 2 1)
  • Use Math, C 16pi - B or C repmat(16pi, 3,
    3) - B
  • Use sort, C sort(sort(B,1,'descend'),2,'descend'
    )
  • Use rotate, C rot90(B,2) or C
    rot90(rot90(B))
  • Use flipup and fliplr, C fliplr(flipup(B))

5
Lab 3 Answers (2)
  • Q2 Operations on Matrix
  • D A()
  • D is a 91 column vector.
  • Listed column by column or according to the
    indexes of each element.
  • Please specify the order! Otherwise I can say
    zig-zag/random/row by row patterns!
  • A(1,) repmat(-2,1,3)
  • There are several ways to execute this repmat
    function!
  • A(1,) repmat(-2,1,1) also works Why?
  • A(1,) -2 also works Why? (but this one is
    wrong since it does not use repmat).
  • A(,2) zeros(3,1) pi
  • There are several ways to write the zeros
    function. Actually zeros is redundant here!
  • A(,2) zeros(1,3) pi also works Why?
  • A(,2) zeros pi also works Why?
  • A(,2) pi also works Why? (but this one is
    wrong since it does not use zeros).
  • 2B 2C scalar expansion is ok, but to avoid
    confusion, lets try to be precise!

6
Lab 3 Answers (3)
  • Q3 Plotting multiple graphs on the same figure
  • Observed
  • Two graphs on one figure.
  • We can do the same thing with hold on! I have
    shown it 2 weeks ago (creating flatland).
  • Say that y is sine graph, z is cosine graph
    within domain -2pi to 2pi, range -1 to 1.
  • The color of the graphs are blue and green
    because of Matlab settings.
  • You can actually specify plot colors!
    plot(x,y,r,x,z,m) r - red, m - magenta.
    Try!
  • Several options
  • Bad, create E from scratch.
  • Assume B exists, then create E from B by dividing
    B with ./ 1 2 3 4 5 6 7 8 9.
  • Apply F sin(E) ? element by element.
  • Several options
  • plot(E(,1),F(,1), E(,2),F(,2),
    E(,3),F(,3)) grid
  • plot(E,F) grid ? This also works because Matlab
    access matrix column by column.
  • We observe three not so precise sine graphs on
    one figure.
  • No relational or logical questions actually
    These are for lab 4

7
Midterm test answers
  • Only if at least 5 students want to know the
    truth ?
  • B. 3.0 GHZ, 1 GB DDR-RAM is still faster than 3.2
    GHZ, 1 GB DRAM.
  • D. 0/1 only.
  • B. x1, y0, z1.
  • E. None of the above. B, C, D are definitely
    wrong (not binary), A is also wrong because 63
    is one less from 64 (exact multiple of 2),
    thus it will not have 0 just before the
    fraction point.
  • B. Step refinement. Coarse, fine grained, etc.
  • D. Little_three_cats are the only valid
    variable,try isvarname(Little_three_cats).
  • B. x is 20. both long variable name 63 chars
    will be truncated into max 63 chars, thus both
    looks the same for Matlab. Thus x 10 10.
  • D. SimpleSimon3 ? is comment, so this is
    basically print out the current value of
    SimpleSimon (assumed to be a valid variable, as
    stated in the problem description).

8
Midterm test answers
  • Only if at least 5 students want to know the
    truth ?
  • A. x is 3.8278, apply the BODMAS! Just be careful
    with \ (reverse operand)
  • B. A will contain values between 31 and 61
    inclusive, in increments of 2. This is due to
    scalar expansion.
  • E. None of the above. A and B are not scalar,
    thus no scalar expansion.The . is element by
    element multiplication? matrix dimension must
    agree.
  • D. C is a 3x3 matrix containing pi in all
    elements except the diagonal (2pi).eye ?
    identity matrix 1 0 0 0 1 0 0 0 1!
  • A. C contains the value 1.A(2-11, 23) will
    produce 5 6 3 4Searching for 5 in the linear
    version of A 5 3 6 4 returns index 1.
  • D. A 1 3 5 2 4 6 1 2 2 Similar as our lab
    3.
  • D. X 2. Just simulate the process.
  • E. Colin Tan and Saif Khan. Too bad if you get
    this wrong p.

9
What we have learned so far
  • Top Down Design to create programs
  • Big steps, small steps, comments, Matlab codes.
  • Matlab program itself
  • Command/figure window, workspace, debugger, etc.
  • Things about Matlab array/matrix
  • Creation, Deletion, Access, Update, Operations,
    etc.
  • Math and logic operations
  • BODMAS, Relational (, , Or, Not).
  • Is it enough to create more complex programs?
  • So far our programs are straight from start to
    end.
  • Single sequence

10
Review on Control Structures
  • Sequence
  • Superman example (wrong sequence of something
    important)
  • How to exit from this room?
  • Repetition
  • for-end ? if your repetition related to
    counting
  • while-end ? if you need to repeat until some
    event occurs
  • e.g. Count sum of square numbers from 1 up to n2
    149n2 ?
  • Selection
  • if-end ? only test one condition
  • if-else-end ? one condition versus the rest
  • if-elseif-else-end ? several conditions
  • switch ? several equality conditions, not ok for
    INEQUALITIES!

11
Quick Test on Control Structures
  • Decide what to do if an earthquake happens HERE
    and NOW!
  • Simulate an ATM machine that can do these simple
    operations
  • Dispense money
  • Check PIN
  • Ask amount to be withdrawn
  • Deduct the users account
  • Ask for ATM card
  • ??? err something fishy ???

12
Lab 4 Free and Easy Time
  • Now, you are free to explore Matlab,especially
    to find answers for Lab 4.
  • For those who have done Lab 4, try this extra
    challenge!The solution is at the end of this
    session
  • Lets create our own ATM machine ?.
  • Operations as listed previously (now in logical
    order)
  • Ask for card
  • Check PIN
  • Ask amount to be withdrawn
  • Dispense that money
  • Deduct the users account
Write a Comment
User Comments (0)
About PowerShow.com