Lecture 12: M/O/F/ for Engineering Applications B Burlingame 27 April 2016.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to MATLAB Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/22/2003.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Matlab intro The Environment
MATLAB Fundamentals.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
Lecture 13: M/O/F/ for Engineering Applications - Part 1 BJ Furman 26NOV2012.
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
You can make this in matlab!. Matlab Introduction and Matrices.
Lecture 14: M/O/F/ for Engineering Applications - Part 2 BJ Furman 28NOV2011.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
Math 15 Lecture 7 University of California, Merced Scilab A “Very” Short Introduction.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
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.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
OUTLINE Overview Numbers, variables and similar in Matlab
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Lecture 3: M/O/F/ for Engineering Applications B Burlingame 16September2015.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
The Hong Kong Polytechnic University Industrial Centre MatLAB Lesson 1 : Overview & Environment Edward Cheung Room W311g.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
Matlab for Engineers Matlab Environment Chapter 2.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
An Introduction to Programming in Matlab Emily Blumenthal
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
ECE 1304 Introduction to Electrical and Computer Engineering
L – Modeling and Simulating Social Systems with MATLAB
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Use of Mathematics using Technology (Maltlab)
Communication and Coding Theory Lab(CS491)
Presentation transcript:

Lecture 12: M/O/F/ for Engineering Applications B Burlingame 27 April 2016

Announcements Rest of semester  Homework Remaining homework can be done in pairs, turn in one paper with both names Homework 6 posted – due 5/4 Homework 7 posted next week – due 5/11 Homework 8, final review – due with final Midterm grades in process  System failure, having to regrade No office hours, tonight

3 What and Why? Data  Pieces of information we deal with in the problem solving process Computers & Software  Tools we use to help automate finding these solutions Matlab Excel C

Matlab and Octave M/O/F are ‘high-level’ languages  They abstract away the nitty-gritty details Numerical calculation  Oriented toward engineering, mathematical, and scientific computing Matlab (Matrix Laboratory)  Particularly good at handling lists of numbers (called arrays) Powerful graphics and analysis tools  Controls, signal processing, data analysis, and other specialized ‘toolboxes’ are available Widely used in industry Matlab is commercial software (a student version is available) Octave and FreeMat are open source and free: (main page) (main page)

MatLab - Current Layout Command Window Interactive ‘scratch pad’ Workspace Workspace: lists variables Directory: files in current dir Workspace/ Current Directory Window Command History Window

M/O/F Basics - 1 Fundamental element: the array  even integers are stored as 1x1 array of double floating point value by default How many bytes?  See Workspace Window Useful commands (see documentation for more details!)  who (information about what is in memory)  whos (more detailed information about what is in memory)  clc (clears the command window. In QtOctave, View  Clear Terminal)  clear (clears all user defined variables)  help name (provides information on command name)

Octave Command Line Enter commands at the prompt

QtOctave GUI Enter commands at the prompt

Octave as a ‘scratch pad’ dynamically typed

M/O/F Basics - 2 Script files (.m files)  Text files containing M/O/F statements Type in a text editor (M/O/F) or use M-file editor in Matlab (File/New/M-File or Ctrl-n)  Comments Matlab: % Octave: % or # FreeMat: %  Example: look at cool_plot.m Verify directory containing cool_plot.m is in the file path  MATLAB: File | Set Path… | select folder  Octave: addpath(‘dir_path’) find from Windows Explorer

Script File Example: cool_plot.m

Octave Script File Example cool_plot.m needs to be in the ‘load path’ Octave: addpath(dir-path) Example (yours may be different): addpath('C:\Octave\Octave_code') Matlab: File | Set Path…

Matlab Script File Example

MatLab Numeric Data Types NameBitsRange double e308 – 1.798e e e-308 single32-3.4e38 – 3.4 e38 int[8,16,32,64]8, 16, 32, 64(-2 (n-1) + 1) – (2 (n-1) -1) uint[8,16,32,64]8, 16, 32, 640 – (2 n – 1)

MatLab Variable Names Begins with a letter Followed by letters, numbers, and an underscore _ Case sensitive Cannot be a MatLab reserved word Note: similar to C ValidInvalid area123x area_of_a_circlearea of a circle NumberOfCountriesIf (if is a reserved word) x123xHowMany!

M/O/F Basics - 3 Array creation  A = [1 2 3; 4,5,6; 7 8 9] size(A) Indexing elements  A(1,2) Adding elements  A(4,2) = 13  A(4,2) = 13; Separate elements by spaces or commas, and rows by semicolon or carriage return Index by enclosing indices in ( ) What does this do?

