26 - 3/20/2000AME 150L1 M ATLAB ®. 26 - 3/20/2000AME 150L2 M ATLAB ® vs. Fortran Fortran Positives –First Compiler –Legacy Codes –Efficient Numerically.

Slides:



Advertisements
Similar presentations
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Advertisements

MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
Welcome to EGR 106 Foundations of Engineering II Course information Today’s specific topics: – Computation and algorithms – M ATLAB Basics Demonstrations.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
MATLAB Basics CS 111 Introduction to Computing in Engineering and Science.
Introduction to MATLAB
Introduction to MATLAB Week 13 – 4/21/09. Instructor: Kate Musgrave Time: Tuesdays 3-5pm Office Hours: Tuesdays 1:30-3pm
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB.
CSE123 Introduction to Computing
Introduction to MATLAB 7 for Engineers
Division Example 2x - 3y + 4z = 10 x + 6y - 3z = 4 -5x + y + 2z = 3 A*X = B where A = B = >> X = A\B X =
Introduction to MATLAB
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
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.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
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
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
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.
THE MATLAB ENVIRONMENT VARIABLES BASIC COMMANDS HELP HP 100 – MATLAB Wednesday, 8/27/2014
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.
1 Chapter 1 MATLAB Primer This introductory chapter is relatively short and has as its main objective the introduction of MATLAB ® to the reader. This.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (2): MATLAB Environment (Chapter 1)
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.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
Copyright © The McGraw-Hill Companies, Inc. Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 1 An Overview of MATLAB.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Technical Computing Environment. MATLAB Matlab is an interactive computing environment that enables numerical computation and data visualization.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Introduction to MATLAB. CSPP58001 MATLAB MATLAB is is a matrix-based language well suited for carrying out numerical analysis. It has many, many high-
ME6104: CAD. Module 4. ME6104: CAD. Module 4. Systems Realization Laboratory Module 4 Matlab ME 6104 – Fundamentals of Computer-Aided Design.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
1 DKT 211 Basic Communication Engineering LAB # 1A : (Lecture 1) Introduction to Matlab  Basic Features  Scientific features  Array Operations  Script.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB Lecture 18.
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Matlab. Textbooks Required:, by Palm (3 rd edition) Required: Introduction to MATLAB for Engineers, by Palm (3 rd edition)
Engineering Analysis – Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
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  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
ENG 1181 First-Year Engineering Program College of Engineering Engineering Education Innovation Center First-Year Engineering Program MAT - Introduction.
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.
CSE123 Introduction to Computing Lecture 2 Introduction to MATLAB.
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.
BASICS OF MATLAB Engr.Mian Shahzad Iqbal Lecturer,Telecom Department University of Engineering & Technology Taxila.
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
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Lecture 2 Introduction to MATLAB
INTRODUCTION TO MATLAB
Simulation And Modelling
Experiment No. (1) - an introduction to MATLAB
CS 111 Introduction to Computing in Engineering and Science
Presentation transcript:

26 - 3/20/2000AME 150L1 M ATLAB ®

26 - 3/20/2000AME 150L2 M ATLAB ® vs. Fortran Fortran Positives –First Compiler –Legacy Codes –Efficient Numerically –Portability Fortran Negatives –Debugging Hard –Cumbersome –Object Orientation pasted-on M ATLAB ® Positives –Interactive mode –Wealth of 3rd party “notebooks” –Matrix Oriented –Efficient I/O and Graphics M ATLAB ® Negatives –Syntax cumbersome –Command Line oriented

26 - 3/20/2000AME 150L3 M ATLAB ® Usage For the next 4 lectures –Slide will introduce topic Useful in reviewing lecture and practicing Can pay attention to on-line demonstration –Demonstration of usage on-line Will show details of usage Shop proper and improper operation First -- Learn to use M ATLAB ® Help

