Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1

Size: px
Start display at page:

Download "Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1"

Transcription

1 Chapter 2 (Part 2) MATLAB Basics dr.dcd.h CS 101 /SJC 5th Edition 1

2 Display Format In the command window, integers are always displayed as integers Characters are always displayed as strings Other values are displayed using a specified display format No matter what display format you choose, MATLAB uses double precision floating point values in its calculations dr.dcd.h CS 101 /SJC 5th Edition 2

3 Display Format 2 The display format can be changed by using format command For example: format short Default display format can be changed via the Preferences manually dr.dcd.h CS 101 /SJC 5th Edition 3

4 Display Format 2 The default format shows four digits after the decimal point, it is also known as short format Descriptions Example short 4 digits after decimal long 14 digits after decimal short e 5 digits plus exponent e+000 short g 5 digits plus w/ or w/o exponent long e 15 digits plus exponent e+000 long g 15 digits plus w/ or w/o exponent bank dollars and cents format 3.14 hex 4-bit hexadecimal fb54442d18 rat approximate ratio of small integers 355/113 compact loose approximate ratio of small integers restore extra line feeds + only displays signs + dr.dcd.h CS 101 /SJC 5th Edition 4

5 The disp Function The disp function displays the contents of a numerical matrix or a string The general form of disp function disp(variable) dr.dcd.h CS 101 /SJC 5th Edition 5

6 The disp Function 2 To represent report that contains numbers and string, the following converting functions can be used: num2str: convert a number to a string int2str: convert an integer to a string dr.dcd.h CS 101 /SJC 5th Edition 6

7 The disp Function 3 To include an apostrophe ( ) in a string, you need to enter the apostrophe twice. It is easier to think the syntax contains two strings. disp( I m what I am ) dr.dcd.h CS 101 /SJC 5th Edition 7

8 Formatted Output: fprintf fprintf function displays one or more values together with related text and provides control over the way values are displayed. The general form of fprintf function fprintf(format, data) format is a string describing the way the data is to be printed data is one or more scalars or arrays dr.dcd.h CS 101 /SJC 5th Edition 8

9 Formatted Output: fprintf 2 The general form of disp function fprintf(format, data) format is a string describing the way the data is to be printed data is one or more scalars or arrays The format is a string containing text plus special conversion characters describing the format of the data dr.dcd.h CS 101 /SJC 5th Edition 9

10 Formatted Output: fprintf 3 Common conversion characters: %? Desired Results %d display value as an integer %e display value in exponential form %f display value in floating-point form %g display value in either floating-point or.exponential form, whichever is shorter %s display value as a string \n line feed, skip to a new line dr.dcd.h CS 101 /SJC 5th Edition 10

11 Formatted Output: fprintf 4 A few fprintf examples: Use double % to insert a percentage sign in an fprintf statement. dr.dcd.h CS 101 /SJC 5th Edition 11

12 Formatted Output: fprintf 5 Advanced formatting characters Extra Format Character Descriptions + display + sign if data is positive display data in a left-adjusted fashion m m.n display data in a field m-digits wide display data in a field m-digits wide,.including n-digits after the decimal point 0 replaces extra blanks by zeros For example: fprintf( %07.2f\n, ) produces dr.dcd.h CS 101 /SJC 5th Edition 12

13 Formatted Output: fprintf 6 Display a string in different formats: dr.dcd.h CS 101 /SJC 5th Edition 13

14 Formatted Output: fprintf 7 Display a number in different formats: dr.dcd.h CS 101 /SJC 5th Edition 14

15 ASCII ASCII stands for American Standard Code for Information Interchange. ASCII encodes 128 characters into 7-bits. They are digits 0 to 9, letters a to z and A to Z, punctuations, control codes, and a space. dr.dcd.h CS 101 /SJC 5th Edition 15

16 ASCII 2 The ASCII chart: dr.dcd.h CS 101 /SJC 5th Edition 16

17 ASCII 3 To include West European languages an additional bit is added, this 8-bit code is called the extended-ascii code. dr.dcd.h CS 101 /SJC 5th Edition 17