M/O/F Basics - 4 Vectors ( just 1xn or nx1 arrays)  B=[sin(pi/4), -2^3, size(A,1)] Vectors using the colon operator  C = 1 : 0.25 : 2  D = 0 : 5 Linspace  E = linspace(0,5,3 ) Logspace  F = logspace(1,3,5) base : increment : limit start : end : n For n elements linearly spaced between start and end start : end : n For n elements logarithmically spaced between start and end For an increment of 1: base : limit Format: Note: limit is reached only if (limit-base)/increment is an integer

M/O/F Basics - 5 Manipulating arrays  Add a row A = [ A ; [ ] ]  Extract a sub-array G = A(1:3, 1:2) Colon operator by itself means, “all the elements”  Can apply to the dimensions of the arrays to access all the elements of a row or column  Can apply to the entire array to get all the elements as a column vector  What order will they come out?  Examples H = [1:4; linspace(10,40,4); 400:-100:100] I = H( [1 2], : ) J = H( : ) What will this produce? Assuming A = [ 1 2 3; 4,5,6 ; ] What does this do? Matlab stores array elements in column- major order.

M/O/F Basics - 6 Special matrices  zeros, ones, eye K=zeros(3) L=ones(4) M=eye(3)

M/O/F Basics - 7 Matrix operations  Arithmetic just like with scalars! (But need to take care that dimensions agree) N=L*7 O=N+eye(4) P=B*E P=B*E’ Q=A+B Q=B+E [1 2]*[3 ; 4] What does the ‘ do? A=[1 2 3; 4,5,6; 7 8 9] B=[sin(pi/4), -2^3, size(A,1)] E=linspace(0,5,3) L=ones(4)

M/O/F Basics - 8 Matrix operations, cont.  Matrix division R1=10k R2=R3=5k V=10V Matrix solution If we had iR = V instead, we’d use ‘right’ division: ( i = R / V ) roughly the same as: i = VR -1 R2 R1 R3 +V i1 i2 i3 R = [ ; e3; 0 10e3 0]; V = [ ]’; I = R \ V i 1 - i 2 - i 3 = 0 R 1 i 3 = V (R 2 +R 3 ) i 2 = V

M/O/F Basics - 9 Matrix operations, cont.  Element-by-element operations use. (dot) and the operator (other than addition/subtraction) dot product of two vectors Note!! period-asterisk means element-by-element multiplication

M/O/F Basics - 10 Functions  Like script M-files, but several differences: first line must be of the form: function [output args] = function_name(input args) variables generated in the function are local to the function, whereas for script files (.m files), variables are global the file must be named, ‘function_name.m’  Make sure you add comments at the start that describe what the function does  Example: root-mean-square function, rms1.m keyword Name that you assign

M/O/F Basics Functions, cont.  Example: root-mean-square function, cont. Pseudocode:  square each element of x  sum the squares  divide by N  take the square root Expression to square each element in vector x  xs = x.^2 Sum the squares  sums = sum(xs) Divide by N  N = length(x)  ms = sums/N Take the square root  rms = sqrt(ms) Before you write the function, make sure the name you propose is not already used! help fn_name

M/O/F Basics Functions, cont.  Example: root-mean-square function, cont. function [y] = rms(v) % rms(v) root mean square of the elements of the column vector v % Function rms(v) returns the root mean square of the elements % of the column vector, v. If v is a matrix, then rms(v) returns % a row vector such that each element is the root mean square %of the elements in the corresponding column of v. vs = v.^2; % what does this line do? Also note semicolon. s = size(v); % what does this line do? y = sqrt(sum(vs,1)/s(1)); % what is s(1)? Let v=sin([0: *pi: 2*pi]’), one period of a sine wave. The RMS value of a sine wave is its amplitude*1/sqrt(2) Does rms() work with a row vector? How about a matrix? H1 comment line (used in lookfor) Comments that will be displayed by help command

M/O/F Basics Functions, cont.  Make rms function more robust to work with row or column vector or matrix with column vectors of data  Pseudocode: Test for size of v  if > 2, print error message  else  if row vector  transpose  calculate rms  See rms3.m

Vector Dot Product Example X Y Find the X and Y components of the vector, V ivv x ˆ   Back

References Matlab. (2009, November 6). In Wikipedia, the free encyclopedia. Retrieved November 6, 2009, from  Matlab tutorials: GNU Octave. (2009, October 31). In Wikipedia, the free encyclopedia. Retrieved November 6, 2009, from  Octave main page: ( access to pre-built installers)  Octave tutorials: FreeMat. ftp:// ses/ENGR-25.htm ftp:// ses/ENGR-25.htm