26 - 3/20/2000AME 150L4 Basic Features Simple Mathematics –M ATLAB ® is like a calculator Type in expression and get answer ( ans= ) Suppress answer with trailing semi-colon ; Can define variables (like in Fortran) –M ATLAB ® operations Fortran-like +, -, * and functions Exponentiation is ^ (like Basic or Excel) 2 Divisions / and \ ( 56/8 same as 8\56 )

26 - 3/20/2000AME 150L5 Hierarchy of operations Similar to Fortran –Expression evaluated left to right –Exponentiation has highest precedence –Multiplication & Division next & equal –Addition & Subtraction next & equal Expressions in Parentheses evaluated first –Start with Innermost & proceed Outward

26 - 3/20/2000AME 150L6 Naming Variables Variable names are Case sensitive (!!!) Names can have up to 31 characters Names must start with a letter Names can contain letter, numerical digits, and underscore (no special characters or blanks) i and j are special (they are )

26 - 3/20/2000AME 150L7 Special Variables i or j - imaginary base ans - unnamed answer pi … eps - machine epsilon (1 + eps)>1 (smallest) inf - stands for infinity NaN or nan - not a number flops - number of floating point operations nargin - number of function input arguments nargout - number of function output arguments realmin - smallest usable positive real number realmax - largest usable positive real number

26 - 3/20/2000AME 150L8 Features of calculations Complex numbers are natural EDU» sqrt(-1) ans = i Pi is predefined in a variable EDU» atan(1)*4-pi ans = 0

26 - 3/20/2000AME 150L9 Cautions Special Variables Can Be Redefined! EDU» pi ans = EDU» pi=5 pi = 5 EDU» atan(1)*4-pi ans =

26 - 3/20/2000AME 150L10 More Features Clear - resets special values and any other defined variables Convenience often misleads EDU» -1*(1/3) EDU» -1^(1/4) ans = EDU» -1^(1/2) EDU» sqrt(sqrt(-1)) ans = i

26 - 3/20/2000AME 150L11 Comments & Punctuation Comments start with % Lines are continued by three periods... Comments cannot be continued (but can use % on next line to make “new” comment) Cannot continue in middle of a variable name

26 - 3/20/2000AME 150L12 Complex Numbers Complex numbers have a magnitude and angle (argument in mathematics) M    M e i  = a + b i where

26 - 3/20/2000AME 150L13 M ATLAB ® Complex Helpers Real, imag, abs, and angle c1 = EDU» mag_c1=abs(c1) i mag_c1 = EDU» c2=3*(2-sqrt(-1)*3) c2 = EDU» angle_c1=angle(c1) i angle_c1 = EDU» c3=6+sin(-5)*j c3 = EDU» imag_c1=imag(c1) i imag_c1 = 2

26 - 3/20/2000AME 150L14 M ATLAB ® Mathematical Functions

26 - 3/20/2000AME 150L15 M ATLAB ® Links Pointers to other texts User Contributed Software (“M-Files”) On-line Demos

26 - 3/20/2000AME 150L16 Command Window Command Window  Workspace who - lists active variables whos - more detailed information clear - clears the workspace (erases all) clear list of variables - clears variables in list help - provides general help help command - provides help on command more on - pauses on full screen

26 - 3/20/2000AME 150L17 Number Display Format format short digits format long digits format short e 3.146e+00+ exponent format long e e+00 format short g better of shorts format long g format hex fb5442d18hexadecimal format rat 355/113rational approximation format bank decimal digits format compact suppresses extra line feeds

26 - 3/20/2000AME 150L18 Command Window Control clc Clear command window home cursor to upper left corner more on Pages the command window computer tells what computer you are running on version Short version information ver long version information quit Stop using Matlab

26 - 3/20/2000AME 150L19 Script M-files Can create scripts of commands Called “m-files” because extension is.m

26 - 3/20/2000AME 150L20 Special M-File Commands disp (variable)display results - no variable names echo control echoing of script commands input prompt user for input keyboard Give temporary control to keyboard pause pause until any key pressed pause n pause n seconds, then continue waitforbuttonpress

