ME305: Introduction to System Dynamics

Similar documents
Introduction to MATLAB

MATLAB Lecture 1. Introduction to MATLAB

FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

Lecture 2. Arrays. 1 Introduction

TUTORIAL MATLAB OPTIMIZATION TOOLBOX

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Introduction to MatLab. Introduction to MatLab K. Craig 1

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics.

Mathematics 4330/5344 #1 Matlab and Numerical Approximation

TUTORIAL 1 Introduction to Matrix Calculation using MATLAB TUTORIAL 1 INTRODUCTION TO MATRIX CALCULATION USING MATLAB

Matlab and Octave: Quick Introduction and Examples 1 Basics

Identity Matrix: >> eye(3) ans = Matrix of Ones: >> ones(2,3) ans =

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

Getting To Know Matlab

(Creating Arrays & Matrices) Applied Linear Algebra in Geoscience Using MATLAB

Grace days can not be used for this assignment

Introduction to MATLAB

Introduction to MATLAB

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu

AN INTRODUCTION TO MATLAB

Introduction to MATLAB

Introduction to MATLAB

2.0 MATLAB Fundamentals

Computer Packet 1 Row Operations + Freemat

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

To start using Matlab, you only need be concerned with the command window for now.

Lecture 2: Variables, Vectors and Matrices in MATLAB

Introduction to MATLAB 7 for Engineers

Matlab Tutorial and Exercises for COMP61021

MATLAB Basics. Mohamed Taha. Communication Engineering Department Princess Sumaya University Page 1 of 32. Full Screen.

Laboratory 1 Octave Tutorial

ENGR 1181 MATLAB 02: Array Creation

Introduction to MATLAB for Engineers, Third Edition

Matlab Tutorial for COMP24111 (includes exercise 1)

A Guide to Using Some Basic MATLAB Functions

Learning from Data Introduction to Matlab

LAB 2 VECTORS AND MATRICES

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Introduction to MATLAB

Some elements for Matlab programming

Introduction to Matlab

Arrays and Matrix Operations

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

Introduction to Matlab

A QUICK INTRODUCTION TO MATLAB

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

MAT 343 Laboratory 2 Solving systems in MATLAB and simple programming

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

Introduction to MATLAB programming: Fundamentals

EGR 102 Introduction to Engineering Modeling. Lab 05A Managing Data

MATH 5520 Basics of MATLAB

MATH 3511 Basics of MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

The MATLAB system The MATLAB system consists of five main parts:

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

Chapter 2. MATLAB Fundamentals

An Introduction to MATLAB and the Control Systems toolbox Aravind Parchuri, Darren Hon and Albert Honein

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

Computational Methods CMSC/AMSC/MAPL 460. Vectors, Matrices, Linear Systems, LU Decomposition, Ramani Duraiswami, Dept. of Computer Science

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3.

MATLAB GUIDE UMD PHYS401 SPRING 2012

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

Introduction to MATLAB

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

CME 192: Introduction to Matlab

ENGR 105: Introduction to Scientific Computing. Dr. Graham. E. Wabiszewski

Summer 2009 REU: Introduction to Matlab

Introduction to MATLAB

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50

Introduction to Matlab

What is MATLAB and howtostart it up?

Matlab notes Matlab is a matrix-based, high-performance language for technical computing It integrates computation, visualisation and programming usin

Getting Started with MATLAB

AH Matrices.notebook November 28, 2016

MATLAB BASICS. M Files. Objectives

QUICK INTRODUCTION TO MATLAB PART I

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Vectors and Matrices. Chapter 2. Linguaggio Programmazione Matlab-Simulink (2017/2018)

Matrix Manipula;on with MatLab

Introduction to MATLAB Programming

Introduction to Engineering gii

1 Overview of the standard Matlab syntax

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

Using the fprintf command to save output to a file.

A 30 Minute Introduction to Octave ENGR Engineering Mathematics Tony Richardson

ECE Lesson Plan - Class 1 Fall, 2001

MATLAB Premier. Asst. Prof. Dr. Melik DÖLEN. Middle East Technical University Department of Mechanical Engineering 10/30/04 ME 304 1

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

Introduction to Matrix Operations in Matlab

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