18 Data Files The save command saves data from the current workspace into a disk file. The general form of save function save < ascii> filename <var_list> By default, the filename will be given the extension mat. If no variables are specified, all variables in the workspace will be saved. If option ascii is used, the data will be saved in an ASCII file with the exponential form. dr.dcd.h CS 101 /SJC 5th Edition 18

19 Data Files 2 dr.dcd.h CS 101 /SJC 5th Edition 19

20 Data Files 3 The file wsav01.mat can not be opened externally outside the MATLAB The file wsav02 can be opened by edit function or notepad. ASCII code for xyz Note that when the ascii option is used, information such as variable names and types will be lost. dr.dcd.h CS 101 /SJC 5th Edition 20

21 Data Files 4 The load command loads data from a disk file into the current workspace. The general form of load function load filename load mat filename.dat If a MAT-file is loaded, all of the variables will be restored with the names and types. dr.dcd.h CS 101 /SJC 5th Edition 21

22 Data Files 5 Data having different column sizes should not be saved together if the ascii option will be used. dr.dcd.h CS 101 /SJC 5th Edition 22

23 Data Files 6 The contents of an ASCII-file will be converted into an array having the same name as the file (w/o the extension). Data having different column sizes should not be saved together if the ascii option will be used. dr.dcd.h CS 101 /SJC 5th Edition 23

24 Scalar Arithmetic Operations Arithmetic Operation Algebraic Form MATLAB Form Addition a + b a + b Subtraction a b a b Multiplication a x b a * b Division a b a / b or b \ a Exponentiation a b a ^ b Note: b\a is called the left division. Parentheses may be used to group terms and the subexpressions inside the parentheses are evaluated first. dr.dcd.h CS 101 /SJC 5th Edition 24

25 Scalar Arithmetic Operations 2 Parentheses may be used to group terms and the sub-expressions inside the parentheses are evaluated first. For example: 2^(8+6/3) returns ^8+6/3 returns 258 dr.dcd.h CS 101 /SJC 5th Edition 25

26 Array & Matrix Operations Operation Syntax Descriptions Array Addition a + b Array addition and matrix addition are identical. Array Subtraction a b Array subtraction and matrix subtraction are identical. Array Multiplication a.* b Element-by-element multiplication of a and b : a(i,j)*b(i,j). Both a and b must be the same shape. Matrix Multiplication a * b The no. of columns in a must equal the no. of rows in b. Array Right Division Array Left Division Matrix Right Division Matrix Left Division Array Exponentiation a./ b a.\ b a / b a \ b a.^ b Element-by-element division of a and b: a(i,j)/b(i,j). Both arrays must be the same shape. Element-by-element division of a and b: b(i,j)/a(i,j). Both arrays must be the same shape. In MATLAB, it is defined by a*inv(b), where inv(b) is the inverse of b. In MATLAB, it is defined by inv(a)*b, where inv(a) is the inverse of a. Element-by-element exponential of a and b: a(i,j)^b(i,j). Both a and b must be the same shape. Element-by-element operation is performed on corresponding elements in the associated two arrays. dr.dcd.h CS 101 /SJC 5th Edition 26

27 Array & Matrix Operations 2 Array operation between two arrays: Array multiplication: Matrix multiplication: dr.dcd.h CS 101 /SJC 5th Edition 27

28 Precedence of Arithmetic Operations Precedence Descriptions Perform calculations inside all parentheses, working from the innermost set to the outermost. Perform all exponentials, working from left to right. Perform all multiplications and divisions, working from left to right. Perform all additions and subtractions, working from left to right. Note: a^b^c is not evaluated as but (a^b)^c. dr.dcd.h CS 101 /SJC 5th Edition 28

29 Solutions of Linear Equations Consider the following system of three equations with three unknowns: 3x + 2y z = 10 x + 3y + 2z = 5 x y z = 1 which can be expressed as AX = B where A=, B= and X=. It can be solved for X using linear algebra. The solution is X = A -1 B = dr.dcd.h CS 101 /SJC 5th Edition 29

30 Homework Assignment #4 Quiz 2.3 Page 51: 2, 3 Quiz 2.4 Page 58: 1, 2 This assignment is due by next week. Late submission will be penalized. dr.dcd.h CS 101 /SJC 5th Edition 30

