INTRODUCTION TO MATLAB. Padmanabhan Seshaiyer

Size: px
Start display at page:

Download "INTRODUCTION TO MATLAB. Padmanabhan Seshaiyer"

Transcription

1 INTRODUCTION TO MATLAB First Steps You should start MATLAB by simply typing matlab if you are working on a Unix system or just by double clicking the MATLAB icon if you are using a Windows based system. If all goes well you will see a MATLAB prompt >> inviting you to initiate a calculation. In what follows, any line beginning with >> indicates typed input to MATLAB. You are expected to type what follows by not the >> prompt itself. MATLAB supplies that automatically. Arithmetic with MATLAB MATLAB understands the basic arithmetic operations: +, -, *, /. Powers are indicated with ^, thus typing >> 5*4 + 3^2 and pressing enter, results in 29 The laws of precedence are built in but if in doubt, you should put parentheses appropriately. For example, >> 7+3*(2/(8-2)) 8 The sort of elementary functions familiar on hand calculators are also available. For example, >> sqrt(3^2+4*4) 5 >> exp(log(3.2)) 3.2

2 Using Variables You can assign numerical values to variables for use in subsequent calculations. For example the volume of a sphere can be calculated via the following sequence: >> radius = 3; >> volume=(4/3)*pi*radius^3 volume = Note that the first line did not seem to produce a result in screen. When MATLAB encounters an instruction followed by a semi-colon ; it suppresses any visual confirmation. It really does obey the instruction and records the value of the variable in the memory. This is useful if you want to avoid cluttering up the screen with intermediate results. Each variable must somehow be assigned before you make use of it in further calculations. For example if you have followed the above example with, >> x=4*pi*radius*h you should get the result,??? Undefined function or variable 'h' This is self-explanatory. If you now type >> h=3; >> x=4*pi*radius*h you should have more success. Incidentally, a quick way of repeating a previous MATLAB instruction is to press the up-arrow key until you recover the command you need. You may also use the sideways arrows to modify any of the previous commands. At any point typing the command, >> who tells about all the variables that are in the workspace of the current MATLAB session. Vectors A vector can be input in several ways. For example, >> u=[1 3 5]; >> v=[1,3,5]; >> w=1:2:5; All three commands above yield the same vector. One can perform vector operations such as, >> z=u+v-w;

3 Note that the vectors described so far are row vectors. To get a corresponding column vector, we invoke the transpose of a vector. For example, >> u The difference between the vectors u and u can be understood by typing the commands >> size(u) >> size(u ) which yields the row size followed by the column size for each vector. One can now multiply vectors appropriately to either yield an innerproduct >> z=u*u or a matrix, >> z=u *u Multiplication of vectors only happens if the inner matrix dimensions agree. For example, >> u*u would yield,??? Error using ==> * Inner matrix dimensions must agree. Suppose we want a set of values z given by z = u 2 then we want >> z = u.*u; where the. is inserted before the * symbol which forces an element-by-element operation. Similarly u./v and u.^3 can be understood to be the corresponding element-by-element operations. Example: Suppose we want to find the distance between two points A and B whose position vectors are given by a = (1, 2) and b = (5, 5) respectively. The following sequence of commands can be executed in MATLAB to obtain the desired result: >> a=[1 2]; >> b=[5 5]; >> d = b a; >> dd = d*d ; >> dist_ab = sqrt(dd)

4 Script Files Now suppose we want to modify the position vectors and find the distance between the new coordinates, it will not be worthwhile to type all the commands again. Instead one can create a script file, which will contain all the necessary information. To create a new script file, one can open their favorite text editor and type the following commands, % dist_ab.m % Calculates distance between any two position vectors a and b d=b-a; dd=d*d ; dist_ab=sqrt(dd) Save these contents in a file named dist_ab.m and note that the script file has a.m extension which denotes that it is a MATLAB file. Now one can pick values for the vectors a and b by simply typing say, >> a=[1 2 3]; >> b=[5 5 3]; Then find the distance by simply typing >> dist_ab dist_ab = 5 This program can be called repeatedly to find the distance between any two position vectors that are entered by the user. Function Files It was tedious to have to assign the two vectors each time before using the above script file. One can combine the assignment of input values with the actual instruction, which invokes the script file by using a function m-file. Not only that, but also one can at the same time assign the answer to an output variable. To create a new function file, one can open their favorite text editor and type the following commands,

