Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square

Similar documents
! The MATLAB language

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.

MATLAB. The Language of Technical Computing. Getting Started with MATLAB Version 5. Computation. Visualization. Programming

A Brief MATLAB Tutorial

MATLAB = MATrix LABoratory. Interactive system. Basic data element is an array that does not require dimensioning.

Introduction to MATLAB

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

Getting started with MATLAB

Introduction to Matlab

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

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

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

MATLAB. The Language of Technical Computing. Getting Started with MATLAB Version 7

Finding, Starting and Using Matlab

Introduction to MATLAB

MATLAB Primer. R2016b

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

Lecturer: Keyvan Dehmamy

MATLAB 7 Getting Started Guide

Introduction to Matlab

2.0 MATLAB Fundamentals

Introduction to MATLAB

Introduc)on to Matlab

Eng Marine Production Management. Introduction to Matlab

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Introduction to MATLAB

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

HERIOT-WATT UNIVERSITY DEPARTMENT OF COMPUTING AND ELECTRICAL ENGINEERING. B35SD2 Matlab tutorial 1 MATLAB BASICS

Chapter 1 Introduction to MATLAB

MATLAB 7 Getting Started Guide

Dr Richard Greenaway

Matlab Tutorial and Exercises for COMP61021

Lab #1 Revision to MATLAB

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

Basic Graphs. Dmitry Adamskiy 16 November 2011

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

An Introduction to MATLAB II

Computer Programming in MATLAB

Matlab Tutorial for COMP24111 (includes exercise 1)

Getting Started with MATLAB 7

What is Matlab? A software environment for interactive numerical computations

Computational Photonics, Seminar 01 on Introduction into MATLAB, Page 1

Getting Started with MATLAB 7

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

Introduction to MATLAB Practical 1

Introduction to MATLAB

Introduction to MATLAB

A Quick Tutorial on MATLAB. Zeeshan Ali

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

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

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

Mechanical Engineering Department Second Year (2015)

What is MATLAB? It is a high-level programming language. for numerical computations for symbolic computations for scientific visualizations

Chapter 2. MATLAB Fundamentals

Introduction to Engineering gii

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

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

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

Introduction to MATLAB

Dr. Nahid Sanzida b e. uet .ac.

QUICK INTRODUCTION TO MATLAB PART I

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

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

General Information. There are certain MATLAB features you should be aware of before you begin working with MATLAB.

MATLAB BASICS. M Files. Objectives

AN INTRODUCTION TO MATLAB

MATLAB is a multi-paradigm numerical computing environment fourth-generation programming language. A proprietary programming language developed by

ECE Lesson Plan - Class 1 Fall, 2001

Matlab Tutorial, CDS

Matlab Introduction. Scalar Variables and Arithmetic Operators

Scientific Computing Lecture Series Introduction to MATLAB Programming

Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany

1 Introduction to MATLAB

A General Introduction to Matlab

Stokes Modelling Workshop

PART 1 PROGRAMMING WITH MATHLAB

Introduction to Unix and Matlab

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

Lecture 2 Introduction to MATLAB. Dr.Tony Cahill

What is MATLAB and howtostart it up?

Introduction to MATLAB

Introduction to MATLAB

Quick introduction to Matlab. Edited by Michele Schiavinato

MATH 2221A Mathematics Laboratory II

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

University of Alberta

1 Introduction to MATLAB

Introduction to MATLAB Programming

Prepared by: Khairul Anuar Ishak Department of Electrical, Electronic & System Engineering Faculty of Engineering Universiti Kebangsaan Malaysia

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Evolutionary Algorithms. Workgroup 1

Lecture 1: What is MATLAB?

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Matlab Notes. Dayalbagh Educational Institute. From the SelectedWorks of D. K. Chaturvedi Dr. D. K. Chaturvedi, Dr., Dayalbagh Educational Institute

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Transcription:

Matlab Lecture 1 - Introduction to MATLAB Five Parts of Matlab MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-touse environment. Typical uses include: Math and computation Algorithm development Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar non-interactive language such as C or Fortran. The MATLAB language High-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features The MATLAB working environment Facilities for managing the variables and importing and exporting data Tools for developing, managing, debugging, and profiling M-files Handle Graphics Two-dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics Graphical User Interface functions The MATLAB mathematical function library The MATLAB Application Program Interface (API) Allows you to write C and Fortran programs that interact with MATLAB Lecture 1-1 Lecture 1-2 Entering Matrices (1) - Magic Square Entering Matrices (2) - Method 1:Direct entry 4 ways of entering matrices in MATLAB: 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 Rules of entering matrices: Separate the elements of a row with blanks or commas Use a semicolon ; to indicate the end of each row Surround the entire list of elements with square brackets, [ ] To enter Dürer's matrix, simply type:» A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1] Engraving by Albrecht Dűrer, German artist and mathematician in 1514. MATLAB displays the matrix you just entered, A = 16 3 2 13 5 10 11 8 9 6 7 12 4 15 14 1 No need to define or declare size of A Lecture 1-3 Lecture 1-4

Entering Matrices (3) - as lists Entering Matrices (4) - subscripts Why is this a magic square? Try this in Matlab :- Result in row vector variable ans Result in cloumn vector variable ans» sum(a) ans ans =» A A ans ans = 16 16 5 9 4 3 10 10 6 15 15 2 11 11 7 14 14 13 13 8 12 12 1» sum(a ) Compute the sum of each column in A Transpose matrix A Compute the sum of each row in A A(i,j) refers to element in row i and column j of A :- row col» A(4,2) ans ans = 15 15» A(1,4) + A(2,4) + A(3,4) + A(4,4)» X = A; A;» X(4,5) = 17 17 X = 16 16 3 2 13 13 0 5 10 10 11 11 8 0 9 6 7 12 12 0 4 15 15 14 14 1 17 17 Slow way of finding sum of column 4 Make another copy of A in X ; suppress output Add one element in column 5, auto increase size of matrix Lecture 1-5 Lecture 1-6 Entering Matrices (5) - colon ; Operator Expressions & built-in functions ; used to specify range of numbers start end» 1:10 1:10 ans ans = 1 2 3 4 5 6 7 8 9 10 10» 100:-7:50 incr ans ans = 100 100 93 93 86 86 79 79 72 72 65 65 58 58 51 51» 0:pi/4:pi ans ans = 0 0.7854 1.5708 2.3562 3.1416 First k elements of the j th column in A Short-cut for all rows» A(1:k,j);» sum(a(1:4,4))» sum(a(:,end)) 0 to pi with incr. of pi/4 last col Elementary functions» rho rho = (1+sqrt(5))/2 rho rho = 1.6180 Complex number» a = abs(3+4i) a = 5 Special functions» z = sqrt(besselk(4/3,rho-i)) z = 0.3730+ 0.3214i Built-in constants (function) pi pi 3.14159265 3.14159265» huge huge = exp(log(realmax)) I huge huge = 1.7977e+308 or or j Imaginary Imaginary unit, unit, -1-1 eps eps FP FP relative relative precision, precision, 2-52 -52» toobig = pi*huge realmin realmin Smallest Smallest FP FP number, number, 2-1022 toobig = Inf Inf realmax realmax Largest Largest FP FP number, number, (2-)2 (2-)2 1023 Inf Inf Infinity Infinity NaN NaN Not-a-number Not-a-number Lecture 1-7 Lecture 1-8