31 Common MATLAB Functions Mathmatical functions: abs, min, max, mod, rem cos, sin, tan acos, asin, atan, atan2(y,x) exp, log, log10, sqrt Rounding functions ceil, floor, round, fix String conversion functions char, double, int2str, num2str, str2num dr.dcd.h CS 101 /SJC 5th Edition 31

32 Mathematical Functions abs(x): returns x or the magnitude if x is a complex number. [maximum, index]=max(x): returns the maximum value in array x and its index. [minimum, index]=min(x): returns the minimum value in array x and its index. dr.dcd.h CS 101 /SJC 5th Edition 32

33 Mathematical Functions 2 Both mod(x,y) and rem(x,y) return the reminder after division. The mod function produces a result that is either zero or has the same sign as the divisor. The rem function produces a result that is either zero or has the same sign as the dividend. dr.dcd.h CS 101 /SJC 5th Edition 33

34 Mathematical Functions 3 atan2(y,x): returns over 4 quadrants of angle. dr.dcd.h CS 101 /SJC 5th Edition 34

35 Rounding Functions ceil(x): rounds x to the nearest integer towards. fix(x): rounds x to the nearest integer towards 0. floor(x): rounds x to the nearest integer towards round(x): rounds x to the nearest integer. dr.dcd.h CS 101 /SJC 5th Edition 35

36 String Conversion Functions char: converts numbers to a string. double: converts an array of char to ASCII codes. int2str: converts a number to an integer string. num2str: converts a number to a string. str2num: converts a string to a number. dr.dcd.h CS 101 /SJC 5th Edition 36

37 Two-Dimensional Plots The general form of plot function plot(x, y) y is a 1-1 function of x When plot is execute, a figure window opens. Title and axis labels can be added by title(str) xlabel(str) ylabel(str) Grid lines can be enabled/disable by grid on/off dr.dcd.h CS 101 /SJC 5th Edition 37

38 Two-Dimensional Plots 2 dr.dcd.h CS 101 /SJC 5th Edition 38

39 Save Plots The print command can be used to save a plot as an image from a M-script print <option> filename Valid options deps: monochrome encapsulated postscript image depsc: color encapsulated postscript image djpeg: JPEG image dpng: portable network graphic image dtiff: compressed TIFF image dr.dcd.h CS 101 /SJC 5th Edition 39

40 Save Plots 2 Use File/Save As menu option on the Figure Window to save a graphical image. dr.dcd.h CS 101 /SJC 5th Edition 40

41 Multiple Plots 1st method: plot two functions y 1 =f(x 1 ) and y 2 =g(x 2 ) at once plot(x 1, y 1, x 2, y 2, ) x 1 and x 2 can be defined over different ranges For example: f(x) = sin(2x) The first derivation of f(x) = 2 cos(2x) To plot them side-by-side for comparison dr.dcd.h CS 101 /SJC 5th Edition 41

42 Multiple Plots 2 dr.dcd.h CS 101 /SJC 5th Edition 42

43 Multiple Plots 3 2nd method: plot y 1 and y 2 separately with hold function enabled plot(x 1, y 1 ) hold on: Retain current plot when adding new plots plot(x 2, y 2 ) hold off: next plot will clear up figure space first dr.dcd.h CS 101 /SJC 5th Edition 43

44 Multiple Plots 4 dr.dcd.h CS 101 /SJC 5th Edition 44

45 Graph Properties You can change the appearance of your plots by selecting user defined line styles color mark styles. Legends can be added by legend(str1, str2,, <position>) Position: Best least conflict with the figure NorthWest North NorthEast West East SouthWest South SouthEast dr.dcd.h CS 101 /SJC 5th Edition 45

46 Graph Properties 2 Line Style Indicator Marker Style Indicator Color Indicator solid - point. blue b dotted : circle o green g dash-dot -. x-mark x red r dashed -- plus + cyan c (none) (no line) star * magenta m square s yellow y diamond d black k triangle down triangle up v ^ triangle left < triangle right > pentagram hexagram p h dr.dcd.h CS 101 /SJC 5th Edition 46

47 Specify Graph Property plot(x, y, opstr) Opstr combining line style, marker style, and color For example: :ok indicates dotted line :, circle marker o, and black color k. legend(str_list, Location, Best ) Best least conflict with the figure All locations can be outside plot, eg. BestOutside dr.dcd.h CS 101 /SJC 5th Edition 47

