MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
CMPS 1371 Introduction to Computing for Engineers FUNCTIONS.
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
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.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Builtin and user defined functions
1 Introduction to MATLAB MATLAB is all of the following: 1.Computational environment 2.Plotting software 3.Programming language Typical applications: 1.Calculations.
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
Matlab for Engineers Built-in Matlab Functions Chapter 3.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 1.
INTRODUCTION TO MATLAB LAB# 01
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Arrays 1 Multiple values per variable. Why arrays? Can you collect one value from the user? How about two? Twenty? Two hundred? How about… I need to collect.
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.
Matlab for Engineers Manipulating Matlab Matrices Chapter 4.
CMPS 1371 Introduction to Computing for Engineers MatLab.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Recap Script M-file Editor/Debugger Window Cell Mode Chapter 3 “Built in MATLAB Function” Using Built-in Functions Using the HELP Feature Window HELP.
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Chapter 6 Review: User Defined Functions Introduction to MATLAB 7 Engineering 161.
Working with Arrays in MATLAB
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
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.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Lecture 24: Rough and Ready Analysis. MATLAB uses function names consistent with most major programming languages For example sqrt sin cos log.
Matlab for Engineers Matlab Environment Chapter 2.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
SCRIPTS AND FUNCTIONS DAVID COOPER SUMMER Extensions MATLAB has two main extension types.m for functions and scripts and.mat for variable save files.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.
ECE 1304 Introduction to Electrical and Computer Engineering
Arithmetic Operations
Numeric, Cell and Structural Arrays One of the strenghts of MATLAB is the capabilty to handle collection of numbers called ARRAYS. MATLAB refers to scalars,
ECE 1304 Introduction to Electrical and Computer Engineering
Built-in MATLAB Functions Chapter 3
User Defined Functions
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
Fourth Year – Software Engineering
Introduction to MATLAB
Introduction to Matlab
Matlab Basics Tutorial
Chapter 2 MATLAB Environment
CHAPTER 3 Built-in MATLAB Functions
Presentation transcript:

MATLAB An Introduction to MATLAB (Matrix Laboratory) 1

MATLAB Windows 2

Command Window – Heart of MATLAB – Access most commands and functions Workspace window – Shows created variables during present session – Variables remain only for present session Current Directory Window – Contains options for locating, opening, editing, and saving files Command History Window – Keeps a history of commands used and executed in the Command Window – Does not show results of your commands 3

Document Window (Double-click on any Variable in the Workspace window automatically launches a document window ) 4 Document Window

Figure Window When Figures are created a new window opens 5

Edit Window 6 Save and Run

Order of Operation 1.Exponentiation 2.Multiplication / division 3.Parentheses first 4.Addition / subtraction 7

Parentheses Use only ( ) { } and [ ] mean something different MATLAB does not assume operators 8 5 * (3+4) not 5(3+4)

Basic Math Functions Built into MATLAB – Addition (+) – Subtraction (-) – Multiplication (*) – Division (/) – Exponentiation (^) 9

Saving a MATLAB Session Only values of the variables are saved in the workspace Window ( Caution: Do not program in the Command Window. Program in the Editor Window) 10

Saving a MATLAB Session ( Caution: Use Editor Window to program.) 11

Saving a Program as a M-file 1.Save your work by creating an m-file 2.File->New->m-file 3.Type your commands in the edit window that opens 4.Save as XXX.m 5.The file is saved into the current directory 6.It runs in the command window 12

Comments (%) Be sure to comment your code – Add your name – Date – Section # – Assignment # – Descriptions of what you are doing and why 13

Comments (%) 14

Elementary Math Functions abs(x)absolute value sign(x)plus or minus exp(x)e x log(x) natural log log10(x)log base 10 15

Rounding Functions round(x) fix(x) floor(x) ceil(x) 16

Rounding Functions 17

Discrete Mathematics factor(x) gcd(x,y) greatest common denominator lcm(x) lowest common multiple rats(x) represent x as a fraction factorial(x) primes(x) isprime(x) 18

Trigonometric Functions sin(x)sine cos(x)cosine tan(x)tangent asin(x)inverse sine sinh(x)hyperbolic sine asinh(x)inverse hyperbolic sine sind(x)sine with degree input asind(x)inverse sin with degree output 19

Data Analysis max(x) min(x) mean(x) median(x) sum(x) prod(x) sort(x) 20

Data Analysis 21 When x is a matrix, the max is found for each column

Data Analysis 22

Data Analysis 23

Data Analysis 24

Determining Matrix Size size(x)number of rows and columns length(x) biggest dimension 25

Determining Matrix Size 26

Variance and Standard Deviation 27

Random Numbers rand(x) – Returns an x by x matrix of random numbers between 0 and 1 rand(n,m) – Returns an n by m matrix of random numbers These random numbers are evenly distributed 28

Random Numbers 29

Matrices Group of numbers arranged into rows and columns Single Value (Scalar) – Matrix with one row and one column Vector (One dimensional matrix) – One row or one column Matrix (Two dimensional) 30

Scalar Calculations You can use MATLAB like you’d use a calculator 31

Scalar Calculations 32

Variables MATLAB allows you to assign a value to a variable A=3 Should be read as A is assigned a value of 3 Use the variables in subsequent calculations 33

Predefined MATLAB Functions 34 Functions consist of – Name – Input argument(s) – Output Sqrt (x) = results Sqrt (4) = 2

Functions accept either scalar or matrix input 35 X=1:10 is one row matrix 1 to 10

d - Matrix 36

Array Operations 37 To create a row vector, enclose a list of values in brackets

Array Operations 38 You may use either a space or a comma as a “delimiter” in a row vector

Array Operations 39 Use a semicolon as a delimiter to create a new row

Array Operations 40 Use a semicolon as a delimiter to create a new row

Array Operations 41 Hint: It’s easier to keep track of how many values you’ve entered into a matrix, if you enter each row on a separate line. The semicolons are optional

Array Operations While a complicated matrix might have to be entered by hand, evenly spaced matrices can be entered much more readily. The command b= 1:5 or the command b = [1:5] both return a row matrix 42

Array Operations 43 The default increment is 1, but if you want to use a different increment put it between the first and final values

Array Operations Array multiplication.* Array division./ Array exponentiation.^ 44 In each case the size of the arrays must match

Array Operations Repetitive Calculations assume you have a list of angles in degrees that you would like to convert to radians. 45

Array Operations Repetitive Calculations 46

Array Operations Transpose Operator 47

Array Operations Transpose Operator 48

Array Operations Transpose Operator 49

Number Display Scientific Notation – Although you can enter any number in decimal notation, it isn’t always the best way to represent very large or very small numbers – In MATLAB, values in scientific notation are designated with an e between the decimal number and exponent. (Your calculator probably uses similar notation.) 50

Number Display 51

To calculate spacing between elements use linspace and logspace 52

logspace 53 e =

Manipulating MATLAB Matrices 54

55