MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.

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 Engineering MATLAB – 11 Plotting - 4 Agenda Multiple curves Multiple plot.
1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
MATLAB Basics CS 111 Introduction to Computing in Engineering and Science.
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Introduction to MATLAB
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB.
Lecture 2 MATLAB fundamentals Variables, Naming Rules, Arrays (numbers, scalars, vectors, matrices), Arithmetical Operations, Defining and manipulating.
Introduction to MATLAB
Matrix Mathematics in MATLAB and Excel
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.
Matlab intro The Environment
Part 1 Chapter 2 MATLAB Fundamentals
MATLAB Fundamentals.
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
1 M ATLAB Short Course. History of Calculator 2 3 Introduction to Matlab Matlab is short for Matrix Laboratory Matlab is also a programming language.
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.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Introduction to MATLAB
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Introduction to MATLAB 58:111 Numerical Calculations Department of Mechanical and Industrial Engineering.
CSE123 Lecture 5 Arrays and Array Operations. Definitions Scalars: Variables that represent single numbers. Note that complex numbers are also scalars,
How to Use MATLAB A Brief Introduction. 2 What can MATLAB do? Matrix Operations Symbolic Computations Simulations Programming 2D/3D Visualization.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
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
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Peng Liu Haas School of Business University of California, Berkeley
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-
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 18P. 1Winter Quarter Introduction to MATLAB Lecture 18.
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.
1 Lecture 1 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
ES 240: Scientific and Engineering Computation. Chapter 8 Chapter 8: Linear Algebraic Equations and Matrices Uchechukwu Ofoegbu Temple University.
Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University and Prof. Steve Chapra, Tufts University All.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Array Creation ENGR 1187 MATLAB 2. Today’s Topics  Arrays: What are they?  Vectors  Matrices  Creating Arrays.
Introduction to Matlab Electromagnetic Theory LAB by Engr. Mian Shahzad Iqbal.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
INTRODUCTION TO MATLAB Dr. Hugh Blanton ENTC 4347.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Introduction to MATLAB 1.Basic functions 2.Vectors, matrices, and arithmetic 3.Flow Constructs (Loops, If, etc) 4.Create M-files 5.Plotting.
ECE 351 M ATLAB I NTRODUCTION ( BY T EACHING A SSISTANTS )
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Matlab for Engineers Matlab Environment Chapter 2.
CMPS 1371 Introduction to Computing for Engineers VECTORS.
1 Faculty Name Prof. A. A. Saati. 2 MATLAB Fundamentals 3 1.Reading home works ( Applied Numerical Methods )  CHAPTER 2: MATLAB Fundamentals (p.24)
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Introduction to MATLAB Ehsan Adeli M. Iran University of Science and Technology, E-Learing Center, Fall 2008 (1387)
CS100A, Fall 1998, Lecture 191 CS100A, Fall 1998 Lecture 19, Thursday Nov 05 Matlab Concepts: Matlab arrays Matlab subscripting Matlab plotting.
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
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
ECE 1304 Introduction to Electrical and Computer Engineering
MATLAB DENC 2533 ECADD LAB 9.
Introduction To MATLAB
EEE 244 Numerical Methods In Electrical Engineering
Part 1 Chapter 2 MATLAB Fundamentals
INTRODUCTION TO MATLAB
Part 1 Chapter 2 MATLAB Fundamentals
Announcements P3 due today
How to Use MATLAB A Brief Introduction.
Presentation transcript:

MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra (det, inv …) Plotting, plot(x,y,’r’), hist (colormap([0 0 0])), semilog, loglog

GETTING HELP type one of following commands in the command window: help – lists all the help topic help topic – provides help for the specified topic help command – provides help for the specified command help help – provides information on use of the help command helpwin – opens a separate help window for navigation lookfor keyword – Search all M-files for keyword

VARIABLES Variable names: Must start with a letter May contain only letters, digits, and the underscore “_” Matlab is case sensitive, i.e. one & OnE are different variables. Matlab only recognizes the first 31 characters in a variable name. Assignment statement: Variable = number; Variable = expression; Example: >> tutorial = 1234; >> tutorial = 1234 tutorial = 1234 NOTE: when a semi-colon ”;” is placed at the end of each command, the result is not displayed

VARIABLE CONT(‘) Special variables: ans : default variable name for the result pi: = ………… eps: = e-016, smallest amount by which 2 numbers can differ. Inf or inf : , infinity NaN or nan: not-a-number Commands involving variables: who: lists the names of defined variables whos: lists the names and sizes of defined variables clear: clears all varialbes, reset the default values of special variables. clear name: clears the variable name clc: clears the command window clf: clears the current figure and the graph window.

A row vector in MATLAB can be created by an explicit list, starting with a left bracket, entering the values separated by spaces (or commas) and closing the vector with a righ bracket. A column vector can be created the same way, and the rows are separated by semicolo VECTORS,MATRIXES,ARRAYS LINEAR ALGEBRA Example: >> x = [ *pi 0.5*pi 0.75*pi pi ] x = x is a row vector. >> y = [ 0; 0.25*pi; 0.5*pi; 0.75*pi; pi ] y = y is a column vector.