48 Specify Graph Property 2 dr.dcd.h CS 101 /SJC 5th Edition 48

49 Specify Graph Property 3 dr.dcd.h CS 101 /SJC 5th Edition 49

50 Logarithmic Plots A logarithmic scale (base 10) is useful if a variable ranges over many orders of magnitude, or data varies exponentially. semilogy uses a log10 scale on the y axis semilogx uses a log10 scale on the x axis loglog uses a log10 scale on both axes dr.dcd.h CS 101 /SJC 5th Edition 50

51 Logarithmic Plots 2 dr.dcd.h CS 101 /SJC 5th Edition 51

52 Logarithmic Plots 3 dr.dcd.h CS 101 /SJC 5th Edition 52

53 Example 2.4 Figure below shows a voltage source V=120 Volt with an internal resistance R S of 50 W supplying a load of resistance of R L. Find the value of load resistance that will result in the maximum possible power being supplies by the source to the load. Plot the power supplied to the load as a function of R L. dr.dcd.h CS 101 /SJC 5th Edition 53

54 Example The power supplied to the load R L is given by P L = I 2 R L where I is the current supplied to the load, it can be obtained by Ohm s law V R S +R L Procedures to perform the work: Define an array of possible values for R L Compute the current for each value of R L Compute the supplied power for each value of R L Plot the power supplied to the load for each value of R L Determine the maximum power dr.dcd.h CS 101 /SJC 5th Edition 54

55 Example dr.dcd.h CS 101 /SJC 5th Edition 55

56 Example dr.dcd.h CS 101 /SJC 5th Edition 56

57 Homework Assignment # Exercises Page 83: This assignment is due by next week. Late submission will be penalized. dr.dcd.h CS 101 /SJC 5th Edition 57

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

MATLAB Introduction to MATLAB Programming

MATLAB Introduction to MATLAB Programming MATLAB Introduction to MATLAB Programming MATLAB Scripts So far we have typed all the commands in the Command Window which were executed when we hit Enter. Although every MATLAB command can be executed

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

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

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

Chapter 2. MATLAB Basis

Chapter 2. MATLAB Basis Chapter MATLAB Basis Learning Objectives:. Write simple program modules to implement single numerical methods and algorithms. Use variables, operators, and control structures to implement simple sequential

More information

1. Register an account on: using your Oxford address

1. Register an account on:   using your Oxford  address 1P10a MATLAB 1.1 Introduction MATLAB stands for Matrix Laboratories. It is a tool that provides a graphical interface for numerical and symbolic computation along with a number of data analysis, simulation

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

ENGR 1181 Autumn 2015 Final Exam Study Guide and Practice Problems

ENGR 1181 Autumn 2015 Final Exam Study Guide and Practice Problems ENGR 1181 Autumn 2015 Final Exam Study Guide and Practice Problems Disclaimer Problems seen in this study guide may resemble problems relating mainly to the pertinent homework assignments. Reading this

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

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

Consider this m file that creates a file that you can load data into called rain.txt

Consider this m file that creates a file that you can load data into called rain.txt SAVING AND IMPORTING DATA FROM A DATA FILES AND PROCESSING AS A ONE DIMENSIONAL ARRAY If we save data in a file sequentially than we can call it back sequentially into a row vector. Consider this m file

More information

A Guide to Using Some Basic MATLAB Functions

A Guide to Using Some Basic MATLAB Functions A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available

More information

Math 2250 MATLAB TUTORIAL Fall 2005

Math 2250 MATLAB TUTORIAL Fall 2005 Math 2250 MATLAB TUTORIAL Fall 2005 Math Computer Lab The Mathematics Computer Lab is located in the T. Benny Rushing Mathematics Center (located underneath the plaza connecting JWB and LCB) room 155C.

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

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

1 Introduction to Matlab

1 Introduction to Matlab 1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

More information

Lab 1 Intro to MATLAB and FreeMat

Lab 1 Intro to MATLAB and FreeMat Lab 1 Intro to MATLAB and FreeMat Objectives concepts 1. Variables, vectors, and arrays 2. Plotting data 3. Script files skills 1. Use MATLAB to solve homework problems 2. Plot lab data and mathematical

