259 Lecture 15 Introduction to MATLAB. 2 What is MATLAB?  MATLAB, which stands for “MATrix LABoratory” is a high- performance language for technical.

Slides:



Advertisements
Similar presentations
MATLAB – A Computational Methods By Rohit Khokher Department of Computer Science, Sharda University, Greater Noida, India MATLAB – A Computational Methods.
Advertisements

Introduction to MATLAB The language of Technical Computing.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Digital Image Processing Lecture3: Introduction to MATLAB.
Lecture 1: Introduction Lecture series based on the text: Essential MATLAB for Engineers and Scientists By Hahn & Valentine
Chapter 10 Review: Matrix Algebra
MATLAB Lecture One Monday 4 July Matlab Melvyn Sim Department of Decision Sciences NUS Business School
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
BRIAN D. HAHN AND DANIEL T. VALENTINE THIRD EDITION Essential MATLAB® for Engineers and Scientists.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to MATLAB Session 1 Prepared By: Dina El Kholy Ahmed Dalal Statistics Course – Biomedical Department -year 3.
You can make this in matlab!. Matlab Introduction and Matrices.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Lecture 4 MATLAB Windows Arithmetic Operators Maintenance Functions
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
Introduction to MATLAB CBE 502 Mathematical Methods of Engineering Analysis.
MEGN 536 – Computational Biomechanics MATLAB: Getting Started Prof. Anthony J. Petrella Computational Biomechanics Group.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
INTRODUCTION TO MATLAB LAB# 01
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (1): Introduction.
Lecture 28: Mathematical Insight and Engineering.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Getting Started with MATLAB 1. Fundamentals of MATLAB 2. Different Windows of MATLAB 1.
10/24/20151 Chapter 2 Review: MATLAB Environment Introduction to MATLAB 7 Engineering 161.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
Basics of MATLAB By DR. Wafaa Shabana
MATLAB Environment ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Introduction to MATLAB Session 1 Simopekka Vänskä, THL 2010.
INTRODUCTION TO MATLAB MATLAB is a software package for computation in engineering, science, and applied mathemat-ics. It offers a powerful programming.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
A string is an array of characters Strings have many uses in MATLAB Display text output Specify formatting for plots Input arguments for some functions.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
MATLAB – PT1 The purpose of this workshop is to get you started and to have fun with MATLAB! Let’s talk a little and decide on what we will be covering.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to MATLAB Zongqiang Liao Research Computing Group UNC-Chapel Hill.
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Tutorial 2 : Matlab - Getting Started.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
MATLAB (Matrix Algebra laboratory), distributed by The MathWorks, is a technical computing environment for high performance numeric computation and.
1-2 What is the Matlab environment? How can you create vectors ? What does the colon : operator do? How does the use of the built-in linspace function.
MATLAB ……………….matrix laboratory. Bhushan D Patil PhD Research Scholar Department of Electrical Engineering Indian Institute of Technology, Bombay Powai,
ECE 1304 Introduction to Electrical and Computer Engineering
Introduction to MATLAB
Introduction to MATLAB
Computer Application in Engineering Design
Signals in Matlab Matlab as a name stands for Matrix Laboratory.
MATLAB Basics Nafees Ahmed Asstt. Professor, EE Deptt DIT, DehraDun.
INTRODUCTION TO BASIC MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
Digital Image Processing using MATLAB
Use of Mathematics using Technology (Maltlab)
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Digital Image Processing
Communication and Coding Theory Lab(CS491)
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Matlab Basic Dr. Imtiaz Hussain
Presentation transcript:

259 Lecture 15 Introduction to MATLAB

2 What is MATLAB?  MATLAB, which stands for “MATrix LABoratory” is a high- performance language for technical computing.  It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation.  Typical uses include: Math and computation Algorithm development Data acquisition Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including graphical user interface building

3 What is MATLAB?  MATLAB is an interactive system whose basic data element is an array that does not require dimensioning.  In many university environments, it is the standard instructional tool for introductory and advanced courses in mathematics, engineering, and science.  In industry, MATLAB is the tool of choice for high-productivity research, development, and analysis.

4 What is MATLAB?  MATLAB features a family of add-on application-specific solutions called toolboxes, which allow you to learn and apply specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are available include signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many others.

5 The MATLAB System  The MATLAB system consists of these main parts: Desktop Tools and Development Environment The MATLAB Mathematical Function Library The MATLAB Language (syntax) Graphics The MATLAB External Interfaces/Application Programming Interface (used to design software)