5 % distfn.m % Calculates the distance between two vectors a and b % Input: a, b (position vectors) % Output: dist_ab is the distance between a and b function dist_ab = distfn(a, b) d= b a; dd = d*d ; dist_ab = sqrt(dd); Save these contents in a file named distfn.m and we should now be able to run, >> dist_ab=distfn([1 2 3], [ 5 5 3]) or >> a=[1 2 3]; >> b=[5 5 3]; >> dist_ab=distfn(a, b); To save a certain part of the work in the MATLAB session, one can type, >> diary work1 >>. >>. >> diary off All the work between the diary commands will be saved into a file called work1. Homework: Create a function file to deduce the maximum length of the side of a triangle ABC whose position vectors are given by a, b, c. One of the most useful commands in MATLAB is the help command. For e.g., you can type, >> help sin >> help sqrt and so on. Also note that, >> help distfn would return the comments that were entered at the beginning of the program written in the session.

6 Matrices To define a matrix you start with its name. Square brackets are used to begin and each matrix. You can separate elements with a space or a comma, and each row with a semi-colon like this: >> A = [1, 2, -6; 7, 5, 2; -2, 1, 0] or this: >> A = [1 2-6; 7 5 2; ] In either case you have defined the same 3 by 3 matrix named A and you can use it at any time in a calculation or to define another matrix by using its name (A). Examples: >> B = [2-4 7 ] B is a 1 by 3 row matrix >> C = [2; -4; 7; ] C is a 3 by 1 column matrix >>D = [5, 8,-2; 3,-4, 5] D is a 2 by 3 matrix You can edit individual elements of a matrix as follows: >> A(1,1) = -5 changes the element in row1 column1 of matrix A to -5 >> D(2,3) = 0 changes the element in row2 column3 of matrix D to 0 To perform operations on matrices you use the symbols ( +, -, * ) from the number keypad or above the numbers across the top of the keyboard.

7 Examples: >> A + A adds the matrix A to itself. >> B * C multiplies B and C >> C*B - A A is subtracted from the product of C and B The symbol ^ (above the number 6) is used to raise a matrix to an exponent as follows: >> A^3 cubes the matrix A (you might also use A*A*A for the same calculation) >> C*D an error message is displayed Matlab will give an error message when the calculation cannot be done because of a dimension mismatch. To solve the system of equations for (x, y, z) using Gaussian Elimination: a x + b y + c z = u e x + f y + g z = v p x + q y + r z = w we perform the following steps in matlab. >> A = [a b c; e f g; p q r]; >> b = [u; v; w]; >> M = [A b]; >> R = rref(m); >> X = R(4, 1:3);

8 More helpful MATLAB commands: quit or exit either of these closes the program and s your matlab session. save filename this command will save all variables (and ONLY the variables - NOT the whole session) that you have defined in the current session. This is helpful when you enter large matrices that you want to work with at a later date. load filename this command loads the variables that you saved in a previous session. lpr this is the command used to print your diary file. EXIT THE MATLAB PROGRAM. At the osf1 prompt, type: lpr -Pst220 filename (note: st220 is the printer in ST I room 220. At other locations you will use another printer name after the -P ) who why displays variables you have defined in your current session matlab answers the question.(again and again) clear clears all variables from your current session. Only use this command if you want to lose everything. % this is used for comments. Matlab ignores any line that begins with % Matlab has many built in matrix functions and operators. I have listed some here that you may find useful: >> size(a) gives the dimension of the matrix A >> inv(a) calculates the inverse of the matrix A, if it exists. >> det(a) calculates the determinant of the matrix A >> rref(a) calculates the row reduced echelon form of the matrix A >> A' forms the transpose of the matrix A. >> eye (2,2) this is the 2 by 2 identity >> zeros (3,3) builds the zero matrix of any dimension >> ones (3,2) fills a matrix of any size with ones. >> rats(a) displays elements of the matrix A as fractions >> format long displays all numbers with 15 digits instead of the usual 4 digits

9 Some useful built-in functions: Elementary trigonometric functions and their inverses sin, cos, tan, sec, csc, cot, asin, acos, atan, asec, acsc, acot Elementary hyperbolic functions and their inverses sinh, cosh, tanh, sech, csch, coth, asinh, acosh, atanh, asech, acsch, acoth Basic logarithmic and exponentiation functions log, log2, log10, exp, sqrt, pow Basic Statistical functions max, mean, min, median, std, var, sum Basic complex number functions imag, real, i, j, abs, angle, cart2pol Basic data analysis functions fft, ifft, interpn, spline, diff, del2, gradient Basic logical functions and, or, xor, not, any, all, isempty, is* Basic polynomial operations poly, roots, residue, polyfit, polyval,conv Function functions that allows users to manipulate mathematical expressions feval, fminbnd, fzero, quad, ode23, ode45, vectorize, inline, fplot, explot Basic matrix functions zeros, ones, det, trace, norm, eig Try the following: >> f='2+cos(x)'; >> f=inline(f); >> fplot(f,[0,2*pi]) >> x=fzero(inline('cos(x)','x'),1)