More information

Chapter 3: Introduction to MATLAB Programming (4 th ed.)

Chapter 3: Introduction to MATLAB Programming (4 th ed.) Chapter 3: Introduction to MATLAB Programming (4 th ed.) Algorithms MATLAB scripts Input / Output o disp versus fprintf Graphs Read and write variables (.mat files) User-defined Functions o Definition

More information

Prof. Manoochehr Shirzaei. RaTlab.asu.edu

Prof. Manoochehr Shirzaei. RaTlab.asu.edu RaTlab.asu.edu Introduction To MATLAB Introduction To MATLAB This lecture is an introduction of the basic MATLAB commands. We learn; Functions Procedures for naming and saving the user generated files

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

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

Programming 1. Script files. help cd Example:

Programming 1. Script files. help cd Example: Programming Until now we worked with Matlab interactively, executing simple statements line by line, often reentering the same sequences of commands. Alternatively, we can store the Matlab input commands

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 Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed MATLAB Constants, Variables & Expression Introduction MATLAB can be used as a powerful programming language. It do have IF, WHILE, FOR lops similar to other programming languages. It has its own vocabulary

More information

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division Excel R Tips EXCEL TIP 1: INPUTTING FORMULAS To input a formula in Excel, click on the cell you want to place your formula in, and begin your formula with an equals sign (=). There are several functions

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

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

Mechanical Engineering Department Second Year (2015)

Mechanical Engineering Department Second Year (2015) Lecture 7: Graphs Basic Plotting MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. This section describes a few of the most

More information

STAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006

STAT 391 Handout 1 Making Plots with Matlab Mar 26, 2006 STAT 39 Handout Making Plots with Matlab Mar 26, 26 c Marina Meilă & Lei Xu mmp@cs.washington.edu This is intended to help you mainly with the graphics in the homework. Matlab is a matrix oriented mathematics

More information

Introduction to Scientific and Engineering Computing, BIL108E. Karaman

Introduction to Scientific and Engineering Computing, BIL108E. Karaman USING MATLAB INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 To start from Windows, Double click the Matlab icon. To start from UNIX, Dr. S. Gökhan type matlab at the shell prompt.

More information

Quick MATLAB Syntax Guide

Quick MATLAB Syntax Guide Quick MATLAB Syntax Guide Some useful things, not everything if-statement Structure: if (a = = = ~=

More information

CS-201 Introduction to Programming with Java

CS-201 Introduction to Programming with Java CS-201 Introduction to Programming with Java California State University, Los Angeles Computer Science Department Lecture V: Mathematical Functions, Characters, and Strings Introduction How would you estimate

More information

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression.

Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression. What is the answer? >> Logical Subscripting: This kind of subscripting can be done in one step by specifying the logical operation as the subscripting expression. The finite(x)is true for all finite numerical

More information

LAB 1 General MATLAB Information 1

LAB 1 General MATLAB Information 1 LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by

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

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP) Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

More information

PROGRAMMING WITH MATLAB WEEK 6

PROGRAMMING WITH MATLAB WEEK 6 PROGRAMMING WITH MATLAB WEEK 6 Plot: Syntax: plot(x, y, r.- ) Color Marker Linestyle The line color, marker style and line style can be changed by adding a string argument. to select and delete lines

More information

Lecturer: Keyvan Dehmamy

Lecturer: Keyvan Dehmamy MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

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

ENGR 1181c Midterm Exam 2: Study Guide and Practice Problems

ENGR 1181c Midterm Exam 2: Study Guide and Practice Problems ENGR 1181c Midterm Exam 2: Study Guide and Practice Problems Disclaimer Problems seen in this study guide may resemble problems relating mainly to the pertinent homework assignments. Reading this study

More information

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation

CDA5530: Performance Models of Computers and Networks. Chapter 8: Using Matlab for Performance Analysis and Simulation CDA5530: Performance Models of Computers and Networks Chapter 8: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

More information

Additional Plot Types and Plot Formatting

Additional Plot Types and Plot Formatting Additional Plot Types and Plot Formatting The xy plot is the most commonly used plot type in MAT- LAB Engineers frequently plot either a measured or calculated dependent variable, say y, versus an independent

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Anthony J. O Connor School of Science, Griffith University, Brisbane, Australia 1. What is MATLAB? MATLAB started as an interactive program for doing matrix calculations and has

