Introduction to MATLAB

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
ECEN/MAE 3723 – Systems I MATLAB Lecture 1. Lecture Overview  Introduction and History  Matlab architecture  Operation basics  Visualization  Programming.
CSci 2031: Matlab Tutorial Guoquan (Paul) Huang Jan 24, 2008.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Arrays Revisited Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to MATLAB
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
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.
An Introduction to Scilab Tsing Nam Kiu 丁南僑 Department of Mathematics The University of Hong Kong 2009 January 7.
February 7, 2005 Lecture 7 - By Paul Lin 1 CPET 190 Lecture 7 Problem Solving with MATLAB Paul Lin
MATLAB Basics With a brief review of linear algebra by Lanyi Xu modified by D.G.E. Robertson.
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 Zongqiang Liao Research Computing Group UNC-Chapel Hill.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
EECE 360/460 Matlab Tutorial Jan Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs.
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.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
Basics of MATLAB By DR. Wafaa Shabana
Winter Semester 2014/2015 College of Engineering.
Scientific Computing Introduction to Matlab Programming.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Introduction MATLAB stands for MATrix LABoratory.  Basics  Matrix Manipulations  MATLAB Programming  Graphics  Image types  Image Processing  Useful.
Introduction to MATLAB Session 1 Simopekka Vänskä, THL 2010.
OUTLINE Overview Numbers, variables and similar in Matlab
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Introduction to Matlab By E. Noura Semary. Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
Interduction to MATLAB Manal Alotaibi Mathematics department College of science King saud university.
Introduction to Matlab Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to Matlab
訊號與系統 廖文淵 德霖技術學院資訊工程系 Introduction to MATLAB.
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
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
Introduction to Matlab Engr. Mian Shahzad Iqbal LAB NO.2
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.
전자장 1 실험 - Matlab 사용법 - Photonic Systems Laboratory School of EE, Seoul National University Photonic Systems Lab School of EECS, S.N.U.
NoViC, Dept. of Mechanical Eng Acoustics Lab., NoViC 1. Download Matlab 2.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Matlab Programming for Engineers
Introduction to MATLAB
Matlab Training Session 4: Control, Flow and Functions
L – Modeling and Simulating Social Systems with MATLAB
Lecture: MATLAB Chapter 1 Introduction
Introduction to MATLAB
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
MATLAB stands for MATrix LABoratory.
Introduction to Matlab
Presentation transcript:

Introduction to MATLAB Morris Law Jan 5, 2013

Outline Matlab software Entering matrix Matrix function and manipulation Matlab graphics Matlab programming: writing M-file and functions Function input & output Control flow

MATLAB software Multi-platforms (Windows, Linux, MacOSX) Technical computing Script language Variables are all matrices Expandable by adding toolboxes

Entering matrix Explicit listing M-file External data files Stored the above statement in ex1.m. Run the M-file, i.e. >> ex1 External data files >> load A.dat Built-in statements and functions >> B = eye(3)

Matrix function and manipulation ones(3), zeros(3), eyes(3) magic(4), hilb(5), rand(4,3) size(A), eig(A), det(A), inv(A), diag(A) sum(A), prod(A), mean(A), max(A), std(A)

Exercise on Matrix functions Try A = [1 2 3; 4 5 6; 7 0 9] x = ones(3) y = eye(3) z = zeros(3) d = diag(A) det(A) inv(A) rank(A) eig(A)

Exercise on Matrix functions m = magic(4) sum(m) sum(m’) sum(diag(m)) r = rand(4,3) size(r)

Matrix elements >> x = [-1.3, sqrt(3), (1+2+3)*4/5 ]; -1.3000 >> x(5)= abs(x(1)) x = -1.3000 1.7321 4.8000 0 1.3000 >> y = 1:5 y = 1 2 3 4 5 xy = [x;y] xy = -1.3000 1.7321 4.8000 0 1.3000 1.0000 2.0000 3.0000 4.0000 5.0000

