Introduction to Matlab

Slides:



Advertisements
Similar presentations
Lab # 03- SS Basic Graphic Commands. Lab Objectives: To understand M-files principle. To plot multiple plots on a single graph. To use different parameters.
Advertisements

Introduction to Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to Matlab
Lecture (4) Plotting & Programming (1) Eng. Osama Talaat 1.
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 for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
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 Northeastern University: College of Computer and Information Science Co-op Preparation University (CPU) 10/27/2003.
MATLAB - Lecture 22A Two Dimensional Plots / Chapter 5 Topics Covered:
Vectors and Plotting Selim Aksoy Bilkent University Department of Computer Engineering
Introduction to Matlab Tutorial for CS4MN3/SE3X03 Wen Yu McMaster University.
MATLAB Week 3 17 November Outline Graphics – Basic plotting – Editing plots from GUI – Editing plots from m-file – Advanced plotting commands.
Introduction to Matlab 332:202 Discrete Mathematics Spring 2007.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
EPSII 59:006 Spring Outline Managing Your Session File Usage  Saving Workspace  Loading Data Files  Creating M-files More on Matrices Review.
MATLAB Fundamentals.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
PLOTS AND FIGURES DAVID COOPER SUMMER Plots One of the primary uses for MATLAB is to be able to create publication quality figures from you data.
ENG College of Engineering Engineering Education Innovation Center 1 2D Plots 1 in MATLAB Topics Covered: 1.Plotting basic 2-D plots The plot()
Introduction to MATLAB January 18, 2008 Steve Gu Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,
„  1999 BG Mobasseri1 9/18/2015 June 2 GRAPHICS IN MATLAB- PART I BASIC PLOTTING.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
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.
INTRODUCTION TO MATLAB LAB# 01
Lecture 2 - Matlab Introduction CVEN 302 June 5, 2002.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB – 2D Plots 1 Go to the class drive: ---> MatLab - Graphing ---> Seed Files.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Plot (x-values, y-values) >> x = linspace (-3, 3, 20); >> x = linspace (-3, 3, 20); >> y = 2*x – 1; >> y = 2*x – 1; >> plot (x, y) >> plot (x, y)
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.
ELG 3120 Lab 2 TAs Wei Zhang Ozgur Ekici (Section A) (Section B)
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 Engineering MATLAB – 9 Plotting - 2 Agenda Formatting plots.
NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS ( NET 222: COMMUNICATIONS AND NETWORKS FUNDAMENTALS (PRACTICAL PART) Lab 2 : potting to Matlab Networks.
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
An Introduction to Programming in Matlab Emily Blumenthal
EGR 106 – Week 5 – 2-D Plots Question : Why do engineers use plots? Answer : To analyze, visualize, and present data. Matlab has many useful plotting options.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation.
ECE 1304 Introduction to Electrical and Computer Engineering
Creating a Plot The plot function can take one or more inputs; e.g. plot (x, y) or plot (y) Note that in the two-argument version, the vectors x and.
Computer Application in Engineering Design
Introduction to Mat lab
3D-Graphs A 3D surface is defined as: z = f(x, y)
Ch3 Graphics Overview of Plotting Editing Plots
Course Information Do not rely on color to distinguish curves (due to black-white printout). Use different line styles to distinguish curves (solid, dashed,
Lecture 25: Exploring data
Matrices and Arrays.
MATLAB DENC 2533 ECADD LAB 9.
Introduction To MATLAB
Net 222: Communications and networks fundamentals (Practical Part)
Net 222: Communications and networks fundamentals (Practical Part)
Net 222: Communications and networks fundamentals (Practical Part)
MATLAB How to use (using M-files) Double click this icon
MATLAB Tutorial Dr. David W. Graham.
MATLAB How to use (using M-files) Double click this icon
Tutorial 2 SEG7550 Introduction to MATLAB II
MATLAB How to use (using M-files)
Introduction to MATLAB Plotting LAB 3
CSCI N317 Computation for Scientific Applications Unit 1 – 5 MATLAB
Yang-Ming University, Taipei, Taiwan
Introduction to MATLAB
Plotting Signals in MATLAB
Announcements P3 due today
How to Use MATLAB A Brief Introduction.
Presentation transcript:

Introduction to Matlab 332:202 Discrete Mathematics Spring 2007

Contents What is Matlab Matlab basic Advanced usage of Matlab - plots - loops - working with m files - advanced functions

Contents What is Matlab Matlab basic Advanced usage of Matlab

What is Matlab Matrix laboratory easy to learn robust powerful functions

Contents What is Matlab Matlab basic Advanced usage of Matlab

Get Help Help - help - help function name (help abs)

Basic Math Operations To compute a math expression composed of numbers and mathematics operators + addition - subtraction * multiplication / division ^ power Compute (2+3-9)*7^2/4 =-49

General Math Expressions To compute a math expression composed of numbers, variables and mathematics operators Define all variables The others are the same E.g. x=3;y=6;x+y=? It is equivalent to 3+6

Exercise in Class(1) 5 minutes x=123;y=234;z=345 Write the command expression and get the result: 1) the sum of x and y 2) subtract y from z 3) the multiplication of x and z Answer 1) x+y=357;2)z-y=111;3)x*z=42435

