A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.

Slides:



Advertisements
Similar presentations
Introduction to MATLAB The language of Technical Computing.
Advertisements

Introduction to Matlab
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
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.
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.
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Introduction to MATLAB MECH 300H Spring Starting of 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.
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.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MATLAB Basics With a brief review of linear algebra by Lanyi Xu modified by D.G.E. Robertson.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
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.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
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 LAB# 01
Numerical Computation Lecture 2: Introduction to Matlab Programming United International College.
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.
Chapter 1: Getting Started with MATLAB MATLAB for Scientist and Engineers Using Symbolic Toolbox.
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.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Basics of MATLAB By DR. Wafaa Shabana
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
Scientific Computing Introduction to Matlab Programming.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
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
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Introduction to Matlab By E. Noura Semary. Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic.
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”
>> x = [ ]; y = 2*x y = Arrays x and y are one dimensional arrays called vectors. In MATLAB all variables are arrays. They allow functions.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
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.
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.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
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.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
NoViC, Dept. of Mechanical Eng Acoustics Lab., NoViC 1. Download Matlab 2.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
ECE 1304 Introduction to Electrical and Computer Engineering
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
MATH 493 Introduction to MATLAB
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Lecture 2 Introduction to MATLAB
Communication and Coding Theory Lab(CS491)
Introduction to MATLAB
INTRODUCTION TO MATLAB
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.
Matlab Basics Tutorial
Presentation transcript:

A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University

What is Matlab MATLAB® is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. 1 1 Matlab Help

Matlab as a calculator Matlab incorporates simple arithmetic operators + - * / ^ Matlab includes basic functions such as: sin(), log(), log10(), exp(), cosh() Matlab also includes predefined constants: pi, e Values may be assigned to variables: >>U=6; (semicolon suppresses screen output) >>V=5; (Matlab is case- sensitive) >>U*V ans= 30(If no name is specified, “ans” is used by default) >>W=log(U);

Some Basic Commands Who:Lists all variables in workspace Whos:Provides more detailed information on variables in workspace Clear:Clears variables and functions from memory… Clear a, bClears only a and b cd:Change directory ls:Lists files in current directory load filename:Loads file into memory

Matrices You can enter matrices into MATLAB in several different ways: Enter an explicit list of elements. Load matrices from external data files. Generate matrices using built-in functions. Create matrices with your own functions in M-files. An NxM matrix has N rows and M columns Rows may be separated by “enter” >>A=[ ] gives A = Rows may also be separated by semi- colons: >>A=[1 2;3 4]; Columns are separated by a space or comma >>A= [1,2;3,4]

Matrix elements The element located in the i th row and j th column of matrix A can be accessed as: >>A(i,j) The value of an element can easily be changed >>A(2,1)=5; This changes the previous matrix to A= Formulas can be used >>A(2,2)=cos(pi)+sin(pi) A = The elements of an entire row or column can be accessed or changed: >>A(:,2)=6; This changes A to: A=

Matrix elements (Contd) A column can be deleted using: >>A(:,2)=[ ] (This erases the 2 nd column) A row can be deleted in a similar way: >>A(4,:)=[ ] The transpose of a matrix can be obtained using ‘: If A is Then, A’ is Special arrays: Zeros: creates a matrix of all zeros; >>zeros(2,2) yields 0 Ones: creates an array of all ones; >>ones(2,1) yields 1 Eye: creates the identity matrix; >>eye(2,2) yields

For-Loops For loops allow you to repeat statements a certain number of times, and are especially useful for assigning values to array elements. Each for loop ends with an “end” statement For i=1:N For j=1:M A(i,j)=sin(x(i))+b*cos(pi*y(j)) end

Matrix operations If A and B are arrays of the same size: C=A+B; generates an array of the same size as A and B whose elements are the sum of the elements of A and B Alternatively, use For i=1:N For j=1:M C(i,j)=A(i,j)+B(i,j); end Inv(A) generates the matrix inverse of A, i.e., inv(A)*A yields the identity matrix C=A*B; product of matrices A and B

If-statement If (i==2) A(i)=1; end If ((i>2) & (i<=6)) A(i)=3*i; else A(i)=0; end If ((i~=2) & (i<5))Note: ~= means “not equal to” A(i)=3 elseif (i>6) A(i)=1; end

While statement While repeats a statement until the expression between parentheses is no longer true. i=1 While(i<10) i=i+1; End At the end of this while loop, i will be equal to 10

Basic Plotting Suppose x, U and V are 1-D arrays plot(x,U) plots U vs. x plot(x,U,’o’) plots U vs. x and uses an ‘o’ marker xlabel(‘this is my x title’) ylabel(‘this is my y title’) title(‘This is my title’) plot(x,U,’o’,x,V,’+’) Plots U vs x and V vs x on same plot legend(‘this is my U legend’,’this is my V legend’) Figure(1) opens the first figure window

Basic plotting (cont’d) You can also use the GUI to input titles, legends, etc.

More plotting If x, y, and T are NxM arrays where x and y arrays hold the x and y coordinate info: contour(x,y,T) generates a contour plot of T in the x-y plane colorbar inserts a colorbar showing the scale used for the contour plot If x, y, U and V are NxM arrays and U and V represent the x and y components of velocity: quiver(x,y,U,V) generates a velocity vector plot in the x-y plane

A few more tricks Suppose x and A are NxM arrays and you want to plot the data in the k’th row plot(x(k,:),A(k,:)) the colon indicates that you want to go over the entire j-index range If you wish to have 4 plots on the same page, use the “subplot” command If you save a figure in a.fig format, you can open it again in Matlab at a later time and edit it. To copy and paste Matlab plot in Word, either use “edit – copy figure” in Matlab, then paste in document or save figure in Matlab as.jpg file.