MBI REU Matlab Tutorial

Fundamentals of MATLAB Usage

Programming in Mathematics. Mili I. Shah

Transcription:

ME305: Introduction to System Dynamics Using MATLAB MATLAB stands for MATrix LABoratory and is a powerful tool for general scientific and engineering computations. Combining with user-friendly graphics interface, MATLAB is able to present sophisticated plots and graphics. 1. Invoking and Exiting MATLAB You can start MATLAB either from an X terminal or an ASCII terminal. The major difference of the two is that in an ASCII terminal you cannot see the results of graphics commands. The following instructions show you how to invoke MATLAB (Please note that if you have MATLAB on a PC, then you can skip this section.): Using an ASCII terminal: simply type matlab at the UNIX prompt. Using an X terminal or a work-station: Make sure you are in windows environment, i.e. such as done through openwin command. When you invoke MATLAB and get the message of MATLAB will run, but no windows will open, you need to set the DISPLAY environment so as to properly show the results of graphics command in your program. You can use either one of the following commands: setenv DISPLAY terminalname:0 or matlab -display terminalname:0 where terninalname is the name of the station on which you are working, and is shown on the top of the terminal (e.g. ranki). When you successfully invoke MATLAB, you will get the MATLAB prompt: >>. If you have problem with the path setting, you need to modify your.cshrc file by either appending the path /usr/site/bin to any of set-path line, or simply adding a new line set path = ($path, /usr/site/bin) to the end of the file. To activate the modification without re-logging, you can use the command source.cshrc<cr>. To exit Matlab, simply enter exit or quit at the MATLAB prompt. ME 305: System Dynamics Using MATLAB page 1

2. Fundamentals 2.1 How Does MATLAB Work? MATLAB can either work interactively by interpreting each command entered through keyboard, or use an M-file which stores a long sequence of commands. In the former case, MATLAB works like a calculator which shows you the result right after entering a sequence of operations. In the later case, an M-file functions like a program which collects a sequence of instructions. To create an M-file, you can use VI editor, text editor, or other editors available, and store the file with the extension.m, such as, homework.m. To invoke an M-file, simply enter the name, without the extension at the MATLAB prompt, for example, >>homework<cr> More information on these files will be provided later. 2.2 How to Create a Matrix? The easiest way to create a matrix is to explicitly list all the elements of the matrix in brackets [ ]. In the brackets, each element is separated by a blank or comma; each row ends with a semicolon. To create a matrix, say A, we can enter A = [1 0 0; 0 1 0; 0 0 1]<CR> or as the following: A = [1 0 0<CR> 0 1 0<CR> 0 0 1 ]<CR> In addition, you can use the following built-in functions to create a matrix: eye: to create an identity matrix eye(n) creates a n-by-n identity matrix. eye(m,n) creates an m-by-n matrix with ones on the diagonal and zeros elsewhere. eye(size(a)) creates an identity matrix with the same size as matrix A. ones: to create a matrix with all ones as its elements. one(n) creates a n-by-n ones matrix. one(m,n) creates an m-by-n ones matrix. one(size(a)) creates an ones matrix with the same size as matrix A. zeros: to create a matrix with all zeros as its elements. zero(n) creates a n-by-n zeros matrix. zero(m,n) creates an m-by-n zeros matrix. zero(size(a)) creates an zeros matrix with the same size as matrix A. ME 305: System Dynamics Using MATLAB page 2