10 Plotting Basics Suppose we wish to plot the graph y=x 2 in the interval [-1, 1], then just type, >> x = -1:0.1:1 >> y=x.*x >> plot(x,y) Note that the axes are automatically chosen to suit the range of variables used. One can add more features to the plot using the following commands: >> title( Graph of y=x^2 ) >> xlabel( x ) >> ylabel( y ) Suppose now we want to plot the graphs y 1 =x 2 and y 2 =2x on the same figure, we need, >> y1=x.*x; >> y2=2*x; >> plot(x,y1) >> hold on >> plot(x,y2, ro ) Note that the hold on command tells MATLAB to retain the most recent graph so that a new graph can be plotted. Note that axes are adjusted and the second curve is plotted with a red circle. More options on the choice for the color and symbol can be found by typing, >> help plot Suppose we want to plot the graphs y 1 =x 2 and y 2 =2x on the same figure but partitioned into two subplots then we say, >> subplot(2,1,1) >> plot(x,y1) >> subplot(2,1,2) >> plot(x,y2) One must now be able to employ the various plotting commands in various combinations to get the desired figure.

11 Conditional Statements: for Loops: This allows a group of commands to be repeated a fixed, predetermined number of times. The general form of a for loop is: for x = array Commands End For example, >> for n=1:10 x(n)=sin(n*pi/10); yields the vector x given by, >> x x = Columns 1 through Columns 8 through Let us now use the for loop to generate the first 15 Fibonacci numbers 1,1,2,3,5,8, >> f=[1 1]; >> for k=1:15 f(k+2) = f(k+1) + f(k); >> f

12 while Loops This evaluates a group of commands an infinite number of times unlike the for loop that evaluates a group of commands a fixed number of times. The general form for while loop is while expression Commands For example to generate all the Fibonacci numbers less than 1000, we can do the following: >> f=[1 1]; >> k=1; >> while f(k) < 1000 f(k+1) = f(k+1) + f(k); k = k +1; >> f

13 if-else- Construct There are times when a sequence of commands must be conditionally evaluated based on a relational test. This is done by the if-else- construct whose general form is, if expression Commands For example if we want to give 20% discount for larger purchases of oranges, we say, >> oranges=10; % number of oranges >> cost = oranges*25 % Cost of oranges cost = 250 >> if oranges > 5 cost = (1-20/100)*cost; >> cost cost = 200 If there are more conditions to be evaluated then one uses the more general if-else- construct given by, if expression Commands evaluated if True else Commands evaluated if False

14 switch-case Construct This is used when sequences of commands must be conditionally evaluated based on repeated use of an equality test with one common argument. In general the form is, switch expression case test_expression1 Commands_1 case test_expression2 Commands_2.. otherwise Commands_n. Let us now consider the problem of converting entry in given units to centimeters. % centimeter.m % This program converts a given measument into the equivalent in cms % It illustrates the use of SWITCH-CASE control flow function y=centimeter(a,units) switch units % convert A to cms case {'inch','in'} y = A*2.54; case {'feet','ft'} y = A*2.54*12; case {'meter','m'} y = A*100; case {'centimeter','cm'} y = A; otherwise disp(['unknown units: ' units]) y = nan; %% stands for not a number

15 Character Strings: In MATLAB, these are arrays of ASCII values that are displayed as their character string representation. For example: >> t = Hello t = Hello >> size(t) 1 5 A character string is simply text surrounded by single quotes. Each character in a string is one element in the array. To see the underlying ASCII representation of a character string, you can type, >> double(t) The function char provides the reverse transformation: >> char(t) hello Since strings are numerical arrays with special attributes, they can be manipulated just like vectors or matrices. For example, >> u=t(2:4) u = ell >> u=t(5:-1:1) u = olleh >> u=t(2:4) u = e l l One can also concatenate strings directly. For instance,

16 >> u= My name is ; >> v= Mr. MATLAB ; >> w=[u v] w = My name is Mr. MATLAB The function disp allows you to display a string without printing its variable name. For example: >> disp(w) My name is Mr. MATLAB In many situations, it is desirable to embed a numerical result within a string. The following string conversion performs this task. >> radius=10; volume=(4/3)*pi*radius^3; >> t=[ A sphere of radius num2str(radius) has volume of num2str(volume). ]; >> disp(t) It may sometimes be required to find a certain part of a longer string. For example, >>a= Texas Tech University ; >>findstr(a, ) %% Finds spaces >>findstr(a, Tech ) %% Finds the string Tech ans 7 >>findstr(a,'te') %% Finds the string starting with Te 1 7 >>findstr(a, tech ) %% This command is case-sensitive [ ] If it is desired to replace all the case on Tech to TECH then one can do this by using, >>strrep(a, Tech, TECH ) Texas TECH University

