A Brief Introduction to MATLAB

Similar documents
Introduction to MATLAB Practical 1

Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

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

Laboratory 1 Octave Tutorial

Introduction to Matlab

Desktop Command window

Stokes Modelling Workshop

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

Introduction to Engineering gii

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

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

What is Matlab? A software environment for interactive numerical computations

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c.

Introduction to Matlab

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

George Mason University ECE 201: Introduction to Signal Analysis Spring 2017

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

LAB 1: Introduction to MATLAB Summer 2011

MATLAB/Octave Tutorial

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

Math 2250 MATLAB TUTORIAL Fall 2005

Introduction to GNU-Octave

MAT 275 Laboratory 1 Introduction to MATLAB

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

Matlab Tutorial and Exercises for COMP61021

INTRODUCTION TO MATLAB, SIMULINK, AND THE COMMUNICATION TOOLBOX

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

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

MATLAB Tutorial. Primary Author: Shoumik Chatterjee Secondary Author: Dr. Chuan Li

MATLAB. Input/Output. CS101 lec

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below.

ME 121 MATLAB Lesson 01 Introduction to MATLAB

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

1-- Pre-Lab The Pre-Lab this first week is short and straightforward. Make sure that you read through the information below prior to coming to lab.

Computer Programming in MATLAB

PHYS 210: Introduction to Computational Physics MATLAB Exercises 2

How to learn MATLAB? Some predefined variables

Introduction to Python Practical 1

The value of f(t) at t = 0 is the first element of the vector and is obtained by

Programming in Mathematics. Mili I. Shah

An Introduction to MATLAB II

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

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

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.

An Introductory Tutorial on Matlab

GEORGIA INSTITUTE OF TECHNOLOGY. SCHOOL of ELECTRICAL and COMPUTER ENGINEERING. ECE 2026 Summer 2018 Lab #0: Introduction to MATLAB

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

What is MATLAB and howtostart it up?

Introduction to MATLAB LAB 1

Introduction to MATLAB

2.0 MATLAB Fundamentals

AMS 27L LAB #2 Winter 2009

Grace days can not be used for this assignment

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

Introduction to MATLAB

CSE/Math 485 Matlab Tutorial and Demo

A Short Introduction to Matlab

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

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

Lab P-1: Introduction to MATLAB. 3. Learn a little about advanced programming techniques for MATLAB, i.e., vectorization.

LAB 1 General MATLAB Information 1

Introduction to MATLAB

Lecturer: Keyvan Dehmamy