For example, you can define matrix A as a 3-by-3 identity matrix by entering A=eye(3). You will obtain a matrix A exactly the same as the one you entered before. You can also use linspace, logspace, rand, randn, meshgrid, and so on, to create a matrix. 2.2 How to Create a Vector? To Create a vector simply enter all the elements of the vector in the brackets [ ].In the brackets, each element is separated by a blank or comma. For example, to create a vector, say B, we can enter B = []<CR> 2.2 Some Basic Operators and Important Symbols Assume that A and B are two vectors, say A = 1 2 and B = 3 4, Y is a square matrix, say Y = 1 2, and p is a scalar. 3 4 Arithmetic Operators: Operator Description Usage Operator Description Usage + addition C=A+B C=p+B - subtraction C=A-B C=p-B * matrix multiplication C=A'*B C=A*B' C=p*A.* array multiplication C=A.*B C=p.*A C=A.*p C=A*p / matrix left division (XA=B X=A/B) C=A/B C=A/p./ array left division C=A./B C=p./B \ matrix right division (AX=B X=A\B) C=A\B C=p\A.\ array right division C=A.\B C=p.\B ^ matrix power C=Y^p.^ array power C=A.^B (Y must be a squarec=p^y matrix) C=A.^p C=p.^B ' matrix transpose C=A'.' array transpose C=A.' The dimensions of vectors and matrices are important in these arithmetic operations. You may try C=A*B, C=A'.*B, C=A.*B' and see what you get. ME 305: System Dynamics Using MATLAB page 3

Relational Operators: perform element-by-element comparisons between two matrices of equal dimensions. The result is a matrix of the same size, with elements of ones and zeros. Operator Description Usage Operator Description Usage > greater than A>B >= greater than or equal A>=B < less than A<B <= less than or equal A<=B == equal A==B ~ = not equal A~=B Logical Operators: perform element-by-element operations between two matrices of equal dimensions. The result is a matrix of the same size, with elements of ones and zeros. Operator Description Usage & AND C=A&B OR C=A B ~ NOT C=~A Important Symbols: Symbol Description Usage (or example) % Denotes a comment % This is a comment.! Execute a command available!ls -al<cr> in the operating system : Creates vectors, matrixi:j = [i,i+1,i+2,...,j] subscripts, and for iterations. i:k:j = [i, i+k, i+2k,..., j] C=X(:,j) -> take j-th column as vector C C=X(i,:) -> take i-th row as vector C (Try X(:,:), X(i:j), X(:, i:j), X(i:j,:), X(:)) 3. Complex Numbers for i = 1:10 You can also use complex numbers in MATLAB. In MATLAB, i, j, and sqrt(-1) are the same. Therefore, you can use any of them to express a complex unit, for example, a=3+4i. Similarly, you can create a complex matrix as the following: A = [1 2]+i*[3, 4] or A = [1+3*i, 2+4*i] Notice that there is no blank spaces surrounding + sign. You can also use the operators presented in precious section in complex vectors and matrices. ME 305: System Dynamics Using MATLAB page 4

Solution to Linear Equations To solve linear systems of equations, you can use either direct methods or iterative methods. 1. Direct Methods 1.1 Using Matrix Division Operators Given the following linear system of equations 3x x + 2x = 12 x + 2x + 3x = 11 2x 2x x = 2 The above system can be written as: AX = B, where A is a 3X3 matrix, and X and B are column vectors. We can solve for X = x x x T using the following steps: Step 1: Create matrix A, A=[3-1 2; ; 2-2 -1] Step 2: Create vector B, B=[12; 11; 2] Step 3: Solve for X, X=A\B' 1.2 LU Decomposition You can use this method only when matrix A is a square matrix. The above procedure in the MATLAB utilizes methods similar to Gaussian elimination. MATLAB also has the functions available for LU decomposition. This is slightly different from the formulation in the text-book. To produce two matrices, L, and U using MATLAB, use the following steps (assuming that matrix A is already entered). [L, U] = lu(a) This will print L and U after the execution of this command. The above command utilizes dual assignment capability of the MATLAB, since the function "lu" creates two outputs. Once you have the LU decomposition of matrix A, you can solve AX = B as follows: y = L\B, X = U\y ME 305: System Dynamics Using MATLAB page 5

Learning MATLAB Online When you are within MATLAB on any computer, 1. Type demo at >> prompt. 2. Click on matrices in demowindow. 3. Double click on Basic Matrix operations ( Slideshow player will start) a) Click on start >> and then click on next slide to see the slide show. There are other options like b) Inverse of Matrices c) Graphs and Matrices d) Sparse matrics e) Matrix Manipulation f) Eigen and Singular value show g) Command line demos 4. Type helpwin (Matlab window will open) To know all the general commands, operators. Ex. Double click on matlab/general to know all the general purpose commands Double click on matlab/ops to know all the operators and special characters etc. ME 305: System Dynamics Using MATLAB page 6