17 Relational Operators: These include the operators < <= > >= == ~= These operators can be used to compare two arrays of the same size, or to compare an array to a scalar. For example: >> A=1:5, B=5-A A = B = >> g=a>3 g = finds elements of A that are greater than 3. Zeros appear in the result where this condition is not satisfied and ones appear where it is. >> for n=2:6 if rem(n,2)~=0 n n = 3 n = 5

18 Logical Operators: The three main logical operators are: AND, OR, NOT which are represented by the symbols &,, ~ respectively in MATLAB. Often one can combine these operators with relational expressions. For example: >> g=(a>2) & (A<5) g = returns ones where A is greater than 2 AND less than 5. >> for n=2:6 if (rem(n,2)~=0) & (rem(n,3)~=0) n n = 5 Finally, the above capabilities make it easy to generate arrays representing discontinuous functions, which are very useful in understanding signals etc. The basic idea is to multiply those values in an array that you wish to keep with ones, and multiply all other values with zeros. For example, >> x = -2:0.1:2; % Creates Data >> y = ones(size(x)); >> y = (x>-1)&(x<1); >> plot(x,y) This should plot a function which resembles part of a square wave that is discontinuous at x=-1 and x=1.

COMPUTATIONAL MODELING WITH MATLAB

COMPUTATIONAL MODELING WITH MATLAB COMPUTATIONAL MODELING WITH MATLAB Neslon Mandela African Institute of Science and Technology Arusha, Tanzania NSF-USAID PEER 013 PROGRAM George Mason University Fairfax, Virginia, USA Introduction MATLAB

More information

LAB 1 General MATLAB Information 1

LAB 1 General MATLAB Information 1 LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by

More information

Introduction to MATLAB

Introduction to MATLAB Outlines September 9, 2004 Outlines Part I: Review of Previous Lecture Part II: Part III: Writing MATLAB Functions Review of Previous Lecture Outlines Part I: Review of Previous Lecture Part II: Part III:

More information

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Introduction to Scientific and Engineering Computing, BIL108E. Karaman USING MATLAB INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 To start from Windows, Double click the Matlab icon. To start from UNIX, Dr. S. Gökhan type matlab at the shell prompt.

More information

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

Starting MATLAB To logon onto a Temple workstation at the Tech Center, follow the directions below. What is MATLAB? MATLAB (short for MATrix LABoratory) is a language for technical computing, developed by The Mathworks, Inc. (A matrix is a rectangular array or table of usually numerical values.) MATLAB

More information

Introduction to MATLAB

Introduction to MATLAB Outlines January 30, 2008 Outlines Part I: Part II: Writing MATLAB Functions Starting MATLAB Exiting MATLAB Getting Help Command Window Workspace Command History Current Directory Selector Real Values

More information

General MATLAB Information 1

General MATLAB Information 1 Introduction to MATLAB General MATLAB Information 1 Once you initiate the MATLAB software, you will see the MATLAB logo appear and then the MATLAB prompt >>. The prompt >> indicates that MATLAB is awaiting

More information

A. Matrix-wise and element-wise operations

A. Matrix-wise and element-wise operations USC GSBME MATLAB CLASS Reviewing previous session Second session A. Matrix-wise and element-wise operations A.1. Matrix-wise operations So far we learned how to define variables and how to extract data

More information

Matlab Workshop I. Niloufer Mackey and Lixin Shen

Matlab Workshop I. Niloufer Mackey and Lixin Shen Matlab Workshop I Niloufer Mackey and Lixin Shen Western Michigan University/ Syracuse University Email: nil.mackey@wmich.edu, lshen03@syr.edu@wmich.edu p.1/13 What is Matlab? Matlab is a commercial Matrix

More information

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS

Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS Inlichtingenblad, matlab- en simulink handleiding en practicumopgaven IWS 1 6 3 Matlab 3.1 Fundamentals Matlab. The name Matlab stands for matrix laboratory. Main principle. Matlab works with rectangular

More information

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

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB? Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

More information

Some elements for Matlab programming

Some elements for Matlab programming Some elements for Matlab programming Nathalie Thomas 2018 2019 Matlab, which stands for the abbreviation of MATrix LABoratory, is one of the most popular language for scientic computation. The classical