26 - 3/20/2000AME 150L21 M ATLAB ® Session Control A file called startup.m (in your search path) will execute every time you start M ATLAB ® Suggestions for a startup file –Keep a diary (copy) of day’s session (you can edit it to remove irrelevant material) –set more on

26 - 3/20/2000AME 150L22 Sample Startup file % This is the startup.m initialization file more on %pause on a full screen dfile=strcat(date,'.txt'); %make date string diary(dfile); %Create a diary file %named with today's date disp(strcat(‘Diary created:',datestr(now,0)))

26 - 3/20/2000AME 150L23 File & Directory Management Save, load & deleting variables save stores all variables in matlab.mat save liststores variables in list load loads all variables from matlab.mat load listloads just variables in list These commands are for initializing workspace

26 - 3/20/2000AME 150L24 File Management Details save (fname, ['var1','var2',…]) saves variables var1 and var2 into file stored in string fname delete ('data.mat') deletes named file Lots of low-level file I/O - we will not use in AME150

26 - 3/20/2000AME 150L25 Exist Command Details EXIST('A') returns: 0 if A does not exist 1 if A is a variable in the workspace 2 if A is a file [usually M-file] on MATLAB's search path 3 if A is a MEX-file on MATLAB's search path 4 if A is a MDL-file on MATLAB's search path 5 if A is a built-in MATLAB function 6 if A is a P-file on MATLAB's search path 7 if A is a directory

26 - 3/20/2000AME 150L26 Embedded OS Commands cd or pwd Show or change present working directory p=cd Return present working directory dir or ls Display files in current directory d=dir return current working directory p=matlabroot return dir path to Matlab type cow Type cow.m in Command window what Type organized listing of Matlab files

26 - 3/20/2000AME 150L27 M ATLAB ® Special Features Vectors and Arrays (and array operations) Plotting Linear Algebra Polynomials (and their roots) Solutions of Systems of Equations Problem Solving

26 - 3/20/2000AME 150L28 M ATLAB ® Arrays M ATLAB ® has many features to work with arrays of numbers (vectors & matrices) Definition: x=[ list of elements separated by, or blanks ] each element may be an arbitrary expression x = [0 0.1*pi,.2*pi … 0.9*pi pi] y=sin(x) produces an array result

26 - 3/20/2000AME 150L29 M ATLAB ® Arrays (2) Arrays have the following properties –1-D Arrays can be rows or columns (use ; to signal end of row) –2-D Arrays have rows and columns –M ATLAB ® can handle higher numbers of dimensions - extra dimensions are “pages”

26 - 3/20/2000AME 150L30 M ATLAB ® Arrays (3) An Array is referred to by its name (same as naming variables) An element of an array is indicated by an index (enclosed in parentheses) V = [ ] V(3) is 3 V(:3) is [1 2 3] V(2:) is [ ]

26 - 3/20/2000AME 150L31 The Colon “:” operator The Colon is used to create equi-spaced lists x=[1:4] is [ ] N1:N2 starts at N1 and increments by 1 to N2 x=[1:2:9] is [ ] N1:N2:N3 starts at N1, increments by N2 until reach N3 Angle=[180:-1:0] generates a list of 181 angles from 180 to 0 (in reverse order) Radians=pi/180*Angle (same but in radians)

26 - 3/20/2000AME 150L32 Scalars and Vectors Scalars can be added, subtracted, multiplied or divided into vectors (element by element) » x=[ ];y=3*x y = » z=x+7 z =

26 - 3/20/2000AME 150L33 The Dot “. “ Operator Some operators don’t make sense » x^2 ??? Error using ==> ^ Matrix must be square. » x.^2 ans =

26 - 3/20/2000AME 150L34 The Dot “. “ Operator (continued) The Dot before an operator signals that you want top perform the same operation on every element in an array x = y = » x.*y ans =