Entering Matrices (6) - Method 2: Generation Entering Matrices (7) - Method 3 & 4: Load & M-File» Z = zeros(2,4) Z = 0 0 0 0 0 0 0 0 Useful Useful Generation Functions» F = 5*ones(3,3) Zeros Zeros All All zeros zeros F = 5 5 5 5 5 5 ones ones All All ones ones 5 5 5 rand rand Uniformly distributed random elements between (0.0, (0.0, 1.0) 1.0)» N = fix(10*rand(1,10)) randn N = 4 9 4 4 8 randn Normally... distributed random... elements, mean mean = 0.0, 0.0, var var = 1.0 1.0» R = randn(4,4) R = 1.0668 0.2944 0.6918-1.4410 0.0593-1.3362 0.8580 0.5711-0.0956 0.7143 1.2540-0.3999-0.8323 1.6236-1.5937 0.6900» magik magik magik.dat 16.0 3.0 2.0 13.0 5.0 10.0 11.0 8.0 9.0 6.0 7.0 12.0 4.0 15.0 14.0 1.0.m files can be run by just typing its name in Matlab» load load magik.dat Read data from file into variable magik Three dots ( ) means continuation to next line magik.m A = [... 16.0 3.0 2.0 13.0 5.0 10.0 11.0 8.0 9.0 6.0 7.0 12.0 4.0 15.0 14.0 1.0}; Lecture 1-9 Lecture 1-10 Entering Matrices (8) - Concatenate & delete Command Window» B = [A [A A+32; A+32; A+48 A+48 A+16] A+16] B = 16 16 3 2 3 48 48 35 35 45 45 5 10 10 11 11 8 37 37 42 42 43 43 40 40 9 6 7 12 12 41 41 38 38 39 39 44 44 4 15 15 14 14 1 36 36 47 47 46 46 33 33 64 64 51 51 50 50 61 61 32 32 19 19 18 18 29 29 53 53 58 58 59 59 56 56 21 21 26 26 27 27 24 24 57 57 54 54 55 55 60 60 25 25 22 22 23 23 28 28 52 52 63 63 62 62 49 49 20 20 31 31 30 30 17 17» X = A; A;» X(:,2) = [] [] X = 16 16 2 13 13 5 11 11 8 9 7 12 12 4 14 14 1 2nd column deleted ctrl-p ctrl-p Recall Recall previous previous line line ctrl-n ctrl-n Recall Recall next next line line ctrl-b ctrl-b Move Move back back one one character character ctrl-f ctrl-f Move Move forward forward one one character character ctrl ctrl -- ctrl-r ctrl-r Move Move right right one one word word ctrl ctrl -- ctrl-l ctrl-l Move Move left left one one word word home home ctrl-a ctrl-a Move Move to to beginning beginning of of line line end end ctrl-e ctrl-e Move Move to to end end of of line line esc esc ctrl-u ctrl-u Clear Clear line line del del ctrl-d ctrl-d Delete Delete character character at at cursor cursor backspace backspace ctrl-h ctrl-h Delete Delete character character before before cursor cursor ctrl-k ctrl-k Delete Delete to to end end of of line line Lecture 1-11 Lecture 1-12

MATLAB Graphics(1) - Creating a Plot MATLAB Graphics(2) - Mesh & surface plots» t = 0:pi/100:2*pi;» y = sin(t);» plot(t,y)» grid grid» axis([0 2*pi 2*pi -1-1 1]) 1])» xlabel('0 \leq \leq \itangle \leq \leq \pi') \pi')» ylabel('sin(t)')» title('graph of of the the sine sine function')» text(1,-1/3,'\it{demonstration of of plotting}')» [X,Y] [X,Y] = meshgrid(-8:.5:8);» R = sqrt(x.^2 + Y.^2) Y.^2) + eps; eps;» Z = sin(r)./r;» mesh(x,y,z)» text(15,10,'sin(r)/r')» title('demo of of 2-D 2-D plot'); Lecture 1-13 Lecture 1-14 MATLAB Graphics(3) - Subplots» t = 0:pi/10:2*pi;» [X,Y,Z] = cylinder(4*cos(t));» subplot(2,2,1); mesh(x)» subplot(2,2,2); mesh(y)» subplot(2,2,3); mesh(z)» subplot(2,2,4); mesh(x,y,z) MATLAB Graphics(3) - Subplots Matlab official method: generate encapsulated postscript files -» print -depsc2 mesh.eps My method:- Use <PrintScreen> key (top right corner) to capture the plot on screen Use MS Photo Editor or similar bit-map editing program to cut out the the plot that I want Paste it into MS Word or MS PowerPoint or save it as.bmp/.gif file Resize as necessary Fit as many as required on page Type written description (or report) if needed Print document to any printer (not necessarily postscript printer) Lecture 1-15 Lecture 1-16

MATLAB Help and Online Tutorial Web-based MATLAB Help & Documentation» helpwin Click Click here here for for HTML HTML based based help help Double click click on on matlab\lang Lecture 1-17 Lecture 1-18 MATLAB Environment (1) MATLAB Environment (2) Managing Commands and Functions addpath Add directories to MATLAB's search path help Online help for MATLAB functions and M-files path Control MATLAB's directory search path Working with Files and the Operating Environment cd Change working directory delete Delete files and graphics objects diary Save session in a disk file Managing Variables and the Workspace clear Remove items from memory length Length of vector dir edit! Directory listing Edit an M-file Execute operating system command load Retrieve variables from disk save Save workspace variables on disk size Array dimensions who, whos List directory of variables in memory Lecture 1-19 Lecture 1-20