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

Slides:



Advertisements
Similar presentations
Debugging ACL Scripts.
Advertisements

Algorithm Analysis Input size Time I1 T1 I2 T2 …
RAPTOR Syntax and Semantics By Lt Col Schorsch
Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin.
Course Web Site – Also linked from Blackboard Course Materials – Excel Tutorials – Access Tutorials – PPT.
Introduction to Excel Formulas, Functions and References.
Transformations We want to be able to make changes to the image larger/smaller rotate move This can be efficiently achieved through mathematical operations.
Week 5: Loops 1.  Repetition is the ability to do something over and over again  With repetition in the mix, we can solve practically any problem that.
CMPS 1371 Introduction to Computing for Engineers
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
IT1005 Lab session on week 5. About your Lab TA Name: Steven Halim (Indonesian) Occupation: – Full time teaching assistant – Part time PhD student Not.
Section 2.3 Gauss-Jordan Method for General Systems of Equations
CIS 101: Computer Programming and Problem Solving Lecture 7 Usman Roshan Department of Computer Science NJIT.
ITERATIVE CONSTRUCTS: DOLIST Dolist is an iterative construct (a loop statement) consisting of a variable declaration and a body The body states what happens.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Loops – While, Do, For Repetition Statements Introduction to Arrays
28-Jun-15 Recursion. 2 Definitions I A recursive definition is a definition in which the thing being defined occurs as part of its own definition Example:
 2003 Prentice Hall, Inc. All rights reserved Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
Mr Barton’s Maths Notes
The switch Statement, DecimalFormat, and Introduction to Looping
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
BETTER MANAGING OUR TIME KRONOS TIMEKEEPER SCHEDULING TRAINING YMCA OF METROPOLITAN DALLAS August 30, 2015.
Maths Notes Number 5. Decimals
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
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,
Outlines Chapter 3 –Chapter 3 – Loops & Revision –Loops while do … while – revision 1.
A Computer Science Tapestry 1 Recursion (Tapestry 10.1, 10.3) l Recursion is an indispensable technique in a programming language ä Allows many complex.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Today  Table/List operations  Parallel Arrays  Efficiency and Big ‘O’  Searching.
Leena Razzaq Office: 310BWVH Office hours: Monday 11am-1pm or by appointment jys.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Matlab for Engineers Manipulating Matlab Matrices Chapter 4.
Java Data Types Assignment and Simple Arithmetic.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Biol 304 Week 3 Equilibrium Binding Multiple Multiple Binding Sites.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
Control Structures - Selections - Repetitions/iterations (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
Introduction to Loops For Loops. Motivation for Using Loops So far, everything we’ve done in MATLAB, you could probably do by hand: Mathematical operations.
SPLASH! 2012 QUADRATIC RECIPROCITY Michael Belland.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Introduction to Loops Iteration Repetition Counting Loops Also known as.
A (VERY) SHORT INTRODUCTION TO MATLAB J.A. MARR George Mason University School of Physics, Astronomy and Computational Sciences.
This presentation will attempt to guide you through the information needed to solving harder equations of the type ax 2 + bx + c = 0 When you get to the.
1 CSCD 326 Data Structures I Hashing. 2 Hashing Background Goal: provide a constant time complexity method of searching for stored data The best traditional.
Copyright © 2000, Department of Systems and Computer Engineering, Carleton University 1 Introduction An array is a collection of identical boxes.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
INF3110 Group 2 EXAM 2013 SOLUTIONS AND HINTS. But first, an example of compile-time and run-time type checking Imagine we have the following code. What.
CS1010: Programming Methodology
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Linear Algebra Review.
CS1020 – Data Structures And Algorithms 1 AY Semester 2
Repetition Structures Chapter 9
What to do when a test fails
CS1371 Introduction to Computing for Engineers
MATLAB DENC 2533 ECADD LAB 9.
Mr Barton’s Maths Notes
Unit-2 Divide and Conquer
Java Programming Loops
Maths for Signals and Systems Linear Algebra in Engineering Lectures 13 – 14, Tuesday 8th November 2016 DR TANIA STATHAKI READER (ASSOCIATE PROFFESOR)
Mr Barton’s Maths Notes
Java Programming Loops
Midterm Review October 23, 2006 ComS 207: Programming I (in Java)
Presentation transcript:

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

Remember This (Again)! your answers (in Microsoft Word format) to: stevenhalim at gmail.com With subject: – “IT1005-LabGroupID” “FullName”, e.g. IT1005-7A StevenHalim – Mr Gmail will sort your s 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 s/week !

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 submission mechanism will result in deduction of 1 mark from the offender’s marks for that particular lab.

Lab 3 – Answers (1) Q1 – Operations on Matrix A.Results: 3*3 matrix; [ ]  create array; `;’  change row 0:2:4  start from 0, increment by 2, stop until 4, etc. B.Several options: Manual, not advisable, B = [0 2*pi 4*pi; … ]; or B = [0 2 4; …] * pi; Semi manual, B = [0:2*pi;4*pi; …]; or B = [0:2:4; …] * pi; Assuming A exist: B = A*pi; or B = A.*pi; (‘.*’ is actually not needed as pi is scalar). C.Several options, if I am the lecturer, I will ask you to list at least 4 ways! Wrong, C = [16*pi 14*pi 12*pi; …];, 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:-1:1,3:-1:1); C = B(end:-1:1, end:-1:1); or C = B([3 2 1],[3 2 1]); Use Math, C = 16*pi - B; or C = repmat(16*pi, 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));

Lab 3 – Answers (2) Q2 – Operations on Matrix A.D = A(:) D is a 9*1 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! B.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’). C.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, let’s try to be precise!

Lab 3 – Answers (3) Q3 – Plotting multiple graphs on the same figure A.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! B.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. C.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…

Midterm test answers Only if at least 5 students want to know the ‘truth’ 1.B. 3.0 GHZ, 1 GB DDR-RAM is still faster than 3.2 GHZ, 1 GB DRAM. 2.D. ‘0’/‘1’ only. 3.B. x=1, y=0, z=1. 4.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. 5.B. Step refinement. Coarse, fine grained, etc. 6.D. Little_three_cats are the only valid variable, try ‘isvarname(Little_three_cats)’. 7.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 = D. SimpleSimon%=3;  % 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).

Midterm test answers Only if at least 5 students want to know the ‘truth’ 9.A. x is , apply the BODMAS! Just be careful with \ (reverse operand) 10.B. A will contain values between 31 and 61 inclusive, in increments of 2. This is due to scalar expansion. 11.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. 12.D. C is a 3x3 matrix containing pi in all elements except the diagonal (2+pi). eye  identity matrix [1 0 0; 0 1 0; 0 0 1]! 13.A. C contains the value 1. A(2:-1:1, 2:3) will produce [5 6; 3 4] Searching for 5 in the linear version of A { } returns index D. A = [1 3 5; 2 4 6; 1 2 2]; Similar as our lab D. X = 2. Just simulate the process. 16.E. Colin Tan and Saif Khan. Too bad if you get this wrong :p.

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 (>, ==, <, etc), Logical (And, Or, Not). Is it enough to create more complex programs? So far our programs are straight from start to end. – Single sequence…

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 n 2 : …+n 2 = ? 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!

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: 1.Dispense money 2.Check PIN 3.Ask amount to be withdrawn 4.Deduct the user’s account 5.Ask for ATM card ??? err… something fishy… ???

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… – Let’s create our own ATM machine. – Operations as listed previously (now in logical order): 1.Ask for card 2.Check PIN 3.Ask amount to be withdrawn 4.Dispense that money 5.Deduct the user’s account