Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine.

Slides:



Advertisements
Similar presentations
COMP 116: Introduction to Scientific Programming Lecture 37: Final Review.
Advertisements

Introduction to Matlab
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
MATLAB for Image Processing April 10 th, Outline Introduction to MATLAB –Basics & Examples Image Processing with MATLAB –Basics & Examples.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
General Computer Science for Engineers CISC 106 Lecture 04 Roger Craig Computer and Information Sciences 9/11/2009.
Introduction to MATLAB
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine.
C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB
MATLAB Programming fprintf Cell arrays Structures Flow of control Vectorization Functions 1.
Programming with MATLAB. Relational Operators The arithmetic operators has precedence over relational operators.
MATLAB FUNDAMENTALS: INPUT/OUTPUT LOGIC CONTROL STRUCTURES HP 101 – MATLAB Wednesday, 9/24/2014
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Vlachopoulos Georgios Lecturer of Computer Science and Informatics Technological Institute of Patras, Department of Optometry, Branch of Egion Lecturer.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
INTRO TO PROGRAMMING Chapter 2. M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
Chapter 5. Loops are common in most programming languages Plus side: Are very fast (in other languages) & easy to understand Negative side: Require a.
Matlab tutorial course Lesson 2: Arrays and data types
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
Selection Programming EE 100. Outline introduction Relational and Logical Operators Flow Control Loops Update Processes.
Matlab Programming, part 1 M-files It is generally more convenient to program in Matlab using m-files, ascii text files containing a set of Matlab commands.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Introduction to MATLAB Session 3 Simopekka Vänskä, THL Department of Mathematics and Statistics University of Helsinki 2011.
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.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2010.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
Flow Control and Functions ● Script files ● If's and For's ● Basics of writing functions ● Checking input arguments ● Variable input arguments ● Output.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Introduction to MATLAB Session 1 Simopekka Vänskä, THL 2010.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Introduction to MATLAB 7 MATLAB Programming for Engineer Hassan Migdadi Spring 2013.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
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 Matlab Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
MATLAB Programming COMM2M Harry R. Erwin, PhD University of Sunderland.
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Introduction to MATLAB 7 Engineering 161 Engineering Practices II Joe Mixsell Spring 2012.
Digital Image Processing Introduction to M-function Programming.
Introduction to Matlab
Matlab Programming a logical approach. Outline Announcements: –Homework I: due Wed. by 5, by –Last day to add/drop or change credit/audit Iteration.
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
Structured Programming II: If Statements By the end of this class you should be able to: implement branching in a program describe and use an “if” statement.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
General Computer Science for Engineers CISC 106 Lecture 12 James Atlas Computer and Information Sciences 08/03/2009.
General Computer Science for Engineers CISC 106 Lecture 13 - Midterm Review James Atlas Computer and Information Sciences 10/02/2009.
Interduction to MATLAB (part 2) Manal Alotaibi Mathematics department College of science King saud university.
Improving Matlab Performance CS1114
“Moh’d Sami” AshhabSummer 2008University of Jordan MATLAB By (Mohammed Sami) Ashhab University of Jordan Summer 2008.
Image Processing 1 Digital Image Processing Teacher Assistant: Elhanan Elboher course personal
MATLAB – More Script Files
Matlab Training Session 4: Control, Flow and Functions
L – Modeling and Simulating Social Systems with MATLAB
Scripts & Functions Scripts and functions are contained in .m-files
Outline Matlab tutorial How to start and exit Matlab Matlab basics.
Introduction to MATLAB
Vectorized Code, Logical Indexing
Programming Languages
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
ME 123 Computer Applications I Lecture 5: Input and Output 3/17/03
Presentation transcript:

Computer Science in Practice This course is an introduction to problems (and solutions) that arise in applied fields of computer science such as machine learning, computer vision and graphics. We will mainly use tools of linear algebra.

Computer Science in Practice Lecturer: Dani Lischinski TA: Amit Gruber Course Personal Reception hour: Sunday Web site:

Requirements of the course Exercises (every 2-3 weeks) –Exercises are submitted in pairs –Programming in Matlab or Octave –Experimental validation –Theoretical questions A final exam

Matlab/Octave Basics esk/help/techdoc/matlab_prog/exampleind ex.html (M-file programming) esk/help/techdoc/matlab_prog/exampleind ex.html Use help

M-File Programming M-files can be scripts or functions that accept input arguments and produce one or more outputs. Components of m files: Function definition line function [out1 out2] = name(in1, in2, in3) H1 line - a single comment line that follows the function definition line. % SQUARESUM compute the sum of the square of the matrix elements it is the first text that appears when user write >> help function_name >> lookfor keyword display all functions where the keyword appeared in H1 line Help Text - text block following the H1 line without any blank line in between the two Function body – the Matlab code Comments – lines starting with % (note – add short and clear comments to your code)

Operators Arithmetic operators (numeric computations) –matrix arithmetic (linear algebra A*B) –array arithmetic (element by element A.*B) +, -,./,.^,:.. Relational operators (compare) –Compare corresponding elements of arrays of equal dimensions (, =, ==, ~=) or an array to scalar Logical operators can operate both on logical and numeric data (and: &, or: |, not: ~) true: logical 1 or non-zero numeric quantity false: logical 0 or numerical 0 logical functions : xor, any, all

Flow control if, else, elseif, end switch, case, otherwise, end return try,..catch for i=start:increment:end, end while, end break (used with for or while) continue (used with for or while) Try not to use

Code optimization – vectorizing loops Convert for / while loops to equivalent vector or matrix operations 1D indexing >> for x = 1:k ff(x) = 5*sin((x-1)/(2*pi)); end >> x = 0:k-1 >> ff = 5*sin(x/(2*pi));

Code optimization – vectorizing loops 2D indexing meshgrid – convert rows vectors to arrays C and R that can be used for evaluating function with two variables >> for r = 1:10 >> for c = 1:10 >> b(r,c) = r^2+ c^2 >> end >> [C, R] = meshgrid(1:c, 1:r) >> b = R.^2 + C.^2;

Code optimization – vectorizing loops function B = repmat(A,M,N) [m,n] = size(A); mind = (1:m)’; nind = (1:n)’; mind = mind(:,ones(1,M)); nind = nind(:,ones(1,N)); B = A(mind,nind);

Code Optimization – Preallocating arrays Simple way to improve code execution is to pre-allocate the size of the arrays in the program. The preallocation also help reduce memory fragmentation when working with large matrixes >> f = zeros(1024);

Cell arrays and Structures Cell array is multidimensional array whose elements are copies of other arrays >> c = {‘gauss’,[1 0;0 1], 3} >> c{1} ans = gauss Structures are similar to cell arrays (allow grouping of a collection of dissimilar data) but they addressed by fields rather than by numbers >> params.nimgs = 100; >> params.jump = 2; >> params.baseStr = ‘testImg’

A few more important commands (look in the help) find repmat reshape clear save plot, subplot disp

Exercise 1 Find the first eigenvector and eigenvalue of a matrix using the power method. Targets: –Getting familiar with Octave –Understanding the Power Mehtod –Designing and performing experiments