INTRODUCTORY NOTES ON MATLAB

Size: px
Start display at page:

Download "INTRODUCTORY NOTES ON MATLAB"

Transcription

1 INTRODUCTORY NOTES ON MATLAB C Lamas Fernández, S Marelli, B Sudret CHAIR OF RISK, SAFETY AND UNCERTAINTY QUANTIFICATION STEFANO-FRANSCINI-PLATZ 5 CH-8093 ZÜRICH Risk, Safety & Uncertainty Quantification

2

3 Contents Introduction 4 2 Vectors and matrices 4 2 Creation and access 4 22 Indexing 6 23 Matrix operations 7 24 Modifying the content and shape 8 3 Functions 9 3 Definition 9 32 Integration 9 4 Statistics 9 4 Main functions 9 42 Sampling 43 Specific functions 2 5 Display 2 5 Command window 2 52 Plots 3 3

4 Introduction This document is a short introduction to the MATLAB programming language, with an emphasis on commands that are useful in the context of uncertainty quantification in engineering More information about MATLAB can be found in the on-line book: Moler, C B (2008) Numerical computing with MATLAB Siam Some of the chapters more related to the concepts presented here are: Introduction to MATLAB Quadrature Random Numbers In general, the built-in MATLAB documentation is comprehensive For a given command, you can type help cmd for the inline help in the workspace, or doc cmd for the HTML documentation 2 Vectors and matrices 2 Creation and access Vectors and matrices are defined using square brackets The comma is used to separate columns and the semicolon to separate rows For instance, to define : ( ) 2 v = (, 2, 3) B = 3 4 the following syntax is used: v = [, 2, 3]; B = [,2 ; 3,4]; There are some functions available to create special types of matrices and vectors, as listed in Table Table : Creation of special types of matrices / vectors Description Operation result Syntax Matrix with zeros z = ( 0 0 ) z = zeros(2, 3); Matrix with ones o = o = ones(3, 2); Elements from to N s = (, 2,, N) s = :N; 4

5 Elements from 0 to N, step k q = (0, k, 2k,, N) q = 0:k:N; 0 0 Diagonal matrix D = D = diag([, 2, 3]) Identity matrix I = ( ) 0 0 I = eye(2) Accessing parts of a matrix A and a vector v a, a,n A = v = (v,, v M ) a M, a M,N may be carried out using the commands in Table 2 Table 2: Accessing parts of matrices / vectors Description Operation result Syntax Vector i th element v i v(i) Last vector element v M v(end) Matrix element a i,j A(i,j) k th row k = (a k,,, a k,n ) k = A(k,:) l th column l = a,l a M,l l = A(:,p) Diagonal d = (a,, a 2,2, ) d = diag(a) 5

6 22 Indexing MATLAB has two powerful ways to access subsets of vectors and matrices, namely, absolute and logical indexing Absolute indexing It consists in referring to elements with their absolute index inside the array Consider the vector v = (0, 2, 4, 8) As you would expect, v(2) = 2 and v(4) = 8 These indices can also be combined in a vector: v([2, 4]) = [2, 8] The colon definition of vectors works also here: v(2:4) = [2, 4, 8] Logical indexing A logical index of a matrix A consists on a matrix L A of the same size as A that contains logical values only These are typically created using logical operators For example, let us define the two matrices: A = ( ) B = ( ) and check the elements that are equal in these two matrices: >> LA = A == B LA = 0 0 One can use this index to retrieve elements from the matrices A and B, that are always stored as a column vector: >> A(LA) ans = 2 >> A( LA) ans = 3 4 In this code, using LA, returns the elements that are not true on the index LA, this means the elements of A that are different from B Example Let us consider now a vector y = sin(x), where x = (,, 00) With logical indexing, we can easily see how many elements of y are greater than zero: >> y = sin(:00); sum(y > 0) ans = 50 If we want to set the vector elements with negative values to 0, we can do it with this notation as well: >> y(y < 0) = 0; 6