More information

Script started on Thu 25 Aug :00:40 PM CDT

Script started on Thu 25 Aug :00:40 PM CDT Script started on Thu 25 Aug 2016 02:00:40 PM CDT < M A T L A B (R) > Copyright 1984-2014 The MathWorks, Inc. R2014a (8.3.0.532) 64-bit (glnxa64) February 11, 2014 To get started, type one of these: helpwin,

More information

What is MATLAB and howtostart it up?

What is MATLAB and howtostart it up? MAT rix LABoratory What is MATLAB and howtostart it up? Object-oriented high-level interactive software package for scientific and engineering numerical computations Enables easy manipulation of matrix

More information

AN INTRODUCTION TO MATLAB

AN INTRODUCTION TO MATLAB AN INTRODUCTION TO MATLAB 1 Introduction MATLAB is a powerful mathematical tool used for a number of engineering applications such as communication engineering, digital signal processing, control engineering,

More information

Chapter 1 MATLAB Preliminaries

Chapter 1 MATLAB Preliminaries Chapter 1 MATLAB Preliminaries 1.1 INTRODUCTION MATLAB (Matrix Laboratory) is a high-level technical computing environment developed by The Mathworks, Inc. for mathematical, scientific, and engineering

More information

Ebooks Chemical Engineering

Ebooks Chemical Engineering Uploaded by: Ebooks Chemical Engineering https://www.facebook.com/pages/ebooks-chemical-engineering/238197077030 For More Books, softwares & tutorials Related to Chemical Engineering Join Us @facebook:

More information

1 Introduction to Matlab

1 Introduction to Matlab 1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Brett Ninness Department of Electrical and Computer Engineering The University of Newcastle, Australia. The name MATLAB is a sort of acronym for Matrix Laboratory. In fact, MATLAB

More information

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

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors. 1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN

More information

Lecturer: Keyvan Dehmamy

Lecturer: Keyvan Dehmamy MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Introduction MATLAB is an interactive package for numerical analysis, matrix computation, control system design, and linear system analysis and design available on most CAEN platforms

More information

A QUICK INTRODUCTION TO MATLAB

A QUICK INTRODUCTION TO MATLAB A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Basic operations and a few illustrations This set is independent from rest of the class notes. Matlab will be covered in recitations and occasionally

More information

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

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

More information

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

The value of f(t) at t = 0 is the first element of the vector and is obtained by MATLAB Tutorial This tutorial will give an overview of MATLAB commands and functions that you will need in ECE 366. 1. Getting Started: Your first job is to make a directory to save your work in. Unix

More information

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Intro to matlab getting started Basic operations and a few illustrations This set is indepent from rest of the class notes. Matlab will be covered

More information

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences Introductory remarks MATLAB: a product of mathworks www.mathworks.com MATrix LABoratory What can we do (in or ) with MATLAB o Use like

More information

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

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

Grace days can not be used for this assignment

Grace days can not be used for this assignment CS513 Spring 19 Prof. Ron Matlab Assignment #0 Prepared by Narfi Stefansson Due January 30, 2019 Grace days can not be used for this assignment The Matlab assignments are not intended to be complete tutorials,

More information

Laboratory 1 Octave Tutorial

Laboratory 1 Octave Tutorial Signals, Spectra and Signal Processing Laboratory 1 Octave Tutorial 1.1 Introduction The purpose of this lab 1 is to become familiar with the GNU Octave 2 software environment. 1.2 Octave Review All laboratory

More information

Introduction to MATLAB

Introduction to MATLAB CHEE MATLAB Tutorial Introduction to MATLAB Introduction In this tutorial, you will learn how to enter matrices and perform some matrix operations using MATLAB. MATLAB is an interactive program for numerical

More information

Programming in MATLAB

Programming in MATLAB trevor.spiteri@um.edu.mt http://staff.um.edu.mt/trevor.spiteri Department of Communications and Computer Engineering Faculty of Information and Communication Technology University of Malta 17 February,

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing

More information

Math 2250 MATLAB TUTORIAL Fall 2005

Math 2250 MATLAB TUTORIAL Fall 2005 Math 2250 MATLAB TUTORIAL Fall 2005 Math Computer Lab The Mathematics Computer Lab is located in the T. Benny Rushing Mathematics Center (located underneath the plaza connecting JWB and LCB) room 155C.

More information

GRAPH 4.4. Megha K. Raman APRIL 22, 2015

