Introduction to Matlab Tutorial for CS4MN3/SE3X03 Wen Yu McMaster University.

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.
Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to Matlab
Introduction to Graphing Using MATLAB. Line Graphs  Useful for graphing functions  Useful for displaying data trends over time  Useful for showing.
Matlab Graphics S. Awad, Ph.D. M. Corless, M.S.E.E. E.C.E. Department University of Michigan-Dearborn Introduction to Matlab: 2D Graphics.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
CS231A Matlab Tutorial Philip Lee Winter Overview  Goals › Introduction to Matlab › Matlab Snippets › Basic image manipulations › Helpful Matlab.
MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time.
MA/CS375 Fall MA/CS 375 Fall 2002 Lecture 4.
Introduction to MATLAB
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB.
Introduction to Matlab 332:202 Discrete Mathematics Spring 2007.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
MATLAB Fundamentals.
What is MATLAB ? MATrix LABratory –Originally, it was a front-end to FORTRAN matrix routines developed in the U. of New Mexico and Stanford –Today.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
What is Matlab? A software environment for interactive numerical computations Examples: –Matrix computations and linear algebra –Solving nonlinear equations.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
GNU/Qt Octave Rohin Kumar Y, Dept. of Physics & Astro Physics, University of Delhi.
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
Eng Advanced Marine Vehicles Todays agenda: Lab tomorrow at 2pm (structures lab) ‏ Advanced Marine Party Introduction to Matlab.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
IC3003 B ASIC S CIENTIFIC C OMPUTING Lecture 1 Monday 08:30-11:30 U204a.
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)
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.
EECE 360/460 Matlab Tutorial Jan Outline What is Matlab? What is Matlab? Matlab Interface Matlab Interface Basic Syntax Basic Syntax Plotting Graphs.
MATLAB Tutorial EE 327 Signals and Systems 1. What is MATLAB? MATLAB – Matrix Laboratory The premier number-crunching software Extremely useful for signal.
Eng Ship Structures 1 Introduction to Matlab.
INTRODUCTION TO MATLAB LAB# 01
COMP 116: Introduction to Scientific Programming Lecture 5: Plotting, Scripts and publishing.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
MATLAB Harri Saarnisaari, Part of Simulations and Tools for Telecommunication Course.
MAE 1202: AEROSPACE PRACTICUM An Introduction to MATLAB: Part 2 Mechanical and Aerospace Engineering Department Florida Institute of Technology Developed.
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
ES 240: Scientific and Engineering Computation. Chapter 2 Chapter 2: MATLAB Fundamentals Uchechukwu Ofoegbu Temple University.
Introduction to MATLAB. CSPP58001 MATLAB MATLAB is is a matrix-based language well suited for carrying out numerical analysis. It has many, many high-
Master in Optical Fiber Communications and Photonic Technologies Foundations of Digital Transmission - Fall quarter Introduction to Matlab.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB Lecture 18.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
EGR 106 Lecture 6 2-D Plotting Graphical presentation has become the standard method to show technical information. Engineers use plots to analyze, visualize,
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
Introduction to Matlab Patrice Koehl Department of Biological Sciences National University of Singapore
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Introduction to Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
An Introduction to Programming in Matlab Emily Blumenthal
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.
MAE 421 Matlab review Prof. Mark Glauser Created by: David Marr.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
ECE 1304 Introduction to Electrical and Computer Engineering
MATLAB DENC 2533 ECADD LAB 9.
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
MATLAB How to use (using M-files) Double click this icon
MATLAB Tutorial Dr. David W. Graham.
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
MATLAB How to use (using M-files) Double click this icon
MATLAB How to use (using M-files)
Plotting Signals in MATLAB
Introduction to Matlab
Presentation transcript:

Introduction to Matlab Tutorial for CS4MN3/SE3X03 Wen Yu McMaster University

Matlab Overview Matlab is a commercial "Matrix Laboratory" package which operates as an interactive programming environment Matlab is installed in Moore - ssh moore - change to working directory - matlab - quit or exit