Matrix elements (cont) >> B = [A;r]; >> C = [A,zeros(size(A));ones(size(A)),A] C = 1 2 3 0 0 0 4 5 6 0 0 0 7 8 9 0 0 0 1 1 1 1 2 3 1 1 1 4 5 6 1 1 1 7 8 9 >> D = C(1:3,:) >> D = C(:,3:4)

Matrix Arithmetic Additions (+) Subtraction (-) Multiplication (*) Right division (/) Solve A = xb by x = A/b Left division (\) Solve Ax = b by x = A\b Power (^)

Element-by-Element Operation Using Period (.) x = [1,2,3]; y = [4 5 6]; >> x .* y ans 4 10 18 >> x ./ y 0.25 0.4 0.5 >> x .\ y 4 2.5 2 >> x .^ y ans 1 32 729 >> x .^ 2 1 4 9 >> 2 .^ [x y] 2 4 8 16 32 64

MATLAB graphics If y is a vector, plot(y) produced a linear graph plot(x,y) produces a graph of y versus x t = 0: pi/10: 2*pi; x = sin(t) Y1 = sin(t+.25); Y2 = sin(t+.50); plot(x,y1,’r-’,x,y2,’g--’) Title(‘Phase Shift’) xlabel(‘x=sin(t)’); ylabel(‘y1=sin(t+)’);

MATLAB graphics – 3D mesh The following commands draw a mesh x = [-pi:0.1:pi]; y=x; [X,Y]=meshgrid(x,y); Z = sin(X).* sin(Y) + cos(X).*cos(Y); mesh(Z);

MATLAB programming Two kinds of MATLAB program 1. Script or M-file sequence of Matlab statements without input and output variables are global 2. Functions with input and output defined as function [out1, out2, … outN]= funcname(in1, in2, … inN) variables are local

Writing scripts / M-files Use Matlab M-file editor, save the following as fibo.m % An M-file to calculate Fibonacci numbers f = [1 1]; i=1; while f(i) + f(i+1) < 1000 f(i+2) = f(i) + f(i+1); i=i+1; end plot(f); At the Matlab command prompt, type the following to run >> fibo

Writing script – another example looptest.m % Fill b with square roots of 1 to 1000 using a for loop clear; tic; for i= 1:1000 b(i) = sqrt(i); end t=toc; disp([‘Time taken for loop method is ‘, num2str(t)]); % Fill b with square roots of 1 to 1000 using a vector a = 1:1000; b = sqrt(a); disp([‘Time taken for vector method is ‘, num2str(t)]); Run the program with >> looptest

MATLAB function MATLAB functions allow input and output variables function y = stat(x) % mean average [ m n ] = size(x); if m == 1 m = n; end y = sum(x) / m; If z is a vector, z = 1:99, type >> mean(z) ans 50

Control flow If and break statement For Loops While Loops or for v = expression statements end While Loops while expression If and break statement if expression, break, end or if expression statements [elseif expression statements] [else expression end

General Purpose commands (1/5) Managing commands and functions demo run demo help on line documentation Info information about MATLAB and MathWorks lookfor keyword search through the help entries path control MATLAB's search path type list M-file what directory listing of M-, MAT- and MEX-files which locate functions and files

General Purpose commands (2/5) Managing variables and the workspace clear clear variables and functions from memory disp display matrix or text length length of vector load retrieve variables from disk pack consolidate workspace memory save save workspace variables to disk size size of matrix who list current variables whos list current variables, long form

General Purpose commands (3/5) Working with files and the operating system cd change current working directory delete delete file diary save text of MATLAB session dir directory listing getenv get environment value ! execute operating system command

General Purpose commands (4/5) Controlling the command window clc clear command window echo echo commands inside script files format set output format home send cursor home more control paged output in command window

General Purpose commands (5/5) Starting and quitting from MATLAB matlabrc master startup M-file quit terminate MATLAB startup M-file executed when MATLAB is invoked

Search for documentation helpdesk http://www.mathworks.com

Reference Booklet on Introduction to MATLAB MATLAB primer (version 3)