GRAPH 4.4. Megha K. Raman APRIL 22, 2015 GRAPH 4.4 By Megha K. Raman APRIL 22, 2015 1. Preface... 4 2. Introduction:... 4 3. Plotting a function... 5 Sample funtions:... 9 List of Functions:... 10 Constants:... 10 Operators:... 11 Functions:...

More information

Fundamentals of MATLAB Usage

Fundamentals of MATLAB Usage 수치해석기초 Fundamentals of MATLAB Usage 2008. 9 담당교수 : 주한규 joohan@snu.ac.kr, x9241, Rm 32-205 205 원자핵공학과 1 MATLAB Features MATLAB: Matrix Laboratory Process everything based on Matrix (array of numbers) Math

More information

A = [1, 6; 78, 9] Note: everything is case-sensitive, so a and A are different. One enters the above matrix as

A = [1, 6; 78, 9] Note: everything is case-sensitive, so a and A are different. One enters the above matrix as 1 Matlab Primer The purpose of these notes is a step-by-step guide to solving simple optimization and root-finding problems in Matlab To begin, the basic object in Matlab is an array; in two dimensions,

More information

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

ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu ECON 502 INTRODUCTION TO MATLAB Nov 9, 2007 TA: Murat Koyuncu 0. What is MATLAB? 1 MATLAB stands for matrix laboratory and is one of the most popular software for numerical computation. MATLAB s basic

More information

A General Introduction to Matlab

A General Introduction to Matlab Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti

More information

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

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control

More information

Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MatLab. Introduction to MatLab K. Craig 1 Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations

More information

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003

Math Scientific Computing - Matlab Intro and Exercises: Spring 2003 Math 64 - Scientific Computing - Matlab Intro and Exercises: Spring 2003 Professor: L.G. de Pillis Time: TTh :5pm 2:30pm Location: Olin B43 February 3, 2003 Matlab Introduction On the Linux workstations,

More information

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.

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. EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses

More information

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

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras Module No. #01 Lecture No. #1.1 Introduction to MATLAB programming

More information

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

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise

More information

Introduction to Unix and Matlab

Introduction to Unix and Matlab Introduction to Unix and Matlab 1 Introduction to the Unix System 1.1 Login Pick any machine in Room 451; the screen is probably dark. If so, press the [return] key once or twice. You should see something

More information

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017 Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017 Appendix A Glossary of Matlab Commands Mathematical Operations + Addition. Type help plus

More information

Introduction to MATLAB for CSE390

Introduction to MATLAB for CSE390 Introduction Introduction to MATLAB for CSE390 Professor Vijay Kumar Praveen Srinivasan University of Pennsylvania MATLAB is an interactive program designed for scientific computations, visualization and

More information

PART 1 PROGRAMMING WITH MATHLAB

PART 1 PROGRAMMING WITH MATHLAB PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment

More information

Scientific Computing Lecture 1: MATLAB fundamentals

Scientific Computing Lecture 1: MATLAB fundamentals Scientific Computing Lecture 1: MATLAB fundamentals InFoMM CDT Mathematical Institute University of Oxford Andrew Thompson (slides by Stuart Murray) Lecture I: MATLAB fundamentals What is MATLAB? MATLAB

More information

2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

More information

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

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful

More information

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

CSE/NEUBEH 528 Homework 0: Introduction to Matlab CSE/NEUBEH 528 Homework 0: Introduction to Matlab (Practice only: Do not turn in) Okay, let s begin! Open Matlab by double-clicking the Matlab icon (on MS Windows systems) or typing matlab at the prompt

More information

MAT 275 Laboratory 1 Introduction to MATLAB

MAT 275 Laboratory 1 Introduction to MATLAB MATLAB sessions: Laboratory 1 1 MAT 275 Laboratory 1 Introduction to MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory

More information

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB? Appendix A Introduction to MATLAB A.1 What Is MATLAB? MATLAB is a technical computing environment developed by The Math- Works, Inc. for computation and data visualization. It is both an interactive system

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse

More information

Introduction to Matlab. Matlab variable types. Matlab variable types. Matlab variable types. Notes. Eugeniy E. Mikhailov. Lecture 02. Notes.

Introduction to Matlab. Matlab variable types. Matlab variable types. Matlab variable types. Notes. Eugeniy E. Mikhailov. Lecture 02. Notes. Introduction to Matlab Eugeniy E. Mikhailov The College of William & Mary Lecture 02 Eugeniy Mikhailov (W&M) Practical Computing Lecture 02 1 / 26 Matlab variable types Eugeniy Mikhailov (W&M) Practical

More information

Basic stuff -- assignments, arithmetic and functions