7 Note that this would be much faster (and shorter) than writing the equivalent loop version: for ii = :00 if y(ii) < 0 y(ii) = 0; end end 23 Matrix operations Consider the matrices A and B and the vector v: a, a,n b, b,n A = B = a M, a M,N b M, b M,N v = Matrix operations are summarized in Table 3 Operations on matrix elements are summarized in Table 4 Table 3: Matrix level operations Description Operation result Syntax Transpose of A, A T a, a,m a N, a N,M Matrix sum A + B A + B v v s transpose(a) (for real matrices, A' is equivalent) Matrix multiplication AB T A transpose(b) Matrix division A B A/B A squared A 2 = AA Aˆ2 Matrix inversion A inv(a) A\v Table 4: Element level operations Description Operation result Syntax Element multiplication a, b, a,m b,m a N, b N, a N,M b N,M A B 7

8 Element division Square root Standard function, eg sin Sum Product a, b, a N, b N, a,m b,m a N,M b N,M a, an, a,m an,m sin(a, ) sin(a,m ) sin(a N, ) sin(a N,M) M i= v i M i= v i A/B sqrt(a) sin(a) sum(v) prod(v) Most MATLAB functions, like the trigonometric functions, exponential, probability density functions, etc act element-wise on matrices However, you can always check this behaviour on the function s help 24 Modifying the content and shape Scalar value assignment to a matrix, or part of it, sets each element to its value: ( ) ( ) 0 5 A = A = 0 5 >> A = eye(2); A(A == 0) = 5; Setting a row or column to [], deletes it from the matrix A = 0 0 A = >> A = eye(3); A(:,3) = []; The function repmat(a,m,n) creates a matrix that is made of a grid of M N times the A matrix v = 2 A = >> v = transpose(:3); A = repmat(v,,3); 8

9 3 Functions 3 Definition Consider the function f(x, y) = xy In MATLAB it can be defined easily as an anonymous function: f y) x y; However, it is convenient to be able to evaluate more than one point at once We usually adapt to the notation ( ) x x X = N y y N to represent a sample of N points with two coordinates More generally, X has a dimension M N and each column represents a M dimensional point of a sample with N elements Adapting this convention to MATLAB we can define the previous function in a vectorized fashion as: fv X(,:) X(2,:); 32 Integration The integral of an anonymous function f can be easily approximated in the interval [min, max] using the command integral(f, min, max) >> f xˆ2; integral(f, 0, 2) ans = Note that it is also possible to use ± as boundaries For example, we can integrate the standard normal pdf in (, ) using: >> f =@(x) pdf('normal', x, 0, ); integral(f, Inf, Inf) ans = Statistics 4 Main functions Distribution functions MATLAB can handle various probability distributions through its statistics toolbox, in particular it has the functions: pdf(distr,x,par,par2) that computes the probability density function of the distribution distr with parameters par and par2 on the point X cdf(distr,x,par,par2) that works the same but for the cumulative distribution function 9

10 icdf(distr,x,par,par2) for handling the inverse cumulative distribution function Table 5 gathers a list of the most common keywords that can be used for distr For a full list you can type help pdf Table 5: Keywords and expected parameters for various distributions in MATLAB Keywords Distribution Par Par 2 Obs 'beta' Beta, B(a, b) a b Def only for x (0, ) 'ev' or 'Extreme Value' Extreme value µ β The MATLAB default corresponds to Same, but using X Gumbel, G(µ, β) µ β the Gumbel minima distribution 'gam' or 'Gamma' Gamma Γ(λ, k) k λ Inverted order of parameters 'logn' or 'Lognormal' Lognormal, LN (µ, σ) µ σ 'norm' or 'Normal' Normal, N (µ, σ) µ σ 'unif' or 'Uniform' Uniform, U(a, b) a b 'wbl' or 'Weibull' Weibull, W(α, β) α β Data estimates The basic functions for estimating parameters from data are also available on MATLAB Some of them are presented on Table 6 Table 6: Parameter estimation functions in MATLAB Function mean(x) std(x) var(x) skewness(x) kurtosis(x) Description Mean of X Standard deviation of X Variance of X Skewness of X Kurtosis of X Kernel smoothing MATLAB provides a function for kernel smoothing: [fhat, x] = ksdensity(v) It provides a estimate fhat of the value of the probability density function on the points x 0