Vectors and Matrices Arrays are represented by some elements within brackets The elements of each row is separated by at least one space The separation of rows is by semicolons E.g. [2 3;1 2]

How to Retrieve Elements of Matrix 1 What is the difference between x(2),x(1,2),x(:,2),x(2,:),x(1:2,2)?

How to Retrieve Elements of Matrix 2 Index begins from 1, not 0 For matrix x: x(i) is the ith element, counted along the column x(i,j) is the element at the ith row and jth column x(:,j) is all the elements at the jth column x(i,:) is all the elements at the ith row x(i1:i2,j) is those elements at the jth column, begins from index i1 to i2

Vector and Matrix Operations +,-,*,/ are used in operations between matrices .*,./,.^ are used in operations between matrix elements Pay attention to the dimensions of vectors and matrices

Exercise in Class(2) 10 mins x=[1 2;3 4];y=[5 6;7 8]; z1=[1 2 3];z2=[4 5 6]; 1)Sum of x and y 2) Product of x and y 3)Bitwise product of x and y 4) Bitwise division of z1 over z2 5) Bitwise division of z1 over z2, but for the first two elements only (both the expression and result) Answer:1) [6 8;10 12]; 2) [19 22;43 50]; 3) [5 12;21 32];4)[0.25 0.4 0.5]; 5) z1(1:2)./z2(1:2)=[0.25 0.4]

Matrix Transpose More operators other than +,-,*,/,^ Matrix transpose:’(apostrophe)

Contents What is Matlab Matlab basic Advanced usage of Matlab

Plot plot(y) plots the columns of y versus their index plot(x,y) plots vector y versus vector x plot(x,y,s) plots vector y versus vector x, and s is a character string which states the line properties plot(X1,Y1,S1,X2,Y2,S2,X3,Y3,S3,...) combines the plots defined by the (X,Y,S) triples, where the X's and Y's are vectors or matrices and the S's are strings.

Color Options - Yellow - ‘y’ Magenta - ‘m’ Cyan - ‘c’ Red - ‘r’ Green - ‘g’ Blue - ‘b’ Black - ‘k’

Line Styles - solid line (default) -- dashed line : dotted line -. dash-dot line

Line Markings + - plus sign o - circle * - asterisk . - Point x - cross s - square d - diamond ^ - upward pointing triangle v - downward pointing triangle > - right pointing triangle < - left pointing triangle p - five-pointed star (pentagram) h - six-pointed star (hexagram) Combined use of color, line style, and line marking : ‘r+:’