Basic stuff -- assignments, arithmetic and functions Basic stuff -- assignments, arithmetic and functions Most of the time, you will be using Maple as a kind of super-calculator. It is possible to write programs in Maple -- we will do this very occasionally,

More information

ELEMENTARY MATLAB PROGRAMMING

ELEMENTARY MATLAB PROGRAMMING 1 ELEMENTARY MATLAB PROGRAMMING (Version R2013a used here so some differences may be encountered) COPYRIGHT Irving K. Robbins 1992, 1998, 2014, 2015 All rights reserved INTRODUCTION % It is assumed the

More information

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

Variable Definition and Statement Suppression You can create your own variables, and assign them values using = >> a = a = 3. MATLAB Introduction Accessing Matlab... Matlab Interface... The Basics... 2 Variable Definition and Statement Suppression... 2 Keyboard Shortcuts... More Common Functions... 4 Vectors and Matrices... 4

More information

Getting To Know Matlab

Getting To Know Matlab Getting To Know Matlab The following worksheets will introduce Matlab to the new user. Please, be sure you really know each step of the lab you performed, even if you are asking a friend who has a better

More information

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

MATLAB BASICS. < Any system: Enter quit at Matlab prompt < PC/Windows: Close command window < To interrupt execution: Enter Ctrl-c. MATLAB BASICS Starting Matlab < PC: Desktop icon or Start menu item < UNIX: Enter matlab at operating system prompt < Others: Might need to execute from a menu somewhere Entering Matlab commands < Matlab

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 3 Creating, Organising & Processing Data Dr Richard Greenaway 3 Creating, Organising & Processing Data In this Workshop the matrix type is introduced

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB MATLAB stands for MATrix LABoratory. Originally written by Cleve Moler for college linear algebra courses, MATLAB has evolved into the premier software for linear algebra computations

More information

A Guide to Using Some Basic MATLAB Functions

A Guide to Using Some Basic MATLAB Functions A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Andreas C. Kapourani (Credit: Steve Renals & Iain Murray) 9 January 08 Introduction MATLAB is a programming language that grew out of the need to process matrices. It is used extensively

More information

Matlab as a calculator

Matlab as a calculator Why Matlab? Matlab is an interactive, high-level, user-friendly programming and visualization environment. It allows much faster programs development in comparison with the traditional low-level compiled

More information

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

CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo CSE/Math 456 and CSE/Math 550 Matlab Tutorial and Demo MATLAB is very powerful and varied software package for scientific computing. It is based upon matrices and m files. It is invoked by typing % matlab

More information

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example: Using MATLAB for Stochastic Simulation. Eric W. Hansen. Matlab Basics Introduction MATLAB (MATrix LABoratory) is a software package designed for efficient, reliable numerical computing. Using MATLAB greatly

More information

Introduction to GNU-Octave

Introduction to GNU-Octave Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016

More information

MATLAB QUICK START TUTORIAL

MATLAB QUICK START TUTORIAL MATLAB QUICK START TUTORIAL This tutorial is a brief introduction to MATLAB which is considered one of the most powerful languages of technical computing. In the following sections, the basic knowledge

More information

Lab 1 Intro to MATLAB and FreeMat

Lab 1 Intro to MATLAB and FreeMat Lab 1 Intro to MATLAB and FreeMat Objectives concepts 1. Variables, vectors, and arrays 2. Plotting data 3. Script files skills 1. Use MATLAB to solve homework problems 2. Plot lab data and mathematical

More information

ENGR Fall Exam 1

ENGR Fall Exam 1 ENGR 1300 Fall 01 Exam 1 INSTRUCTIONS: Duration: 60 minutes Keep your eyes on your own work! Keep your work covered at all times! 1. Each student is responsible for following directions. Read carefully..

More information

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

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50 MATLAB Premier Middle East Technical University Department of Mechanical Engineering ME 304 1/50 Outline Introduction Basic Features of MATLAB Prompt Level and Basic Arithmetic Operations Scalars, Vectors,

More information

SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK

SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK Mathematical Statistics SF1901 Probability Theory and Statistics: Autumn 2016 Lab 0 for TCOMK 1 Preparation This computer exercise is a bit different from the other two, and has some overlap with computer

More information

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

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano MATLAB Lesson I Chiara Lelli Politecnico di Milano October 2, 2012 MATLAB MATLAB (MATrix LABoratory) is an interactive software system for: scientific computing statistical analysis vector and matrix computations

More information

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

To start using Matlab, you only need be concerned with the command window for now. Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Basics MATLAB is a high-level interpreted language, and uses a read-evaluate-print loop: it reads your command, evaluates it, then prints the answer. This means it works a lot like