11 If you wish to specify the abscissae where the function shall be estimated, the syntax fhat = ksdensity(v, points) is also possible, where points contains the vector of abscissae Example Estimate the PDF ˆf(0), for x = 0, from a set made of 000 realizations of a standard normal variable N (0, ) (The actual value is φ(0) = 03989) >> x = randn(,000); fi = ksdensity(x, 0) fi = 0396 For more advanced tuning, ksdensity accepts other input parameters, such as choosing the bandwith (eg [fhat, x] = ksdensity(x,'width',8);) or estimating the cumulative distribution function: [Fhat, x] = ksdensity(x,'function', 'cdf'); Example Calling the function without output arguments, will directly produce the plot, in this case for the estimate of the CDF of a standard normal distribution Sampling v = randn(, e4); ksdensity(v, 'function', 'cdf') Random numbers To generate uniformly distributed random numbers in the interval (0, ), one can simply type: rand The same function with an argument n, will give a random matrix of size n n: >> rand(2) ans = Calling it with two arguments, eg rand(m,n), returns a M N matrix with random numbers Random sampling MATLAB provides the function random(distr, par, par2, M, N), that allows one to generate random numbers from various distributions, specifying them in the distr parameter, as in Table 5 The arguments par and par2 stand for the parameters of the distribution and M and N for the dimensions of the generated random matrix

12 Example Plot a sample of 00 points for two independent variables following the distributions x N (0, 5) and y N (0, 05) x = random('normal', 0, 5,, 00); y = random('normal', 0, 5,, 00); plot(x, y, ' '); Specific functions Note that apart from this syntax, there are also specific functions in MATLAB for some of the distributions For example, for the normal distribution, you can use directly normpdf, normcdf, norminv and normrnd or randn for the probability density function, the cumulative distribution function, the inverse cumulative distribution function and for generating random numbers, respectively 5 Display 5 Command window disp(var) The function disp allows you to quickly display information of any kind within the command window: >> a = rand(,00); disp('the last element of a is:'); disp(a(end)); The last element of a is: 0622 disp always displays the results in a new line, and it works regardless of the type of variable that you use as an argument In general, it is the same as not typing the semicolon at the end of the sentences, but disp does not show the name of the variable being displayed fprintf(string,) For a more sophisticated and powerful way of displaying information, you can use fprintf It works by printing a string in which some special characters are included, that are to be replaced by the arguments passed to the function For example, the special character %s is used for including strings, %f for double precision numbers and the escape character \n for writing a new line: >> a = rand(,00); name = 'a'; fprintf('the last element of vector %s is: %f\n', name, a(end)); The last element of vector a is:

13 This function can be very powerful, as it allows you to control, for example, the number of decimal digits to be included, to choose or not an exponential notation, etc For a complete list of its capabilities and special characters, you can type doc fprintf or help fprintf 52 Plots There are many functions in MATLAB that can create plots reviewed in the sequel Only a few of them are plot(x,y,) This function plots a vector with x values against a vector of the same size with y values Let us consider two plots representing y = sin(x), z = sin(2x), where x [ π, π] On x, we will consider a discrete set of points with steps of size 0 and boundaries, so as to capture the values in π x = 32::32; y = sin(x); z = sin(2 x); Now, we create a figure and tell MATLAB to keep it open for plotting different curves (ie not opening new graphical windows) figure hold on The command plot with the vector arguments previously defined will create the plots We can also specify a third argument that indicates the color of the line, in this case 'r' that stands for red There are many options that can be specified on the plot command (color, line style, markers, line width, etc ), check help plot for more details The following code will produce this plot: Example 05 plot(x, y); plot(x, z, 'r'); Table 7 there are a few commands that can be used to modify how the plot looks like You can issue them line by line to see the effect they have on the figure: 3