Assignment :1. 1 Arithmetic Operations : Compute the following quantities ) -1. and compare with (1-

DSP First. Laboratory Exercise #1. Introduction to MATLAB

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Introduction to Matlab

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

A very brief Matlab introduction

1 Introduction to Matlab

Matlab Tutorial for COMP24111 (includes exercise 1)

EE 350. Continuous-Time Linear Systems. Recitation 1. 1

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

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

A GUIDE FOR USING MATLAB IN COMPUTER SCIENCE AND COMPUTER ENGINEERING TABLE OF CONTENTS

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

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

An Introduction to MATLAB. Lab tutor : Dennis Yang LIU Lab 1: Sept. 11, 2014

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

PART 1 PROGRAMMING WITH MATHLAB

A Guide to Using Some Basic MATLAB Functions

Mechanical Engineering Department Second Year (2015)

Lab. Manual. Practical Special Topics (Matlab Programming) (EngE416) Prepared By Dr. Emad Saeid

Dr Richard Greenaway

Matlab Tutorial: Basics

Getting To Know Matlab

Introduction to MATLAB

AMS 27L LAB #1 Winter 2009

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

A Tour of Matlab for Math 496, Section 6

General MATLAB Information 1

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

Introduction to MATLAB for CSE390

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

Introduction to MATLAB

16.06/16.07 Matlab/Simulink Tutorial

PC-MATLAB PRIMER. This is intended as a guided tour through PCMATLAB. Type as you go and watch what happens.

EEE161 Applied Electromagnetics Laboratory 1

Transcription:

A Brief Introduction to MATLAB MATLAB (Matrix Laboratory) is an interactive software system for numerical computations and graphics. As the name suggests, MATLAB was first designed for matrix computations: solving systems of linear equations, computing eigenvalues and eigenvectors of matrices, factoring matrices, and so on. Throughout the years, it has become a computer language for technical computing. It has a variety of computational and graphical capabilities. MATLAB is installed locally on each PC in Computer Labs: Thompson 215 and Thompson 220. TostarttheMATLABprogram,clickonStart All Program MATLAB R2011b (or MATLAB R2014). You will see the following screen with three windows. (It may take a while for MATLAB to be up and run, so please be patient.) The one at the top left is Current Directory, the bottom left is Command History and the one at the right is Command Window. If you click on Desktop on the toolbar, you see these three are marked. You can unmark any of them if you want to close it. On the toolbar, next to Current Directory, type in directory (or your flash-drive) where your files will be (or are). A list of files under that directory should be shown in the Current Directory window on the left. At the top of the Command Window, it lists Video, Demos and Getting Started. Check out these tutorials to learn more about MATLAB. Let us go through some basic MATLAB commands. 1. To Quit To quit from MATLAB, type "quit" at the MATLAB prompt, i.e. quit (enter) 1

2. Help: Type help with a command or a name of an MATLAB build-in function to see its description. For example, help log YoucanalsoclickonHelpontoolbartogetmorehelp. 3. Using MATLAB as a calculator MATLAB can be used as an expression evaluator. To do this you simply type a mathematical expression after the MATLAB prompt. For example, we want to evaluate pi (enter) Now You see: ans 3.1416. If you need more decimal digits, type format long and then press the enter key. Now type in pi again. formate long pi 3.14159265358979 Type format short to return back to the 5 decimal digits display. pi is a built-in MATLAB variable. Try more examples: sin(pi/4) 2^(log2(4)) sqrt(9) 8^(1/3) 4. Assigning Values to Variables MATLAB allows you create variables. For example, x 5; y pi/4; z y sqrt(x) z 3.02146614089724 From this point on, x 5, y 4 and z 4 5 until you replace them. Use who command to list the currently active variables. who Your variables are: ans x y z Note that with having ";" at the end of a command, there will not be a display of the value of the variable after you press "enter". 5. Built-in Functions MATLAB has many built-in functions. For example, (try them to see what you get) abs(-1) sin(pi/2) cos(pi/3) 2

tan(pi/4) exp(0.2) atan(1) log(exp(1)) log2(4) Guess and try a function yourself. How does it work? After you use MATLAB for a while, you can guess some commands. 6. Operations (1) Operations:,,. /,^ Try the following. 2^(1/2)-sqrt(2) 3*exp(-1/2)*sin(pi/3) 2*log(3) (2) Dot operations:.,./,.^ Each operation listed in (1) can operate on vectors and matrices by adding a dot (.) in front of it. Here are examples. Example 1: Build 6 column vectors. x [1;1;2;3;5;8]; y 2*x; z x.*x; w x.^3; u x./5; v x./x; [xyzwuv] ans 1.0000 2.0000 1.0000 1.0000 0.2000 1.0000 1.0000 2.0000 1.0000 1.0000 0.2000 1.0000 2.0000 4.0000 4.0000 8.0000 0.4000 1.0000 3.0000 6.0000 9.0000 27.0000 0.6000 1.0000 5.0000 10.0000 25.0000 125.0000 1.0000 1.0000 7. Set up and Plot Data Matrix (Arrays): a. Graph a function: Example: Graph y sin x e x x 2 1, for x. x -pi:0.1:pi; (Note: x is a row vector that contains values: -pi, -pi 0.1, -pi 0.2,...,pi, with adding ";" at the end, elements of the vector x will not be displayed). y x.*sin(x)-exp(-x) x.^2 1; plot(x,y) Though y is continuous function of x, only finite many points are plotted. MATLAB makes a smooth connection between two points. Type Help plot to learn more about line and point formats for plot. 3

b. Set up a data matrix: If we have a table of data: (Example 1 on Page 11) 9.6 8.7 18.3 10.7 20.0 18.2 47.2 23.9 71.1 48.0 119.1 55.5 174.6 82.7 now we want to load data in a matrix labeled A. In MATLAB, select File New Script. An Editor window is opened: Type in the data (or copy/paste from a text file). Add "A [" at the beginning of the file and "];" at the end. Now save the file as data1.m. Make sure the m-file is saved in the directory that is listed at the Current Directory. Then in the Command Window, we type in data1 (without.m), and check to see if the matrix A is definite: data1 A 1.0e 002 * 0.096000000000000 0.087000000000000 0.183000000000000 0.107000000000000 0.200000000000000 0.182000000000000 0.472000000000000 0.239000000000000 4

0.711000000000000 0.480000000000000 1.191000000000000 0.555000000000000 1.746000000000000 0.827000000000000 To plot the 2nd column of A vs. the 1st column of A: clf (comment: clear the screen) plot(a(:,1),a(:,2), b* ) hold on plot(a(:,1),0.5*a(:,2), r- ) hold off Go to the Figure Window, you should see the following graph: 8. Programs - MATLAB m-files: Select File New Script, type in % Example 2 - Section 1.2 % clear clf data1 nv 1:1:18; nv nv ; B A2(:,1); subplot(3,1,1),plot(nv,b(1:18,1), b* ) xlabel( n ) ylabel( pn ) for i 1:18 B(i,2) B(i 1,1)-B(i,1); end 5

subplot(3,1,2),plot(b(1:17,2),b(1:17,1), r* ) xlabel( pn ) ylabel( pn 1-pn ) for i 1:18 B(i,3) B(i,1)*(665-B(i,1)); end subplot(3,1,3),plot(b(1:17,3),b(1:17,2), k* ) xlabel( pn(665-pn) ) ylabel( pn 1-pn ) save as an m-file: Ex2_1_2.m Ex2_1_2 6