More information

Matlab Tutorial 1: Working with variables, arrays, and plotting

Matlab Tutorial 1: Working with variables, arrays, and plotting Matlab Tutorial 1: Working with variables, arrays, and plotting Setting up Matlab First of all, let's make sure we all have the same layout of the different windows in Matlab. Go to Home Layout Default.

More information

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,

More information

Finding, Starting and Using Matlab

Finding, Starting and Using Matlab Variables and Arrays Finding, Starting and Using Matlab CSC March 6 &, 9 Array: A collection of data values organized into rows and columns, and known by a single name. arr(,) Row Row Row Row 4 Col Col

More information

This appendix provides a quick start introduction to MATLAB. You should be

This appendix provides a quick start introduction to MATLAB. You should be C A P P E N D I X Introduction to MATLAB APPENDIX OUTLINE C.1 MATLAB Interactive Sessions 2 C.2 Computing with MATLAB 5 C.3 Working with Files 12 C.4 Logical Operators and Loops 16 C.5 The MATLAB Help

More information

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.

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. University of Illinois at Urbana-Champaign Department of Electrical and Computer Engineering ECE 298JA Fall 2015 Matlab Tutorial 1 Overview The goal of this tutorial is to help you get familiar with MATLAB

More information

Arithmetic and Logic Blocks

Arithmetic and Logic Blocks Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation

More information

Getting Started with MATLAB

Getting Started with MATLAB APPENDIX B Getting Started with MATLAB MATLAB software is a computer program that provides the user with a convenient environment for many types of calculations in particular, those that are related to

More information

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER BENC 2113 DENC ECADD 2532 ECADD LAB SESSION 6/7 LAB

More information

Introduction to MATLAB

Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming

More information

Matlab Introduction. Scalar Variables and Arithmetic Operators

Matlab Introduction. Scalar Variables and Arithmetic Operators Matlab Introduction Matlab is both a powerful computational environment and a programming language that easily handles matrix and complex arithmetic. It is a large software package that has many advanced

More information

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

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

1 Overview of the standard Matlab syntax

1 Overview of the standard Matlab syntax 1 Overview of the standard Matlab syntax Matlab is based on computations with matrices. All variables are matrices. Matrices are indexed from 1 (and NOT from 0 as in C!). Avoid using variable names i and

More information

Built-in Types of Data

Built-in Types of Data Built-in Types of Data Types A data type is set of values and a set of operations defined on those values Python supports several built-in data types: int (for integers), float (for floating-point numbers),

More information

Desktop Command window

Desktop Command window Chapter 1 Matlab Overview EGR1302 Desktop Command window Current Directory window Tb Tabs to toggle between Current Directory & Workspace Windows Command History window 1 Desktop Default appearance Command

More information

AMS 27L LAB #2 Winter 2009

AMS 27L LAB #2 Winter 2009 AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles

More information

Table of Contents. Basis CEMTool 7 Tutorial

Table of Contents. Basis CEMTool 7 Tutorial PREFACE CEMTool (Computer-aided Engineering & Mathematics Tool) is a useful computational tool in science and engineering. No matter what you background be it physics, chemistry, math, or engineering it

More information

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

This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms: Appendix A Basic MATLAB Tutorial Extracted from: http://www1.gantep.edu.tr/ bingul/ep375 http://www.mathworks.com/products/matlab A.1 Introduction This is a basic tutorial for the MATLAB program which

More information

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group Introduction to MATLAB Simon O Keefe Non-Standard Computation Group sok@cs.york.ac.uk Content n An introduction to MATLAB n The MATLAB interfaces n Variables, vectors and matrices n Using operators n Using

More information

Matlab and Psychophysics Toolbox Seminar Part 1. Introduction to Matlab

Matlab and Psychophysics Toolbox Seminar Part 1. Introduction to Matlab Keith Schneider, 20 July 2006 Matlab and Psychophysics Toolbox Seminar Part 1. Introduction to Matlab Variables Scalars >> 1 1 Row vector >> [1 2 3 4 5 6] 1 2 3 4 5 6 >> [1,2,3,4,5,6] Column vector 1 2

More information

Numerical Methods Lecture 1

Numerical Methods Lecture 1 Numerical Methods Lecture 1 Basics of MATLAB by Pavel Ludvík The recommended textbook: Numerical Methods Lecture 1 by Pavel Ludvík 2 / 30 The recommended textbook: Title: Numerical methods with worked

More information

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals ELEN E384: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals 1 Introduction In the last lab you learn the basics of MATLAB, and had a brief introduction on how vectors

More information