14 Table 7: Commands modifying the layout of a figure Command set(gca,'fontsize', 24); ylim([ 5, 5]) xlim([ pi, pi]) xlabel('x'); ylabel('y'); title('sinusoidal plots'); legend({'sin(x)', 'sin(2x)'}); grid on box on set(gca, 'xtick', pi:pi/2:pi); set(gca, 'xtick', 'ytick', [, 0, ]); Description Make the fonts larger Change the limits on the y axis Change the limits on the x axis Add a label on the x axis Add a label on the y axis Add a title on the plot Add a legend Show a grid on the x and y axis marks Box the figure Modify the place where the grid lines and axis marks are located for x and y respectively After these commands, the previous plot will look like this: Sinusoidal plots sin(x) sin(2x) y x 4

15 Markers Let us now create an example of plot using some of the techniques shown in the previous sections (anonymous functions and logical indexing) Create a figure that allows for several plots: figure hold on Create a function f = x 2, evaluate it in x [0, 6]: f xˆ2; fx = 0::6; fy = f(fx); Plot the function with a discontinuous black line and a line width of 3: plot(fx, fy, ' k', 'linewidth', 3); Generate now 200 random points (x, y), x N (2, ) and y U(0, 4) x = random('normal', 2,,, 200); y = random('uniform', 0, 4,, 200); 2 Use logical indexing now to find those points that are above the line and plot them in different colors, only with markers: idx = y > f(x); plot(x(idx), y(idx), 'b '); plot(x( idx), y( idx), 'r '); Set the limits of the axis according to the random sample and add box and grid: xlim([min(x), max(x)]); ylim([min(y), max(y)]); grid on box on Additional tricks for customizing MATLAB plots are available at: imagesc(a) This function is useful to quickly show the contents of a matrix, scaling the data to use the whole color range Let us create a matrix that contains the basis for a color gradient 5

16 Matrix Code Result A = :00; A = repmat(a, 0, ); imagesc(a); colorbar; hist(v, n) The function hist(v) allows one to plot an histogram of the data contained in a vector v Optionally, you can input a second argument hist(v, N) to specify the number of bins in the plot Example 600 Histogram of the vector v, containing 0 4 random numbers generated from a standard normal distribution: v = randn(,e4); hist(v, 50);

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

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014 PS 12a Laboratory 1 Spring 2014 Objectives This session is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started. Throughout the tutorial, the instructors

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

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016 Physical Sciences 12a Lab 0 Spring 2016 Objectives This lab is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started in this class. It is meant to

More information

CME 192: Introduction to Matlab

CME 192: Introduction to Matlab CME 192: Introduction to Matlab Matlab Basics Brett Naul January 15, 2015 Recap Using the command window interactively Variables: Assignment, Identifier rules, Workspace, command who and whos Setting the

More information

Computer exercise 1 Introduction to Matlab.