Octave – A Free MATLAB Clone  One of the “drawbacks” to MATLAB is that it is very expensive (~$1000 for an academic license).  One possible alternative to MATLAB is OCTAVE, which is a free clone of MATLAB (i.e. Octave mimics the functionality of MATLAB, often in the exact same way).  For more information on Octave (technically GNU Octave), see: Octave downloads from Source Forge (both Windows and Mac OS X installers can be found here: Octave Homepage: 6

7 MATLAB Desktop Current Directory Enter Commands here in the Command Window Current Directory Window Command History Window

Octave Standard Interface 8

Octave GUI (not as stable) 9

10 Calling MATLAB Help  To call Help in MATLAB, either click on the MATLAB Help link, or type “helpdesk” in the Command Window. Octave does NOT have a built-in help file, so “helpdesk” doesn’t apply!  Notice that the Command History window keeps track of all of the commands you type!

11 Ending a MATLAB Session  To end a MATLAB session, type “exit” or “quit”.

12 MATLAB Basics  If you forget how to use a command, but can remember the command name, such as “plot”, type “help plot”.  A description of the command, along with syntax, options, related commands, and examples will appear!

13 MATLAB Basics  In MATLAB, another way to get information about a command is via “doc”, which gives more detailed information than “help”.  Try “doc plot”. This command does not work as well in Octave!

14 MATLAB Basics  Many MATLAB functions are created from M-files, which are programs that contain a set of commands.  These commands are run in order to implement the function.  To see the contents of an m-file, use the “type” command.  This command does not work as well in Octave!  Try “type linspace”.

15 MATLAB Basics  To re-enter a command, use the up or down arrow, or type the first few letters of the command, and hit return!  To clear out your Command Window, use “clc”.  Commands in the Command History can be re-entered by double-clicking on them! The Octave GUI must be on for this to work!

16 Entering Matrices  Matrices are the basic “building blocks” of MATLAB - essentially everything MATLAB does is based on calculations involving a matrix.  The most basic way to enter a matrix is by typing in the entries, inside square brackets, with row entries separated by spaces and new rows designated by semicolons.  Try entering these!

17 The Colon Operator  Another way to enter a matrix is via the colon, which is used to define increments within a vector.  Try each of the following: x = [1:5] y = [1:0.1:5] z = [0:pi/4:2*pi]

18 The Colon Operator  We can “pull out” parts of a matrix with the colon!  Try each of the following:  A(2,:) is row 2 of matrix A.  A(:,3) is column 3 of matrix A.  B(1:2:3,:) is rows 1 and 3 of matrix B.

19 The Colon Operator  A(2,:) = [] removes the second row from A.  To insert the row back in, we can concatenate matrices via A = [A(1,:); ; A(2,:)].  Try w = [x x].  For more information on the colon operator, type “help colon”.

20 Matrix Operations  To re-display matrix A, type “A”.  Matrix Operations:  Addition: +  Subtraction: -  Matrix Multiplication: *  Matrix Power: ^  Transpose – i.e. switch columns and rows (conjugate transpose in the complex case): ’  To transpose a matrix with complex entries, use.’  Inverse of a square matrix A: inv(A).  Matrix Left Division: \ (usage A\B = inv(A)*B)  Matrix Right Division: / (usage A/B = A*inv(B))  Example 1: Try each of the following! AA BB  A+A  A-A  A+B  A*B  B*A  inv(A)  A*inv(A)  A/A  A\A  A\B  inv(A)*B  A^3  A*A*A  A’  A(1,1) = 2+i  A’  A.’

21 Matrix Operations - Example 1 (cont.)

22 Array Operations  Scalar Multiplication: k*A with k a scalar.  “Normal” arithmetic works as expected with the usual order of operations – each number is a 1 x 1 matrix.  Array Multiplication, i.e. entry-wise multiplication of matrices of the same size: A.*B  Array Division, i.e. entry-wise division of matrices of the same size: A./B  Array Exponentiation, i.e. entry-wise exponentiation of matrices of the same size: A.^B  Example 2: Try each of the following!  A(1,1)=1  C = 5*A  C(:,1) = [1 1 1]  A.*C  A./C  A.*B  A.^C  A.*inv(A)  A.^3  1+2/3*4^7

23 Array Operations – Example 2 (cont.)

24 Special Matrices and Matrix Functions  “eye(n)” gives an n x n identity matrix  “zeros(m,n)” gives an m x n matrix of 0’s.  “ones(m,n)” gives an m x n matrix of 1’s.  “det(A)” computes the determinant of an n x n matrix A. (Recall that for A to be invertible, det(A)  0 must hold!)  To clear matrix A out of the Workspace, use “clear A”. To clear ALL variables out of the Workspace, use “clear all”.

25 Linear Systems of Equations  MATLAB can be used to solve systems of linear equations.  Example 3: Solve the system x + 2y = 1 3x + 4y = -1  Solution: This system can be written in matrix form AX=b with:

26 Linear Systems of Equations  Example 3 (cont.)  Check if det(A)  0.  If so, then X = inv(A)*b will follow!

27 Making a Table of Values for a Function  MATLAB can be used to evaluate functions at input values entered as a vector!  For multiplication, division, and powers, use the array versions of these operators.  Example 4: Try the following commands to make a table of values of the function y = (x*sin(x 2 )-4)/(x+1).  x = [1:0.5:5]; % The ; suppresses output to the screen!  y = (x.*sin(x.^2)-4)./(x+1); % Array operators used here.  [x; y] % Concatenate the two vectors.  [x; y]’ % Transpose the matrix with x in column 1 and y in column 2 to get our table!

Creating an M-file  One of the most powerful features of MATLAB is the M- file, which is a file containing a set of commands that can be executed by MATLAB.  M-files syntax: *.m  These can be created as a text file and saved as an M-file.  To call the editor to make an M-file, type “edit”.  M-files can also be made from within MATLAB via pull-down menus File->New->M-file or by highlighting the commands in the Command History window. In the Octave GUI, choose File->New File.  Create an M-file that contains the commands used to make the table in Example 4 above!  Save it on the Desktop as example4.m 28

29 MATLAB’s Path and Running an M- file  To run the M-file we created, we need to put the directory containing the file in MATLAB’s path.  To do this, type “addpath ‘DIRECTORY’ ”, where the ‘DIRECTORY’ is where the file is located, for example, a command like this should be used: “addpath ‘C:\Users\MAK\Desktop’”  In MATLAB, this can also be done via the pull-down menus File->Set Path.  To run the set of commands, type the name of the M-file in the Command Window!

30 The Plot Command  MATLAB’s “plot” command is used to draw graphs of functions.  This is done by plotting (x, y) ordered pairs on a coordinate plane.  To plot the table created above, use the command “plot(x,y)”.  Notice that the graph we get is very jagged – to smooth it out, add more x-values and corresponding y-values to the vectors x and y!

31 The Plot Command  To the right is the same graph as above, with the commands:  x = [1:0.05:5];  y = (x.*sin(x.^2)-4)./(x+1);  plot(x,y)  To add a title, axes labels, and a grid to the graph, use the “title”, “xlabel”, “ylabel”, and “grid” commands!  title(‘y = f(x)’)  xlabel(‘x’)  ylabel(‘y’)  grid on  Try these, then put them into your example4 M-file.  Try plotting y = x*cos(x) on the interval [-,3].

32 Plotting More Than One Function  To plot more than one function on the same graph, use the plot command with the sets of input and output variables listed in order: plot(x,y,x1,y1).  Colors and plot styles can also be specified – to see a complete list of the available options, type “help plot” or “doc plot”.  Here is how to plot the functions f(x) = x^2 and f’(x) = 2x on the same graph!  x = [-1:0.1:2];  y = x.*x;  y1 = 2*x;  plot(x,y,’ro’,x,y1,’b-’)  title(‘y = f(x) and y = f’’(x)’)  xlabel(‘x’)  ylabel(‘y’)  legend(’y=x^2’,’y’’=2x’)

33 Piecewise Defined Functions  In order to plot a piecewise defined function, we concatenate the separate pieces.  x1 = [-2:0.1:0];  y1 = x1.^2 + 1;  x2 = [0:0.1:2];  y2 = sin(x2) +1;  x = [x1 x2];  y = [y1 y2];  plot(x,y,’g’)  xlabel(‘x’)  ylabel(‘y’)  title(’f(x)=x^2, if x is in [-2,0]; sin(x) + 1, if x is in (0,2]’)

34 References  Using MATLAB in Calculus by Gary Jenson  MATLAB Help Files – Getting Started  MATLAB Tutorial from the University of Utah at ab/matlab.html ab/matlab.html  Octave