Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.

Slides:



Advertisements
Similar presentations
Introducing DFA Formal Description Using Peer Instruction Cynthia Bailey Lee UCSD 2011 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia.
Advertisements

User-defined Functions Selim Aksoy Bilkent University Department of Computer Engineering
Pipeline Summary Try to put everything together for pipelines Before going onto caches. Peer Instruction Lecture Materials for Computer Architecture by.
Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Repeating Structures For Loops. Repeating Structures Tasks we need to complete are often very repetitive. Once a task has been mastered, repeating it.
THE PUMPING LEMMA PROVING A LANGUAGE IS NOT REGULAR Dr. Cynthia Lee - UCSD - Spring 2011 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia.
Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Planning, Outlining, Drafting e.g. Formally Starting the Process.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
General Computer Science for Engineers CISC 106 Lecture 13 Roger Craig Computer and Information Sciences 3/13/2009.
Introduction Copyright © Software Carpentry 2011 This work is licensed under the Creative Commons Attribution License See
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
CIS3931 – Intro to JAVA Lecture Note Set 3 19-May-05.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Lecture Set 5 Control Structures Part D - Repetition with Loops.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
CSE 12 – Basic Data Structures Cynthia Bailey Lee Some slides and figures adapted from Paul Kube’s CSE 12 CS2 in Java Peer Instruction Materials by Cynthia.
Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Programming Abstractions in C++ Cynthia Lee CS106X.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Introduction to TouchDevelop
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Engineering Computation with MATLAB Second Edition by David M. Smith.
1 1 © AdaCore under the GNU Free Documentation License Franco Gasperoni
Tutorial: Reduction from A TM Proofs Dr. Cynthia Lee CSE 105, UCSD Spring 2011 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee,
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
1 09/20/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Theory of Computation 1 Theory of Computation Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Introduction Copyright © Software Carpentry This work is licensed under the Creative Commons Attribution License See
Intermediate 2 Computing Unit 2 - Software Development Topic 2 - Software Development Languages and Environments.
Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Matlab tutorial course Lesson 4: Writing your own functions: programming constructs
Matlab Programming for Engineers
Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike.
Counting Loops.
A First Program CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington Credits: a significant part of.
Repetition Intro to Computer Science CS1510 Dr. Sarah Diesburg.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
EGR 115 Introduction to Computing for Engineers Loops and Vectorization – Part 1 Monday 13 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Repetition Statements (Loops). 2 Introduction to Loops We all know that much of the work a computer does is repeated many times. When a program repeats.
BIT 115: Introduction To Programming Professor: Dr. Baba Kofi Weusijana (say Doc-tor Way-oo-see-jah-nah, Doc-tor, or Bah-bah)
A Brief Introduction to Recursion. Recursion Recursive methods … –methods that call themselves! –They can only solve a base case –So, you divide a problem.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Flow Control in Imperative Languages. Activity 1 What does the word: ‘Imperative’ mean? 5mins …having CONTROL and ORDER!
Software Engineering Algorithms, Compilers, & Lifecycle.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Introduction to Python
Introduction to Programming in MATLAB
Hardware Accelerator Test Bench for Error-Correcting Algorithms
Controlling execution - iteration
Chapter 9 Recursion.
Introduction to Programming in MATLAB
Sampling Distributions
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Loops CIS 40 – Introduction to Programming in Python
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Matlab tutorial course
MATLAB Programming Indexing Copyright © Software Carpentry 2011
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Let’s all Repeat Together
SSEA Computer Science: Track A
Introduction to Programming in MATLAB
Introduction to Programming in MATLAB
How to allow the program to know when to stop a loop.
Presentation transcript:

Introduction to Programming in MATLAB Intro. MATLAB Peer Instruction Lecture Slides by Dr. Cynthia Lee, UCSD is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. Based on a work at Cynthia Lee, UCSDCreative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported Licensewww.peerinstruction4cs.org 1

LOOPS! 2

Loops! Computer programmers are extremely lazy, in that we don’t want to do any more typing than necessary – You’ve already seen that instead of re-typing commands, we can use a script or a function Not only do we not like re-typing—even copying and pasting lines of code is too much work for us! – Instead of copying and pasting lines of code we want to repeat some number of times, we can use a loop! 3

for loop Copy-and-paste version » myvector(1) = 0 » myvector(2) = 0 » myvector(3) = 0 » myvector(4) = 0 » myvector(5) = 0 » myvector(6) = 0 for loop version » for i = 1:6 myvector(i) = 0 end Of course, you can also do this: » myvector(1:6) = zeros(1,6) 4

Software Engineering Can you think of other reasons (besides laziness) that we might want to use programming constructs like scripts, functions, and loops to avoid re-typing or copying and pasting code? Here are some suggested reasons: I.Less prone to errors in the code II.Easier to read the code III.Code runs faster IV.Code is more flexible How many of these are true reasons? (a)1 of them (b) 2 of them (c) 3 of them (d) 4 of them 5

for loop Copy-and-paste version » myvector(1) = 0 » myvector(2) = 0 » myvector(3) = 0 » myvecter(4) = 0 » myvector(5) = 0 » myvector(6) = 0 for loop version » for i = 1:6 myvector(i) = 0 end Of course, you can also do this: » myvector(1:6) = zeros(1,6) 6

What does this code do? » mystery = 1 » for i = 1:10 mystery = mystery * i end a)Computes the sum of the integers from 1 to 8 b)Computses the average of the integers from 1 to 10 c)Computes the factorial of 10 d)Computes the median of the integers from 1 to 10 7