Computer exercise 1 Introduction to Matlab. Chalmers-University of Gothenburg Department of Mathematical Sciences Probability, Statistics and Risk MVE300 Computer exercise 1 Introduction to Matlab. Understanding Distributions In this exercise, you

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

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY What is MATLAB? MATLAB (MATrix LABoratory) developed by The Mathworks, Inc. (http://www.mathworks.com) Key Features: High-level language for numerical

More information

(1) Generate 1000 samples of length 1000 drawn from the uniform distribution on the interval [0, 1].

(1) Generate 1000 samples of length 1000 drawn from the uniform distribution on the interval [0, 1]. PRACTICAL EXAMPLES: SET 1 (1) Generate 1000 samples of length 1000 drawn from the uniform distribution on the interval [0, 1]. >> T=rand(1000,1000); The command above generates a matrix, whose columns

More information

Programming in Mathematics. Mili I. Shah

Programming in Mathematics. Mili I. Shah Programming in Mathematics Mili I. Shah Starting Matlab Go to http://www.loyola.edu/moresoftware/ and login with your Loyola name and password... Matlab has eight main windows: Command Window Figure Window

More information

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

Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems

More information

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

Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name: 1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write

More information

Lecture 2: Variables, Vectors and Matrices in MATLAB

Lecture 2: Variables, Vectors and Matrices in MATLAB Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables

More information

A 30 Minute Introduction to Octave ENGR Engineering Mathematics Tony Richardson

A 30 Minute Introduction to Octave ENGR Engineering Mathematics Tony Richardson A 30 Minute Introduction to Octave ENGR 390 - Engineering Mathematics Tony Richardson Introduction This is a brief introduction to Octave. It covers several topics related to both the statistics and linear

More information

QUICK INTRODUCTION TO MATLAB PART I

QUICK INTRODUCTION TO MATLAB PART I QUICK INTRODUCTION TO MATLAB PART I Department of Mathematics University of Colorado at Colorado Springs General Remarks This worksheet is designed for use with MATLAB version 6.5 or later. Once you have

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

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

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

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab MATH 495.3 (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab Below is a screen similar to what you should see when you open Matlab. The command window is the large box to the right containing the

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

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

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student

More information

What is Matlab? The command line Variables Operators Functions

What is Matlab? The command line Variables Operators Functions What is Matlab? The command line Variables Operators Functions Vectors Matrices Control Structures Programming in Matlab Graphics and Plotting A numerical computing environment Simple and effective programming

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Christopher K. I. Williams Division of Informatics, University of Edinburgh October 1999 Background This document has the objective of introducing you to some of the facilities available

More information

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

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA MATLAB for beginners KiJung Yoon, 1 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA 1 MATLAB Tutorial I What is a matrix? 1) A way of representation for data (# of

More information

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

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

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 Programming

Introduction to MATLAB Programming Introduction to MATLAB Programming Arun A. Balakrishnan Asst. Professor Dept. of AE&I, RSET Overview 1 Overview 2 Introduction 3 Getting Started 4 Basics of Programming Overview 1 Overview 2 Introduction

More information

MATLAB TUTORIAL WORKSHEET

MATLAB TUTORIAL WORKSHEET MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent

More information

A very brief Matlab introduction

A very brief Matlab introduction A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading

More information

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services

MATLAB INTRODUCTION. Risk analysis lab Ceffer Attila. PhD student BUTE Department Of Networked Systems and Services MATLAB INTRODUCTION Risk analysis lab 2018 2018. szeptember 10., Budapest Ceffer Attila PhD student BUTE Department Of Networked Systems and Services ceffer@hit.bme.hu Előadó képe MATLAB Introduction 2

More information

Teaching Manual Math 2131

Teaching Manual Math 2131 Math 2131 Linear Algebra Labs with MATLAB Math 2131 Linear algebra with Matlab Teaching Manual Math 2131 Contents Week 1 3 1 MATLAB Course Introduction 5 1.1 The MATLAB user interface...........................

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

1 Week 1: Basics of scientific programming I

1 Week 1: Basics of scientific programming I MTH739N/P/U: Topics in Scientific Computing Autumn 2016 1 Week 1: Basics of scientific programming I 1.1 Introduction The aim of this course is use computing software platforms to solve scientific and

More information

Learning from Data Introduction to Matlab

Learning from Data Introduction to Matlab Learning from Data Introduction to Matlab Amos Storkey, David Barber and Chris Williams a.storkey@ed.ac.uk Course page : http://www.anc.ed.ac.uk/ amos/lfd/ This is a modified version of a text written

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

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

Due date for the report is 23 May 2007

Due date for the report is 23 May 2007 Objectives: Learn some basic Matlab commands which help you get comfortable with Matlab.. Learn to use most important command in Matlab: help, lookfor. Data entry in Microsoft excel. 3. Import data into

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: Quick Start Econ 837

MATLAB: Quick Start Econ 837 MATLAB: Quick Start Econ 837 Introduction MATLAB is a commercial Matrix Laboratory package which operates as an interactive programming environment. It is a programming language and a computing environment

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

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

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr A0B17MTB Matlab Part #1 Miloslav Čapek miloslav.capek@fel.cvut.cz Filip Kozák, Viktor Adler, Pavel Valtr Department of Electromagnetic Field B2-626, Prague You will learn Scalars, vectors, matrices (class

More information

Introduction to MATLAB

Introduction to MATLAB ELG 3125 - Lab 1 Introduction to MATLAB TA: Chao Wang (cwang103@site.uottawa.ca) 2008 Fall ELG 3125 Signal and System Analysis P. 1 Do You Speak MATLAB? MATLAB - The Language of Technical Computing ELG

More information

Summer 2009 REU: Introduction to Matlab

Summer 2009 REU: Introduction to Matlab Summer 2009 REU: Introduction to Matlab Moysey Brio & Paul Dostert June 29, 2009 1 / 19 Using Matlab for the First Time Click on Matlab icon (Windows) or type >> matlab & in the terminal in Linux. Many

More information

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

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003 Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 About MATLAB MATLAB (MATrix LABoratory) is a high level language made for: Numerical Computation (Technical computing)

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

MATLAB TUTORIAL FOR MATH/CHEG 305

MATLAB TUTORIAL FOR MATH/CHEG 305 MATLAB TUTORIAL FOR MATH/CHEG 305 February 1, 2002 Contents 1 Starting Matlab 2 2 Entering Matrices, Basic Operations 2 3 Editing Command Lines 4 4 Getting Help 4 5 Interrupting, Quitting Matlab 5 6 Special

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

LabVIEW MathScript Quick Reference

LabVIEW MathScript Quick Reference Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics LabVIEW MathScript Quick Reference Hans-Petter Halvorsen, 2012.06.14 Faculty of Technology, Postboks

More information

Computational Finance

Computational Finance Computational Finance Introduction to Matlab Marek Kolman Matlab program/programming language for technical computing particularly for numerical issues works on matrix/vector basis usually used for functional

More information

Introduction to MATLAB LAB 1

Introduction to MATLAB LAB 1 Introduction to MATLAB LAB 1 1 Basics of MATLAB MATrix LABoratory A super-powerful graphing calculator Matrix based numeric computation Embedded Functions Also a programming language User defined functions

More information

Introduction to MATLAB

Introduction to MATLAB 58:110 Computer-Aided Engineering Spring 2005 Introduction to MATLAB Department of Mechanical and industrial engineering January 2005 Topics Introduction Running MATLAB and MATLAB Environment Getting help

More information

% Close all figure windows % Start figure window

% Close all figure windows % Start figure window CS1112 Fall 2016 Project 3 Part A Due Monday 10/3 at 11pm You must work either on your own or with one partner. If you work with a partner, you must first register as a group in CMS and then submit your

More information

MATLAB. A Tutorial By. Masood Ejaz

MATLAB. A Tutorial By. Masood Ejaz MATLAB A Tutorial By Masood Ejaz Note: This tutorial is a work in progress and written specially for CET 3464 Software Programming in Engineering Technology, a course offered as part of BSECET program

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

Introduction to MATLAB

Introduction to MATLAB Computational Photonics, Seminar 0 on Introduction into MATLAB, 3.04.08 Page Introduction to MATLAB Operations on scalar variables >> 6 6 Pay attention to the output in the command window >> b = b = >>

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

MATLAB GUIDE UMD PHYS401 SPRING 2012

MATLAB GUIDE UMD PHYS401 SPRING 2012 MATLAB GUIDE UMD PHYS40 SPRING 202 We will be using Matlab (or, equivalently, the free clone GNU/Octave) this semester to perform calculations involving matrices and vectors. This guide gives a brief introduction

More information

EGR 111 Introduction to MATLAB

EGR 111 Introduction to MATLAB EGR 111 Introduction to MATLAB This lab introduces the MATLAB help facility, shows how MATLAB TM, which stands for MATrix LABoratory, can be used as an advanced calculator. This lab also introduces assignment

More information

INTRODUCTION TO MATLAB

INTRODUCTION TO MATLAB 1 of 18 BEFORE YOU BEGIN PREREQUISITE LABS None EXPECTED KNOWLEDGE Algebra and fundamentals of linear algebra. EQUIPMENT None MATERIALS None OBJECTIVES INTRODUCTION TO MATLAB After completing this lab

More information

Getting started with MATLAB

Getting started with MATLAB Sapienza University of Rome Department of economics and law Advanced Monetary Theory and Policy EPOS 2013/14 Getting started with MATLAB Giovanni Di Bartolomeo giovanni.dibartolomeo@uniroma1.it Outline

More information

MATLAB Vocabulary. Gerald Recktenwald. Version 0.965, 25 February 2017

MATLAB Vocabulary. Gerald Recktenwald. Version 0.965, 25 February 2017 MATLAB Vocabulary Gerald Recktenwald Version 0.965, 25 February 2017 MATLAB is a software application for scientific computing developed by the Mathworks. MATLAB runs on Windows, Macintosh and Unix operating

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

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed.

12 whereas if I terminate the expression with a semicolon, the printed output is suppressed. Example 4 Printing and Plotting Matlab provides numerous print and plot options. This example illustrates the basics and provides enough detail that you can use it for typical classroom work and assignments.

More information

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

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands How to Use MATLAB What is MATLAB MATLAB is an interactive package for numerical analysis, matrix computation, control system design and linear system analysis and design. On the server bass, MATLAB version

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

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB

INTRODUCTION TO MATLAB PLOTTING WITH MATLAB 1 INTRODUCTION TO MATLAB PLOTTING WITH MATLAB Plotting with MATLAB x-y plot Plotting with MATLAB MATLAB contains many powerful functions for easily creating plots of several different types. Command plot(x,y)

More information

MATLAB Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos, sin,

More information

Stokes Modelling Workshop

Stokes Modelling Workshop Stokes Modelling Workshop 14/06/2016 Introduction to Matlab www.maths.nuigalway.ie/modellingworkshop16/files 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 1 / 16 Matlab As part of this crash

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

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

Sampling from distributions

Sampling from distributions Sampling from distributions December 17, 2015 1 Sampling from distributions Now that we are able to sample equally distributed (pseudo-)random numbers in the interval [1, 0), we are now able to sample

More information

An Introduction to Numerical Methods

An Introduction to Numerical Methods An Introduction to Numerical Methods Using MATLAB Khyruddin Akbar Ansari, Ph.D., P.E. Bonni Dichone, Ph.D. SDC P U B L I C AT I O N S Better Textbooks. Lower Prices. www.sdcpublications.com Powered by

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

MATLAB BASICS. M Files. Objectives

MATLAB BASICS. M Files. Objectives Objectives MATLAB BASICS 1. What is MATLAB and why has it been selected to be the tool of choice for DIP? 2. What programming environment does MATLAB offer? 3. What are M-files? 4. What is the difference

More information

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

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013 Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.

More information

Documentation for Numerical Derivative on Discontinuous Galerkin Space

Documentation for Numerical Derivative on Discontinuous Galerkin Space Documentation for Numerical Derivative on Discontinuous Galerkin Space Stefan Schnake 204 Introduction This documentation gives a guide to the syntax and usage of the functions in this package as simply

More information

Introduction to Matlab. By: Hossein Hamooni Fall 2014

Introduction to Matlab. By: Hossein Hamooni Fall 2014 Introduction to Matlab By: Hossein Hamooni Fall 2014 Why Matlab? Data analytics task Large data processing Multi-platform, Multi Format data importing Graphing Modeling Lots of built-in functions for rapid

More information

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

Identity Matrix: >> eye(3) ans = Matrix of Ones: >> ones(2,3) ans = Very Basic MATLAB Peter J. Olver January, 2009 Matrices: Type your matrix as follows: Use space or, to separate entries, and ; or return after each row. >> [;5 0-3 6;; - 5 ] or >> [,5,6,-9;5,0,-3,6;7,8,5,0;-,,5,]

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

BSM510 Numerical Analysis

BSM510 Numerical Analysis BSM510 Numerical Analysis Introduction and Matlab Fundamentals Manar Mohaisen Department of EEC Engineering Lecture Content Introduction to MATLAB 2 Introduction to MATLAB MATLAB 3 Scalars >> x = 5; x

More information

Lab #1 Revision to MATLAB

Lab #1 Revision to MATLAB Lab #1 Revision to MATLAB Objectives In this lab we would have a revision to MATLAB, especially the basic commands you have dealt with in analog control. 1. What Is MATLAB? MATLAB is a high-performance

More information

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

Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics. Matlab (Matrix laboratory) is an interactive software system for numerical computations and graphics. Starting MATLAB - On a PC, double click the MATLAB icon - On a LINUX/UNIX machine, enter the command:

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

Introduction to Matlab

Introduction to Matlab Introduction to Matlab The purpose of this intro is to show some of Matlab s basic capabilities. Nir Gavish, 2.07 Contents Getting help Matlab development enviroment Variable definitions Mathematical operations

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

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

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

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations

MATLAB Tutorial. 1. The MATLAB Windows. 2. The Command Windows. 3. Simple scalar or number operations MATLAB Tutorial The following tutorial has been compiled from several resources including the online Help menu of MATLAB. It contains a list of commands that will be directly helpful for understanding

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

How to learn MATLAB? Some predefined variables

How to learn MATLAB? Some predefined variables ECE-S352 Lab 1 MATLAB Tutorial How to learn MATLAB? 1. MATLAB comes with good tutorial and detailed documents. a) Select MATLAB help from the MATLAB Help menu to open the help window. Follow MATLAB s Getting

More information

Chapter 1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,

More information

Lecture 2. Arrays. 1 Introduction

Lecture 2. Arrays. 1 Introduction 1 Introduction Lecture 2 Arrays As the name Matlab is a contraction of matrix laboratory, you would be correct in assuming that Scilab/Matlab have a particular emphasis on matrices, or more generally,

More information

MATLAB Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB built-in functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos,

More information

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

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots

More information

A Quick Introduction to MATLAB/Octave. Kenny Marino, Nupur Chatterji

A Quick Introduction to MATLAB/Octave. Kenny Marino, Nupur Chatterji A Quick Introduction to MATLAB/Octave Kenny Marino, Nupur Chatterji Basics MATLAB (and it s free cousin Octave) is an interpreted language Two basic kinds of files Scripts Functions MATLAB is optimized

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

A Brief MATLAB Tutorial

A Brief MATLAB Tutorial POLYTECHNIC UNIVERSITY Department of Computer and Information Science A Brief MATLAB Tutorial K. Ming Leung Abstract: We present a brief MATLAB tutorial covering only the bare-minimum that a beginner needs

More information

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB In this laboratory session we will learn how to 1. Create matrices and vectors. 2. Manipulate matrices and create matrices of special types

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

Computer Project: Getting Started with MATLAB

Computer Project: Getting Started with MATLAB Computer Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands. Examples here can be useful for reference later. MATLAB functions: [ ] : ; + - *

More information

Getting Started with Matlab

Getting Started with Matlab Chapter Getting Started with Matlab The computational examples and exercises in this book have been computed using Matlab, which is an interactive system designed specifically for scientific computation

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