VECTORS CONT’ Vector Addressing – A vector element is addressed in MATLAB with index enclosed in parentheses. Example: >> x(3) ans =  1st to 3rd elements of vector x The colon notation may be used to address a block of elements. (start : increment : end) start is the starting index, increment is the amount to add to each successive is the ending index. A shortened format (start : end) may be used if increment Example: >> x(1:3) ans =  3rd element of vector x

MATRIX A is an m x n matrix.  A Matrix array is two-dimensional, having both multiple rows and multiple co similar to vector arrays:  it begins with [, and end with ]  spaces or commas are used to separate elements in a row  semicolon or enter is used to separate rows. Example: >> f = [ 1 2 3; f = >> h = [ ] h =

MATRIX CONT Matrix Addressing: -- matrixname(row, column) -- colon may be used in place of a row or column referrs the entire row or column. recall: f = h = Example: >> f(2,3) ans = 6 >> h(:,1) ans = 2 1

SOME USEFUL COMMANDS:  zeros(n) returns a n x n matrix of zeroes  zeros (m,n) returns a m x n matrix of zeroes  ones(n) returns a n x n matrix of ones  ones(m,n) returns a m x n matrix of ones  rand(n) returns a n x n matrix of random number  rand(m,n) returns a m x n matrix of random number  size (A) for a m x n matrix A, returns the row vector [m,n]  containing the number of rows and columns in matrix.  length(A) returns the larger of the number of rows or columns in A

Scalar-Array Mathematics For addition, subtraction, multiplication, and division of an array by a scalar simply apply the operations to all elements of the array. Example: >> f = [ 1 2; 3 4] f = >> g = 2*f – 1 Each element in the g = multiplied by 2, then subtracted 1 3 by

Example: >> x = [ ]; >> y = [ ]; >> z = x.* y z =

Solution by Matrix Inverse: Ax = b A-1 Ax = A-1 b x = A-1 b MATLAB: >> A = [ ; ; ]; >> b = [ 10; 5; -1]; >> x = inv(A)*b x = Answer: x 1 = -2, x2 = 5, x3 = -6 Solution by Matrix Division: The solution to the equation Ax = b can be computed using left division. MATLAB: Answer: >> A = [ ; ; ]; >> b = [ 10; 5; -1]; >> x = A\b x = x1 = -2, x2 = 5, x3 = -6

Plotting Curves: plot (x,y) – generates a linear plot of the values of x (horizontal axis) and y (vertical axis). semilogx (x,y) – generate a plot of the values of x and y using a logarithmic scale for x and a linear scale for y. semilogy (x,y) – generate a plot of the values of x and y using a linear scale for x and a logarithmic scale for y. loglog(x,y) – generate a plot of the values of x and y using logarithmic scales for both x and y.

Multiple Curves: plot (x, y, w, z) – multiple curves can be plotted on the same graph by using multiple arguments in a plot command. The variables x, y, w, and z are vectors. Two curves will be plotted: y vs. x, and z vs. w. legend (‘string1’, ‘string2’,…) – used to distinguish between plots on the same graph Multiple Figures: figure (n) – used in creation of multiple plot windows. place this command before the plot() command, and the corresponding figure will be labeled as “Figure n” close – closes the figure n window. close all – closes all the figure windows. Subplots: subplot (m, n, p) – m by n grid of windows, with p specifying the current plot as the pth window

Example: (polynomial function) plot the polynomial using linear/linear scale, log/ linear scale, linear/log scale, & log/log scale: y = 2x^2 + 7x + 9 CODE % Generate the polynomial: x = linspace (0, 10, 100); y = 2*x.^2 + 7*x + 9; % plotting the polynomial: figure (1); subplot (2,2,1), plot (x,y); title ('Polynomial, linear/linear scale'); ylabel ('y'), grid; subplot (2,2,2), semilogx (x,y); title ('Polynomial, log/linear scale'); ylabel ('y'), grid; subplot (2,2,3), semilogy (x,y); title ('Polynomial, linear/log scale'); xlabel('x'), ylabel ('y'), grid; subplot (2,2,4), loglog (x,y); title ('Polynomial, log/log scale'); xlabel('x'), ylabel ('y'), grid;

Exercise 1: Use Matlab command to obtain the following a) Extract the fourth row of the matrix generated by magic(6) b) Show the results of ‘x’ multiply by ‘y’ and ‘y’ divides by ‘x’. Given x = [0:0.1:1.1] and y = [10:21] c) Generate random matrix ‘r’ of size 4 by 5 with number varying between -8 and 9 Exercise 2: Use MATLAB commands to get exactly as the figure shown below x=pi/2:pi/10:2*pi; y=sin(x); z=cos(x);