More information

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD

Introduction to MATLAB for Numerical Analysis and Mathematical Modeling. Selis Önel, PhD Introduction to MATLAB for Numerical Analysis and Mathematical Modeling Selis Önel, PhD Advantages over other programs Contains large number of functions that access numerical libraries (LINPACK, EISPACK)

More information

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau) Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau) January 24, 2010 Starting Under windows Click on the Start menu button

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

CHAPTER 3 PART 1 MATLAB FUNDAMENTALS

CHAPTER 3 PART 1 MATLAB FUNDAMENTALS CHAPTER 3 PART 1 MATLAB FUNDAMENTALS Chapter 3 : TOPIC COVERS (PROGRAMMING with MATLAB) MATLAB Environment Use of Built-In Functions and Graphics LEARNING OUTCOMES INTRODUCTION It is expected that students

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

MATLAB Guide to Fibonacci Numbers

MATLAB Guide to Fibonacci Numbers MATLAB Guide to Fibonacci Numbers and the Golden Ratio A Simplified Approach Peter I. Kattan Petra Books www.petrabooks.com Peter I. Kattan, PhD Correspondence about this book may be sent to the author

More information

Lecture 2 Introduction to MATLAB. Dr.Tony Cahill

Lecture 2 Introduction to MATLAB. Dr.Tony Cahill Lecture 2 Introduction to MATLAB Dr.Tony Cahill The MATLAB Environment The Desktop Environment Command Window (Interactive commands) Command History Window Edit/Debug Window Workspace Browser Figure Windows

More information

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation CDA6530: Performance Models of Computers and Networks Chapter 4: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

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

Graphing Calculator Tutorial

Graphing Calculator Tutorial Graphing Calculator Tutorial This tutorial is designed as an interactive activity. The best way to learn the calculator functions will be to work the examples on your own calculator as you read the tutorial.

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

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

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

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

Introduction to GNU-Octave

Introduction to GNU-Octave Introduction to GNU-Octave Dr. K.R. Chowdhary, Professor & Campus Director, JIETCOE JIET College of Engineering Email: kr.chowdhary@jietjodhpur.ac.in Web-Page: http://www.krchowdhary.com July 11, 2016

More information

MATLAB primer for CHE 225

MATLAB primer for CHE 225 MATLAB primer for CHE 225 The following pages contain a brief description of the MATLAB features are used in CHE 225. This document is best used in conjunction with the MATLAB codes posted on Vista. Find

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

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

Chapter 2 MATLAB Basics

Chapter 2 MATLAB Basics EGR115 Introduction to Computing for Engineers MATLAB Basics from: S.J. Chapman, MATLAB Programming for Engineers, 5 th Ed. 2016 Cengage Learning Topics 2.1 Variables & Arrays 2.2 Creating & Initializing

More information

Mathematical Operations with Arrays and Matrices

Mathematical Operations with Arrays and Matrices Mathematical Operations with Arrays and Matrices Array Operators (element-by-element) (important) + Addition A+B adds B and A - Subtraction A-B subtracts B from A.* Element-wise multiplication.^ Element-wise

More information

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types

Introduction to Computer Programming in Python Dr. William C. Bulko. Data Types Introduction to Computer Programming in Python Dr William C Bulko Data Types 2017 What is a data type? A data type is the kind of value represented by a constant or stored by a variable So far, you have

More information

What is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions

What is a Function? EF102 - Spring, A&S Lecture 4 Matlab Functions What is a Function? EF102 - Spring, 2002 A&S Lecture 4 Matlab Functions What is a M-file? Matlab Building Blocks Matlab commands Built-in commands (if, for, ) Built-in functions sin, cos, max, min Matlab

More information

1 Introduction to MATLAB

1 Introduction to MATLAB 1 Introduction to MATLAB 1.1 General considerations The aim of this laboratory is to review some useful MATLAB commands in digital signal processing. MATLAB is one of the fastest and most enjoyable ways

More information

What is MATLAB and howtostart it up?