Entering matrices On the interactive window A = [1 2 3 A = [1,2,3; 4,5,6; 7,8,9] ] From Files - data files: load data.ext - script files: data.m Built-in statements and functions: rand(2,3) From blocks: B = [A, zeros(3,2); zeros(2,3), eye(2)]

Operations Matrix operations: +, -, *, ^, ‘, \, / - x = A\b is the solution of A x = b - x = b/A is the solution of x A = b - b/A = (A’\b’)’ Array operations (entry-wise):.*,.^,.\,./ - [1,2,3,4].*[1,2,3,4] = [1,2,3,4].^2 = [1,4,9,16]

Statements, Expressions, and Variables Matlab is an expression language variable = expression, or simply expression Expressions are assigned to default variable ans A statement is terminated with (;), (,) or carriage return A statement can be placed in several lines Several statements can be placed in one line

Control Statement for i = m:k:n statements end while relation statements end if relation statements end

Relations Relational operators:, =, ==, ~= Logical operators: &, |, ~ A relation between matrices is true if the relation of each entry is true any(any(A ~= B)) returns true if any entry of A and B is not equal

Submatrices and Colon Notation 1:5 gives [ ] 0.2:0.2:1.2 gives [0.2, 0.4, 0.6, 0.8, 1.0, 1.2] 5:-1:1 gives [ ] B(1:4,3) first four entries of the third column B(:,3) the third column B(1:4,:) first four rows C=B, B(:,[2 4 5]) = C(:,1:3) B(:,[2,4]) = B(:,[2,4])*[1 2;3 4]

M-files A script file consists of a sequence of normal MATLAB statements Variables in a script file are global Function files provide extensibility to MATLAB Variables in a function file are by default local function [out1, out2, …] = fname(in1, in2, …) A comment line begins with the % symbol

Text s = 'This is a string‘ disp(‘This message is hereby displayed') error('Sorry, the matrix must be symmetric') iter = input('Enter the number of iterations: ') fprintf(1,‘This is a string, too.’)

Output Format. format short fixed point with 4 decimal places (the default) format long fixed point with 14 decimal places format short e scientific notation with 4 decimal places format long e scientific notation with 15 decimal places format rat approximation by ratio of small integers format hex hexadecimal format format bank fixed dollars and cents Format compact suppress most blank lines

Graphics Polar plot: t=0:.01:2*pi; polar(t,abs(sin(2*t).*cos(2*t))); Line plot: x=0:0.05:5;,y=sin(x.^2);,plot(x,y); Stem plot: x = 0:0.1:4;, y = sin(x.^2).*exp(-x); stem(x,y)

Graphics – cond. Mesh plot: z=peaks(25);, mesh(z); Surface plot: z=peaks(25);, surf(z);, colormap(jet); Contour plot: z=peaks(25);,contour(z,16); Quiver plot:

Titles, Axes labeled, and Text title graph title xlabel x-axis label ylabel y-axis label text position text at specified coordinates

Axis axis([xmin,xmax,ymin,ymax]) set axis scaling to prescribed limits axis(axis) freezes scaling for subsequent graphs axis auto returns to auto-scaling v = axis returns vector v showing current scaling axis square same scale on both axes axis equal same scale and tic marks on both axes axis off turns off axis scaling and tic marks axis on turns on axis scaling and tic marks

Line- and Mark-types Linetypes: solid (-), dashed (--). dotted (:), dashdot (-.) Marktypes: point (.), plus (+), star (*), circle (o), x-mark (x)

Other Useful Command for Graphics figure creates an empty figure window hold on freezes the current graphics screen hold off releases the hold print -deps -f3 filename saves to filename.eps the graphics figure 3 saveas(gcf, ‘plot2.eps’) save current figure as graphics file.

References MATLAB Primer, Kermit Sigmon, Department of Mathematics, University of Florida Introduction to Matlab, Joanna Waniek Matlab Tutorial, Prof. Matthias Hein Introduction to MATLAB, Markus Kuhn, University of Cambridge