Example 1)t=0:0.1:4*pi; x=sin(t); plot(x);plot(t,x); plot(t,x,’r’); plot(t,x, 'c+:’); 2)x=1:1:10;y=2*x; plot(x,y,'r-');

Exercise in Class 3 15 mins Write a short program which plots 2 lines in a graph. Two cycles of sin wave and cos wave. Useful function: plot, sin, cos t=0:0.1:4*pi; x=sin(t);y=cos(t); plot(t,x,'r+-',t,y,'bo-.');

Grid Grid or GRID ON adds major grid lines to the current axes. GRID OFF removes major and minor grid lines from the current axes.

Comment Functions xlabel('text') adds text beside the x-axis on the current axis ylabel('text') adds text beside the y-axis on the current axis title('text') adds text at the top of the current axis legend(string1,string2,string3, ...) puts a legend on the current plot using the specified strings as labels text(x,y,'string') adds the text in the quotes to location (X,Y) on the current axes

Axis AXIS Control axis scaling and appearance. AXIS([XMIN XMAX YMIN YMAX]) sets scaling for the x- and y-axes on the current plot. AXIS OFF turns off all axis labeling, tick marks and background. AXIS ON turns axis labeling, tick marks and background back on.

Exercise in Class 4 15 mins Write a short program which plots 2 lines in a graph. Two cycles of sin wave and cos wave. Use as many functions as you can: plot, sin, cos, grid, xlabel, ylabel, grid, title, legend, text, axis t=0:0.1:4*pi; x=sin(t); y=cos(t); plot(t,x,'r+-',t,y,'bo-.'); grid on; xlabel('The Time'); ylabel('The Amplitude'); title('Sin Wave and Cos Wave'); legend('Sin','Cos','Location','Best'); axis([0,4*pi,-2,2]); text(3/4*pi,sin(3/4*pi),'\leftarrow Sin'); text(9/4*pi,cos(9/4*pi),'\leftarrow Cos');

Plots and Graphs – Con’t HOLD ON holds the current plot and all axis properties so that subsequent graphing commands add to the existing graph. HOLD OFF returns to the default mode whereby PLOT commands erase the previous plots and reset all axis properties before drawing new plots. Figure or figure ( );

Save Figures Save manually Use Function Print - print filename directs the output to the PostScript file designated by filename - print -dformat filename exports the figure to the specified file using the specified graphics format, (such as TIFF). e.g. print –dmeta filename print -deps filename

Exercise in Class 5 5 mins Generate a figure, and save it as ps file and emf file, respectively

Plots and Graphs – Con’t One example, different views Plot3() x=-1:0.1:1; y=-1:0.1:1; z=x.^2+y.^2; plot3(x,y,z); Mesh(); contour(); meshc(); meshz(); Surf(); [x,y]=meshgrid(-1:0.1:1); mesh(x,y,z); H = SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into an m-by-n matrix of small axes, selects the p-th axes for the current plot, and returns the axis handle. The axes are counted along the top row of the Figure window, then the second row, etc.

Basic Control Statements-for for, end for variable=expression statement; end expression: initial value: increment: end value for i=1:5 for j=1:4 A(i,j)=1/(i+j-1); end;

Exercise in Class 6 10 mins Write a for program to compute 0.5+1+1.5+2+…+50 x=0; for i=0.5:0.5:50 x=x+i; end

Basic Control Statements-while while, end while expression statement; end expression: a logical statement which is connected by ==,<,<=,>,>=,~=. x=1; while x<5 x=x+1;

Exercise in Class 7 10 mins Write a while program to compute 0.5+1+1.5+2+…+50 i=0.5;x=0; while i<=50 x=x+i; i=i+0.5; end

Basic Control Statements-if if, elseif, end IF expression statements ELSEIF expression ELSE END

M Files Put a bunch of commands in an .m file. Run the file under the command window. The using of ‘;’. Write a function as an .m file. - file name is the function name - the first line defines the function function myresutl=myfunction(a, b); - the comment lines (start with %) follow the first line is shown when asking for help

Exercise in Class 10 mins Write a m file to compute 0.5+1+1.5+2+…+50 Run it

Useful Links www.mathworks.com Google