What is MATLAB and howtostart it up? MAT rix LABoratory What is MATLAB and howtostart it up? Object-oriented high-level interactive software package for scientific and engineering numerical computations Enables easy manipulation of matrix

More information

MATLAB. MATLAB Review. MATLAB Basics: Variables. MATLAB Basics: Variables. MATLAB Basics: Subarrays. MATLAB Basics: Subarrays

MATLAB. MATLAB Review. MATLAB Basics: Variables. MATLAB Basics: Variables. MATLAB Basics: Subarrays. MATLAB Basics: Subarrays MATLAB MATLAB Review Selim Aksoy Bilkent University Department of Computer Engineering saksoy@cs.bilkent.edu.tr MATLAB Basics Top-down Program Design, Relational and Logical Operators Branches and Loops

More information

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation CDA6530: Performance Models of Computers and Networks Chapter 4: Using Matlab for Performance Analysis and Simulation Objective Learn a useful tool for mathematical analysis and simulation Interpreted

More information

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text

Getting Started. Chapter 1. How to Get Matlab. 1.1 Before We Begin Matlab to Accompany Lay s Linear Algebra Text Chapter 1 Getting Started How to Get Matlab Matlab physically resides on each of the computers in the Olin Hall labs. See your instructor if you need an account on these machines. If you are going to go

More information

workspace list the variables and describe their matrix sizes 4x1 matrix (4 rows, 1 column) x=[3.4, 7, 2.2] 1x3 matrix (1 row, 3 columns)

workspace list the variables and describe their matrix sizes 4x1 matrix (4 rows, 1 column) x=[3.4, 7, 2.2] 1x3 matrix (1 row, 3 columns) An Introduction To MATLAB Lecture 3 Basic MATLAB Commands quit exit who whos quits MATLAB quits MATLAB lists all of the variables in your MATLAB workspace list the variables and describe their matrix sizes

More information

ELEMENTARY MATLAB PROGRAMMING

ELEMENTARY MATLAB PROGRAMMING 1 ELEMENTARY MATLAB PROGRAMMING (Version R2013a used here so some differences may be encountered) COPYRIGHT Irving K. Robbins 1992, 1998, 2014, 2015 All rights reserved INTRODUCTION % It is assumed the

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 4 Visualising Data Dr Richard Greenaway 4 Visualising Data 4.1 Simple Data Plotting You should now be familiar with the plot function which is

More information

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab

Overview. Lecture 13: Graphics and Visualisation. Graphics & Visualisation 2D plotting. Graphics and visualisation of data in Matlab Overview Lecture 13: Graphics and Visualisation Graphics & Visualisation 2D plotting 1. Plots for one or multiple sets of data, logarithmic scale plots 2. Axis control & Annotation 3. Other forms of 2D

More information

Computer Programming in MATLAB

Computer Programming in MATLAB Computer Programming in MATLAB Prof. Dr. İrfan KAYMAZ Atatürk University Engineering Faculty Department of Mechanical Engineering What is a computer??? Computer is a device that computes, especially a

More information

Arithmetic. 2.2.l Basic Arithmetic Operations. 2.2 Arithmetic 37

Arithmetic. 2.2.l Basic Arithmetic Operations. 2.2 Arithmetic 37 2.2 Arithmetic 37 This is particularly important when programs are written by more than one person. It may be obvious to you that cv stands for can volume and not current velocity, but will it be obvious

More information

9/4/2018. Chapter 2 (Part 1) MATLAB Basics. Arrays. Arrays 2. Arrays 3. Variables 2. Variables

9/4/2018. Chapter 2 (Part 1) MATLAB Basics. Arrays. Arrays 2. Arrays 3. Variables 2. Variables Chapter 2 (Part 1) MATLAB Basics Arrays The fundamental unit of data in MATLAB is the array. An array is a collection of data values organized into rows and columns and is known by a specified name. Individual

More information

Numerical Analysis First Term Dr. Selcuk CANKURT

Numerical Analysis First Term Dr. Selcuk CANKURT ISHIK UNIVERSITY FACULTY OF ENGINEERING and DEPARTMENT OF COMPUTER ENGINEERING Numerical Analysis 2017-2018 First Term Dr. Selcuk CANKURT selcuk.cankurt@ishik.edu.iq Textbook Main Textbook MATLAB for Engineers,

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

