ENGR 1320 Final Review - Programming Major Topics: – Functions and Scripts – Vector and Matrix Operations in Matlab Dot product Cross product – Plotting.

Slides:



Advertisements
Similar presentations
ENGR-25_Plot_Model-2.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
Advertisements

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:
Input and Output ENGR 1181 MATLAB 5. Input and Output In The Real World Script files (which provide outputs given inputs) are important tools in MATLAB.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
Scripts and Flow Control. Scripts So far we have been entering commands directly into the command line But there is a better way Script files (and functions)
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
1 9/29/06CS150 Introduction to Computer Science 1 Loops Section Page 255.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
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:
Branches and Loops Selim Aksoy Bilkent University Department of Computer Engineering
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB.
Week 7 - Programming I Relational Operators A > B Logical Operators A | B For Loops for n = 1:10 –commands end.
Lecture 12 Another loop for repetition The while loop construct © 2007 Daniel Valentine. All rights reserved. Published by Elsevier.
Loops are MATLAB constructs that permit us to execute a sequence of statements more than once. There are two basic forms of loop constructs: i. while.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
ENGR 1320 Final Review - Math Major Topics: – Trigonometry – Vectors Dot product Cross product – Matrices Matrix operations Matrix equations Gaussian Elimination.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 21P. 1Winter Quarter MATLAB: Structures.
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.
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.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
Fall 2006AE6382 Design Computing1 Control Statements in Matlab Topics IF statement and Logical Operators Switch-Case Disp() vs fprintf() Input() Statement.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
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.
ENGR-25_Programming-3.ppt 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
Synthesis ENGR 1181 MATLAB 11. Topics  No new material  Covers topics that will be on the Midterm 2 Exam MATLAB 01 – Program Design MATLAB 02 – Introduction.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Review the following: if-else One branch if Conditional operators Logical operators Switch statement Conditional expression operator Nested ifs if –else.
Introduction to MATLAB. CSPP58001 MATLAB MATLAB is is a matrix-based language well suited for carrying out numerical analysis. It has many, many high-
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB Lecture 18.
1 Interactive Applications (CLI) and Math Interactive Applications Command Line Interfaces The Math Class Flow of Control / Conditional Statements The.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Introduction to Engineering MATLAB – 7 Script Files - 2 Agenda Script files continued.
CS1109 L AB 3 July 3rd. R OAD M AP Homework submission Review How to use function and scripts While-end Finish last exercise Lab 2 Challenge questions.
CSE123 Lecture 3 Files and File ManagementScripts.
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.
Matlab Programming for Engineers
Digital Image Processing Introduction to M-function Programming.
Introduction to Matlab
Interduction to MATLAB (part 2) Manal Alotaibi Mathematics department College of science King saud university.
Chapter 2 Excel Fundamentals Logical IF (Decision) Statements Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Matlab Programming for Engineers
Computer Application in Engineering Design
Repetition Structures Chapter 9
L2. Basics Variables and Expressions Assignment Statements
Control Statements in Matlab
ESS 116 Introduction to Data Analysis in Earth Science
Matlab Training Session 4: Control, Flow and Functions
Chapter 4 MATLAB Programming
Scripts & Functions Scripts and functions are contained in .m-files
MATLAB: Structures and File I/O
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
MATLAB Tutorial Dr. David W. Graham.
Introduction to Matlab LAB 4
INTRODUCTION TO MATLAB
Topics Introduction to Value-returning Functions: Generating Random Numbers Writing Your Own Value-Returning Functions The math Module Storing Functions.
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.
ME 123 Computer Applications I Lecture 25: MATLAB Overview 4/28/03
MATLAB (Lecture 2) BY:MAHA ALMOUSA.
Presentation transcript:

ENGR 1320 Final Review - Programming Major Topics: – Functions and Scripts – Vector and Matrix Operations in Matlab Dot product Cross product – Plotting in Matlab – Decision Making – Loops For While – Input methods Menu input – Output methods Disp Fprintf

Functions and Scripts What is the difference between a function and a script file in MATLAB? – A script is simply a file that contains a series of commands – A function has inputs and outputs. To call the function from the command window, you must supply the input values, and the function will return the output values. For example the ‘ sqrt() ’ function will take the square root of the input, and return the value as the output. – Example problem: Write a function in MATLAB that returns the roots of a quadratic equation. Inputs: a,b,c of the quadratic formula Outputs: roots How would you make this a script? – See Function Example and Functions in MATLAB for proper coding of functionsFunction ExampleFunctions in MATLAB

Vector operations in MATLAB

Plotting in MATLAB Use the plot() command to plot data in an x vector against data in a y vector Additional plot commands: – title – xlabel – ylabel – legend Example problem: plot the two vectors – x = [0:1:10] – y = x.^2 What does the period before the ^ operator do? See Matlab BasicsMatlab Basics

User input and output MATLAB has 2 main ways of prompting a user for information – input() – menu() To output data, you will either plot results or display information to the command window – fprintf() – disp() – use fprintf() to display formatted results and numerical values See input examples and output examplesinput examplesoutput examples

Decision Making MATLAB has several logical operators – == – ~= – && – || – > – < – <= – >= These operators compare two things and return either a ‘1’ if the statement is true or a ‘0’ if the statement is false – Examples: – a+b == b+a returns a ‘1’ – 3+3 == 4+3 returns a ‘0’ – a+b == b+a && 3+3 == 4+3 returns ? MATLAB can make decisions based on the truth of an expression – If/then statement – Code will execute if the logical expression is true, or be skipped if the expression is false Example problem: Write a code that has the user input a number between 1 and 10 and returns a statement to the screen that tells the user whether the number greater or less than 5. See Decision Making ScreencastDecision Making Screencast

Loops We studied two methods for making code execute multiple times: for loop and while loop – the for structure will loop a set number of times for i=1:n code to execute n times end – the while structure will loop until a condition is met while (logical expression) code to execute until the logical expression is false end See loops for the proper syntaxloops Example problem: Write a function that has an input of a single number n and returns a vector [ … n] using a ‘for’ loop. Example problem 2: What is the value of ‘factorial’ at the end of the execution of this code: counter = 5; factorial = 1; while (counter > 0) factorial = factorial * counter; %Multiply counter = counter - 1; %Decrement end factorial

Study Strategy Exam problems will be similar to homeworks Several problems have been revisited in this class: – Electric circuits, truss equations, etc… Look over the first 2 exams for representative problems (particularly the 2 st for matlab- related problems) Refer to the MATLAB book for help