CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.

Slides:



Advertisements
Similar presentations
259 Lecture 10 Spring 2013 Advanced Excel Topics – More User Defined Functions; Conditional Statements.
Advertisements

CS0007: Introduction to Computer Programming
Week 6 - Programming I So far, we’ve looked at simple programming via “scripts” = programs of sequentially evaluated commands Today, extend features to:
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
1 PHP Statement Constructs Server Scripting. 5-2 Basic Statement All Statements end in a semicolon. Statements are delimited from the HTML code by enclosing.
Programming Environment S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: Control Flow.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 20 th, 2009.
CIS 101: Computer Programming and Problem Solving Lecture 7 Usman Roshan Department of Computer Science NJIT.
Tutorial 12 Working with Arrays, Loops, and Conditional Statements
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Boolean Expressions Conditional Statements & Expressions CSC 1401: Introduction to Programming with Java Lecture 4 – Part 2 Wanda M. Kunkle.
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
Programming Lecture #4 CS 101 Autumn 2006 Tariq Jadoon.
General Computer Science for Engineers CISC 106 Lecture 05 Dr. John Cavazos Computer and Information Sciences 2/20/2009.
Precedence Parentheses Arithemetic ^ * / + - (exception logical not ~ ) Relational > =
Chapter 4 MATLAB Programming Logical Structures Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
TODAY’S LECTURE Review Chapter 2 Go over exercises.
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I.
CS0004: Introduction to Programming Relational Operators, Logical Operators, and If Statements.
Selection Programming EE 100. Outline introduction Relational and Logical Operators Flow Control Loops Update Processes.
COMP 116: Introduction to Scientific Programming Lecture 28: Midterm #2 Review.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
MATLAB Practice 1 Introducing MATLAB Lecture Notes on Video Search & Mining, Spring 2012 Presented by Jun Hee Yoo Biointelligence Laboratory School of.
CMPS 1371 Introduction to Computing for Engineers MatLab.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
ENG 1181 College of Engineering Engineering Education Innovation Center P. 1 MAT - Conditional Statements Topics Covered: 1. if based conditional statements.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
Conditionals 1.The if Statement 1. switch statement Allows for evaluation of multiple cases of the same variable The switch statement is looking for the.
Matlab tutorial course Lesson 4: Writing your own functions: programming constructs
Authors: Peter Cappello Damon Chastain Matthew Urtnowski Course:CECS 541 Instructor: Dr. Michael Hoffman Date:Fall 2010.
General Computer Science for Engineers CISC 106 Lecture 2^4 Roger Craig Computer and Information Sciences 03/23/2009.
Week 7 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
# 1# 1 Nested If Statements in VBA What is a compound condition that we evaluate? What is a Nested If statement? How do we use ElseIf? CS 105 Spring 2010.
CSI 3125, Preliminaries, page 1 Control Statements.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 4 Monday 06 Oct 2014 EGR 115 Introduction to Computing for Engineers.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
General Computer Science for Engineers CISC 106 Lecture 05 James Atlas Computer and Information Sciences 6/22/2009.
Chapter 4 MATLAB Programming MATLAB Troubleshooting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Knowledge Base. Defining a Variable Dim statement Dim intXX As Integer Public in a Module Public dblNN As Double.
Intro to Matlab Yipei Wang & Qihui Li {yipeiw,
Introduction to CMex E177 April 25, Copyright 2005, Andy Packard. This work is licensed under the Creative.
Zhen Jiang Dept. of Computer Science West Chester University West Chester, PA CSC141 Computer Science I.
Control Structure  What is control Structure?  Types of Controls  Use the control structure in VBScript.  Example Summery.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Matlab Programming for Engineers
ITEC 2600 Introduction to Analytical Programming
Computer Application in Engineering Design
Unit-1 Introduction to Java
C-Language Lecture By B.S.S.Tejesh, S.Neeraja
Matlab Training Session 4: Control, Flow and Functions
ECE 1304 Introduction to Electrical and Computer Engineering
Chapter 4 MATLAB Programming
For/Switch/While/Try UC Berkeley Fall 2004, E77 me
Introduction to Programming in MATLAB
Introduction to Programming for Mechanical Engineers (ME 319)
Selection CSCE 121 J. Michael Moore.
Selection Statements Chapter 4 Attaway MATLAB 4E.
Matlab tutorial course
Logical Operations In Matlab.
Control Structures Part 3
Conditional Statements
CS150 Introduction to Computer Science 1
CS2011 Introduction to Programming I Selections (I)
Selection Statements Chapter 3.
Selection Statements Chapter 4 Attaway MATLAB 5E.
Presentation transcript:

CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING

Branching statements If Switch

switch, case, otherwise end switch expression case testval1 statements1 case testval2 statements2 otherwise statementsOther end Let VAL be value of expression. Assume VAL is a scalar double. Does VAL equal testval1 ? Yes: Execute statements1 Jump past end. No: Does VAL equal testval2 ? Yes: Execute statements2 Jump past end No: Execute statementsOther Jump past end Move to code beyond end Any number of cases are allowed. There does not have to be an otherwise (and associated statements).

switch, case, otherwise end switch expression case testval1 statements1 case testval2 statements2 otherwise statementsOther end VAL (the value of expression) need not be a scalar double. It can also be a char array. Matlab uses strcmp (string compare) to check equality of VAL to the various testval1, testval2, etc.

switch, case, otherwise end switch expression case testval1 statements1 case value2 statements2 otherwise statementsOther end testval can also be cell arrays. The equality of VAL (value of expression ) is tested for any of the contents of the cell array testval.

Switch example if x == 1 fprintf('One'); elseif x == 2 fprintf('Two'); elseif x == 3 fprintf('Three'); else fprintf('%d', x); end switch x case 1 fprintf('One'); case 2 fprintf('Two'); case 3 fprintf('Three'); otherwise fprintf('%d', x); end

More plots Subplot: putting multiple plots in one window x=0:.1:2*pi; subplot(2,2,1); plot(x,sin(x)); subplot(2,2,2); plot(x,cos(x)); subplot(2,2,3) plot(x,exp(-x)); subplot(2,2,4); plot(peaks);

QUESTIONS??

Resources “Introduction to Programming with Matlab”, J. Michael Fitzpatrick and John D. Crocetti Lecture slides E77, Andy Packard,