2.2 Creating & Initializing Variables in MATLAB

2.2 Creating & Initializing Variables in MATLAB 2.2 Creating & Initializing Variables in MATLAB Slide 5 of 27 Do-It-Yourself (DIY) EXERCISE 2-1 Answer the followings: (a) What is the difference between an array, a matrix, and a vector? (b) Let: c =

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

Diocese of Boise Math Curriculum 5 th grade

Diocese of Boise Math Curriculum 5 th grade Diocese of Boise Math Curriculum 5 th grade ESSENTIAL Sample Questions Below: What can affect the relationshi p between numbers? What does a decimal represent? How do we compare decimals? How do we round

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

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

ENGR Fall Exam 1

ENGR Fall Exam 1 ENGR 13100 Fall 2012 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

Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999

Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999 Attia, John Okyere. Control Statements. Electronics and Circuit Analysis using MATLAB. Ed. John Okyere Attia Boca Raton: CRC Press LLC, 1999 1999 by CRC PRESS LLC CHAPTER THREE CONTROL STATEMENTS 3.1 FOR

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

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano

MATLAB Lesson I. Chiara Lelli. October 2, Politecnico di Milano MATLAB Lesson I Chiara Lelli Politecnico di Milano October 2, 2012 MATLAB MATLAB (MATrix LABoratory) is an interactive software system for: scientific computing statistical analysis vector and matrix computations

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

3+2 3*2 3/2 3^2 3**2 In matlab, use ^ or ** for exponentiation. In fortran, use only ** not ^ VARIABLES LECTURE 1: ARITHMETIC AND FUNCTIONS

3+2 3*2 3/2 3^2 3**2 In matlab, use ^ or ** for exponentiation. In fortran, use only ** not ^ VARIABLES LECTURE 1: ARITHMETIC AND FUNCTIONS LECTURE 1: ARITHMETIC AND FUNCTIONS MATH 190 WEBSITE: www.math.hawaii.edu/ gautier/190.html PREREQUISITE: You must have taken or be taking Calculus I concurrently. If not taken here, specify the college

More information

Fall 2017: Numerical Methods I Assignment 1 (due Sep. 21, 2017)

Fall 2017: Numerical Methods I Assignment 1 (due Sep. 21, 2017) MATH-GA 2010.001/CSCI-GA 2420.001, Georg Stadler (NYU Courant) Fall 2017: Numerical Methods I Assignment 1 (due Sep. 21, 2017) Objectives. This class is for you and you should try to get the most out of

More information

Integer Operations. Summer Packet 7 th into 8 th grade 1. Name = = = = = 6.

Integer Operations. Summer Packet 7 th into 8 th grade 1. Name = = = = = 6. Summer Packet 7 th into 8 th grade 1 Integer Operations Name Adding Integers If the signs are the same, add the numbers and keep the sign. 7 + 9 = 16-2 + -6 = -8 If the signs are different, find the difference

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 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

An Introductory Tutorial on Matlab

An Introductory Tutorial on Matlab 1. Starting Matlab An Introductory Tutorial on Matlab We follow the default layout of Matlab. The Command Window is used to enter MATLAB functions at the command line prompt >>. The Command History Window

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

Numerical Methods Lecture 1

Numerical Methods Lecture 1 Numerical Methods Lecture 1 Basics of MATLAB by Pavel Ludvík The recommended textbook: Numerical Methods Lecture 1 by Pavel Ludvík 2 / 30 The recommended textbook: Title: Numerical methods with worked

More information

Academic Vocabulary CONTENT BUILDER FOR THE PLC MATH GRADE 5

Academic Vocabulary CONTENT BUILDER FOR THE PLC MATH GRADE 5 Academic Vocabulary CONTENT BUILDER FOR THE PLC MATH GRADE 5 STANDARD 5.2(B) compare and order two decimals to thousandths and represent comparisons using the symbols >,

More information

MEI GeoGebra Tasks for A2 Core

MEI GeoGebra Tasks for A2 Core Task 1: Functions The Modulus Function 1. Plot the graph of y = x : use y = x or y = abs(x) 2. Plot the graph of y = ax+b : use y = ax + b or y = abs(ax+b) If prompted click Create Sliders. What combination

More information