Chapter 2. MATLAB Basis

Size: px
Start display at page:

Download "Chapter 2. MATLAB Basis"

Transcription

1 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 algorithms Topics/Outline:. Arrays. Load and Save. Disp and fprintf..m-files 5. Plotting Chapter M: MATLAB Basis

2 Variables and Arrays The fundamental unit of data in MATLAB program is the array (Vector or Matrix) Even single value variables (Scalars) All operations are optimized for vector use Loops run slower in MATLAB than in Fortran (not a vector operation) size command gives size of the matrix Scalars, Vectors, Matrices MATLAB treat variables as arrays (matrices) Matrix (m n) - a set of numbers arranged in rows (m) and columns (n) Scalar: matrix Row Vector: n matrix Column Vector: m matrix A 5. 7 B C B'. 7. D Chapter M: MATLAB Basis

3 Array: Data Organized into rows and columns Row Row Row A(,5) Row Col Col Col Col Col 5 Col 6 MATLAB Arrays Arrays fundamental unit of data 5. A matrix A = [,,-.5,,;,,.5,-,5]; Optional, use if it helps readability (comma) Start new row (semicolon) Suppress display (semicolon) Chapter M: MATLAB Basis

4 Data types All numbers are double precision The numerical values can be real, imaginary (i or j), or complex Text is stored as arrays of characters You don t have to declare the type of data (defined when running) MATLAB is case-sensitive!!! var = -.; var = i; var = -j; var =.5+.i; var5 = sqrt(.5); string = This is a character string String = Please enter your NetID Variable Names Usually, the name is identified with the problem Variable names may consist of up to 6 characters Variable names may be alphabetic, digits, and the underscore character ( _ ) Variable names must start with a letter ABC, A, C56, CVEN_, _address day, year, iteration, max time, velocity, distance, area, density, pressure Time, TIME, time (case sensitive!!) Chapter M: MATLAB Basis

5 Initializing Variables Explicitly list the values reads from a data file uses the colon (:) operator reads from the keyboard A = [; ; 5; ]; B = [ 5; -6 -] C = [ 5 ; (continuation) -; 5 -] E = [A; ; A]; F = [C(,); A] Matrix Concatenation z x u v ; y 7 9 x y 7 9 x ; y 7 9 x y ; y x Chapter M: MATLAB Basis 5

6 Chapter M: MATLAB Basis 6 E 5 C Colon Operator Creating new matrices (extracting subarrays) from an existing matrix C = [,,5; -,,;,,-;,,] E = C(:,:) = [- ; -] Colon Operator Creating new matrices from an existing matrix C = [,,5; -,,;,,-;,,] G 5 C G = C(:,:) = [,;,]

7 The end Function In array operations, end returns the highest value of a subscript C = [ 5; - ; -; ] H = C(:end,:end) = [ ; ] C 5 H Colon Operator Use subarrays on the LHS of a matrix Update elements of the existing array C = [ 5; - ; -; ] C([ ],:) = [ ; 5 6] C 5 C 5 6 Chapter M: MATLAB Basis 7

8 Chapter M: MATLAB Basis 8 Colon Operator Variable_name = first:incr:last time =.:.5:.5 time = [.,.5,.,.5,.,.5] values = :-: values = [, 9, 8, 7, 6, 5,,, ] linspace gives evenly spaced values x = linspace(,5); y = linspace(-pi,pi) x = linspace(a,b,n_pts) Special Matrices ones(,) ones() zeros(,) eye() Built-in MATLAB functions: zeros, ones, eye

9 Multidimensional Arrays» A(:,:,)=[ -5 7; 9 -];» A(:,:,)=[- 6; - 6];» A A(:,:,) = A(:,:,) = - 6-6» whos A Name Size Bytes Class A xx 96 double array Grand total is elements using 96 bytes MATLAB allocates array elements in column major order. A(,,),A(,,),A(,,),A(,,),A(,,),A(,,), A(,,),A(,,),A(,,),A(,,),A(,,),A(,,) Predefined Special Values The predefined values may be used any time in MATLAB without initializing them first Function Purpose pi (= ) i, j (imaginary part of a complex number) Inf Machine infinity (divided by ) NaN Not-a-Number. Undefined mathematical operation. clock (year, month, day, hour, minute, second) date day-month-year, such as -Jan- eps epsilon, smallest difference between two numbers that can be represented on the computer ans store the result of unassigned variables Chapter M: MATLAB Basis 9

10 >> pi ans =.6 >> size(pi) ans = >> a=[ ; 5 6] a = 5 6 >> size(a) ans = pi.6 a= a 5 6 MATLAB Example» x=+5-. x = 7.8» y=*x^+5 y = 87.5» z=x*sqrt(y) z = 6.86» A=[ ; 5 6] A = 5 6» b=[;;5] b = 5» C=A*b C = 5» who Your variables are: A b y C x z» whos Name Size Bytes Class A x 8 double array C x 6 double array b x double array x x 8 double array y x 8 double array z x 8 double array» save Saving to: matlab.mat» save matrix default filename filename matrix Chapter M: MATLAB Basis

11 Initializing Variables with Keypad Input It is possible to prompt a user and initialize a variable with data input at the keyboard Name = input( Enter your name:, s ) SID = input( Enter your student ID: ) Tel = input( Telephone number: ) Cell = input( Cell phone number: ) = input( address:, s ) Input may be a value or a character string Array Operations An array operation is performed element-by-element C() A()* B(); C() A()* B(); C() A()* B(); C() A()* B(); C(5) A(5)* B(5); MATLAB: C = A.*B; Dot-operator works for.*,./,.^ Not needed for +, - Chapter M: MATLAB Basis

12 Element-by-Element Operations Symbol Operation Form Example Scalar-array addition AB [, 6] [ 7, 9] Scalar-array subtraction AB [ 8, ] 6 [, ] Array addition AB [, 6] [ 8, ] [, 9] Array subtraction AB [, 6] [ 8, ] [, ].* Array multiplication A.* B [, 6].*[, ] [ 6, 8]./ Array right division A. / B [, 7]. / [ 8, 5] [ / 8, 7 / 5].\ Array left division A.\ B [, 7]. \ [ 8, 5] [ \ 8, 7 \ 5].^ Array exponentiation A.^ B [, ].^ [ ^, ^ ] [ 6, 8].^[, 5] [ ^, ^ 5] [ 9, ] [ 5, ].^[, ] [ 5 ^, ^ ] [ 5, 8] Hierarchy of Arithmetic Operations. Parentheses, starting with the innermost pair. Exponentiation, from left to right. Multiplication and division with equal precedence, from left to right. Addition and subtraction with equal precedence, from left to right >> distance =.5 * accel * time^ >> distance =.5 * accel *(time^) >> distance = (.5 * accel * time)^ distance = distance distance Chapter M: MATLAB Basis

13 Chapter M: MATLAB Basis But a*b gives an error (undefined) because dimensions are incorrect. Need to use.* Vector and Matrix operations 7 b a 6 b 5 a 5* 6 * * a.* b Vectorized Matrix Operations 9 8 ).^ B ( F A.^ E B / A. D B A.* C 5 B 8 A

14 Array Operations for m n Matrices A : ; - : - : -; - 5 B A.* C A.^ Matrix Multiplications Recall how matrix multiplication works a d b e g c h f i j ag bh ci k dg eh fi l aj bk cl dj ek fl g h i j a k d l b e ga jd c ha kd f ia ld gb je hb ke ib le gc jf hc kf ic lf [A]*[B] [B]*[A] Chapter M: MATLAB Basis

15 Matrix Multiplication Matrix multiplication can be performed only if the inner dimensions are equal MATLAB In Fortran, the matrix multiplication has to be done by Do Loops In MATLAB, it is automatic A*B = C Note no period (not element-by-element operation) For vectors A*x = b Chapter M: MATLAB Basis 5

16 Chapter M: MATLAB Basis 6 Matrix Transpose ) ( )( ) ( ) )( ( - y' x * x'* y - y' ; x' y ; x Built-in Functions Use help elfun for a list of elementary math functions All the standard operators +, -, *, /, ^ sin, cos, exp, tanh, log, log, etc. These operators are vectorized exp() exp(5) exp() exp(a) ; sin() sin(5) sin() sin( a ) ; 5 a

17 Common MATLAB Built-in Mathematical Functions abs(x) sin(x), cos(x), tan(x) asin(x), acos(x), atan(x), atan(y,x) angle(x) phase angle of complex x exp(x) sqrt(x) log(x), log(x) mod(x,y) remainder or modulo function [value,index] = max(x) [value,index] = min(x) Common MATLAB Built-in Rounding Functions ceil(x) rounds x to the nearest integer towards + fix(x) rounds x to the nearest integer towards floor(x) rounds x to the nearest integer towards round(x) rounds x to the nearest integer ceil(7.6) = 8, ceil(-7.6) = -7 fix(7.6) = 7, fix(-7.6) = -7 floor(7.6) = 7, floor(-7.6) = -8 round(7,6) = 7, round(-7.6) = -7 Chapter M: MATLAB Basis 7

18 Common MATLAB Built-in String Conversion Functions char(x) convert a matrix of numbers into a character string double(x) convert a character string into a matrix of numbers intstr(x) covert x into an integer character string numstr(x) convert x into a character string strnum(x) converts character sting s into a numeric array» string = 'Texas'; double(string) ans = » x=[8 97 5]; char(x) ans = Texas» intstr('tamu Civil') ans = See Table in Appendix A for ASCII character set MAT Files Data Files memory efficient binary format preferable for internal use by MATLAB program ASCII files in ASCII characters useful if the data is to be shared (imported or exported to other programs) ASCII American Standard Code for Information Interchange Chapter M: MATLAB Basis 8

19 MATLAB Input To read files in if the file is an ascii table, use load if the file is ascii but not a table, file I/O needs fopen and fclose Reading in data from file using fopen depends on type of data (binary or text) Default data type is binary Save Files 8-digit text format (variable list) save <fname> <vlist> -ascii 6-digit text format save <fname> <vlist> -ascii -double Delimit elements with tabs save <fname> <vlist> -ascii -double -tabs Example: Vel = [ 5; -6 -] save velocity.dat Vel -ascii.e+.e+ 5.e+ -6.e+.e+ -.e+ Chapter M: MATLAB Basis 9

20 Load Files Read velocity into a matrix velocity.dat >> load velocity.dat >> velocity velocity = e+.e+ 5.e+ -6.e+.e+ -.e+ Load Files Create an ASCII file temperature.dat % Time Temperature read Time and Temperature from temp.dat >> load temperature.dat >> temperature Note: temperature is a 6 matrix Chapter M: MATLAB Basis

21 MATLAB Output Matlab automatically prints the results of any calculation (unless suppressed by semicolon ;) Use disp to print out text to screen disp (x.*y) disp ( Temperature = ) sprintf - display combination Make a string to print to the screen output = sprintf( Pi is equal to %f, pi) MATLAB Output numstr: convert a number to a string intstr: convert an integer to a string (round the element to integer)» string = ['The value of Pi = ' numstr(pi)];» disp (string) The value of Pi =.6» string = ['Value of sqrt(.5) ~ ' intstr(sqrt(.5))];» disp (string) Value of sqrt(.5) ~ Chapter M: MATLAB Basis

22 Formatted Output fprintf (format-string, var,.) %[flags] [width] [.precision] type Examples of type fields %d display value as an integer %e display in exponential format %f display in floating point or decimal notation %g display using %e or %f, depending on which is shorter %% display % \n skip to a new line Numeric Display Format MATLAB Command Display Example format short default.6 format long decimals format bank decimals. format short e decimals.6e format long e 5 decimals e format,,blank x = [5 - -]; format + x = [ ] (+/- sign only) (blank for ) Chapter M: MATLAB Basis

23 fprintf( ) of Scalar temp = 98.6; fprintf( The temperature is %8.f degrees F.\n, temp); The temperature is 98.6 degrees F. fprintf( The temperature is %8.f degrees F.\n, temp); The temperature is 98.6 degrees F. fprintf( The temperature is %8.e degrees F.\n, temp); The temperature is 9.86e+ degrees F. fprintf( ) of Scalar speed =.; fprintf( The speed is %8.f m/s. \n, speed); Save at least 8 characters with decimal digits The speed is. m/s. speed = 59.5; fprintf( The speed is %6.f cm/s. \n, speed); Save at least 6 characters with decimal digits The speed is 59. cm/s. Chapter M: MATLAB Basis

24 fprintf( ) of Matrices score = [ ; ; ] fprintf( Game %d score: Houston: %d Dallas: %d \n, score) Game score: Houston: 75 Dallas: 99 Game score: Houston: 88 Dallas: 8 Game score: Houston: Dallas: 95 Game score: Houston: 9 Dallas: 5 M-Files You can create and save code in text files using MATLAB Editor/Debugger or other text editors (called m-files since the ending must be.m) Use % to add comments These files are called programs. They are similar to FORTRAN or C source codes. A script can be executed by typing the file name, or using the run command MATLAB executes everything stored in a.m file one line after the other as if the commands were entered in the command window Chapter M: MATLAB Basis

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

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

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

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An. CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An

Outline. CSE 1570 Interacting with MATLAB. Starting MATLAB. Outline (Cont d) MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An CSE 170 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

More information

Introduction to MATLAB

Introduction to MATLAB to MATLAB Spring 2019 to MATLAB Spring 2019 1 / 39 The Basics What is MATLAB? MATLAB Short for Matrix Laboratory matrix data structures are at the heart of programming in MATLAB We will consider arrays

More information

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An.

Outline. CSE 1570 Interacting with MATLAB. Outline. Starting MATLAB. MATLAB Windows. MATLAB Desktop Window. Instructor: Aijun An. CSE 10 Interacting with MATLAB Instructor: Aijun An Department of Computer Science and Engineering York University aan@cse.yorku.ca Outline Starting MATLAB MATLAB Windows Using the Command Window Some

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

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

Chapter 2 (Part 2) MATLAB Basics. dr.dcd.h CS 101 /SJC 5th Edition 1 Chapter 2 (Part 2) MATLAB Basics dr.dcd.h CS 101 /SJC 5th Edition 1 Display Format In the command window, integers are always displayed as integers Characters are always displayed as strings Other values

More information

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT

PROGRAMMING WITH MATLAB DR. AHMET AKBULUT PROGRAMMING WITH MATLAB DR. AHMET AKBULUT OVERVIEW WEEK 1 What is MATLAB? A powerful software tool: Scientific and engineering computations Signal processing Data analysis and visualization Physical system

More information

Digital Image Analysis and Processing CPE

Digital Image Analysis and Processing CPE Digital Image Analysis and Processing CPE 0907544 Matlab Tutorial Dr. Iyad Jafar Outline Matlab Environment Matlab as Calculator Common Mathematical Functions Defining Vectors and Arrays Addressing Vectors

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

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

EP375 Computational Physics

EP375 Computational Physics EP375 Computational Physics Topic 1 MATLAB TUTORIAL BASICS Department of Engineering Physics University of Gaziantep Feb 2014 Sayfa 1 Basic Commands help command get help for a command clear all clears

More information

Introduction to MATLAB

Introduction to MATLAB ELG 3125 - Lab 1 Introduction to MATLAB TA: Chao Wang (cwang103@site.uottawa.ca) 2008 Fall ELG 3125 Signal and System Analysis P. 1 Do You Speak MATLAB? MATLAB - The Language of Technical Computing ELG

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

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

Quick MATLAB Syntax Guide

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

More information

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing SECTION 1: INTRODUCTION ENGR 112 Introduction to Engineering Computing 2 Course Overview What is Programming? 3 Programming The implementation of algorithms in a particular computer programming language

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

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional.

MATLAB NOTES. Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional. MATLAB NOTES Matlab designed for numerical computing. Strongly oriented towards use of arrays, one and two dimensional. Excellent graphics that are easy to use. Powerful interactive facilities; and programs

More information

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to. Starting Matlab Go to MATLAB Laboratory 09/09/10 Lecture Lisa A. Oberbroeckling Loyola University Maryland loberbroeckling@loyola.edu http://ctx.loyola.edu and login with your Loyola name and password...

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

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB 1 Introduction to MATLAB A Tutorial for the Course Computational Intelligence http://www.igi.tugraz.at/lehre/ci Stefan Häusler Institute for Theoretical Computer Science Inffeldgasse

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

CME 192: Introduction to Matlab

CME 192: Introduction to Matlab CME 192: Introduction to Matlab Matlab Basics Brett Naul January 15, 2015 Recap Using the command window interactively Variables: Assignment, Identifier rules, Workspace, command who and whos Setting the

More information

1 Week 1: Basics of scientific programming I

1 Week 1: Basics of scientific programming I MTH739N/P/U: Topics in Scientific Computing Autumn 2016 1 Week 1: Basics of scientific programming I 1.1 Introduction The aim of this course is use computing software platforms to solve scientific and

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

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

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

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 Short Introduction to Matlab

A Short Introduction to Matlab A Short Introduction to Matlab Sheng Xu & Daniel Reynolds SMU Mathematics, 2015 1 What is Matlab? Matlab is a computer language with many ready-to-use powerful and reliable algorithms for doing numerical

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

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

MATLAB QUICK START TUTORIAL

MATLAB QUICK START TUTORIAL MATLAB QUICK START TUTORIAL This tutorial is a brief introduction to MATLAB which is considered one of the most powerful languages of technical computing. In the following sections, the basic knowledge

More information

Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Kristian Sandberg Department of Applied Mathematics University of Colorado Goal The goal with this worksheet is to give a brief introduction to the mathematical software Matlab.

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

2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

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

To start using Matlab, you only need be concerned with the command window for now.

To start using Matlab, you only need be concerned with the command window for now. Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,

More information

Dr Richard Greenaway

Dr Richard Greenaway SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

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

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

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

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

Chapter 3. built in functions help feature elementary math functions data analysis functions random number functions computational limits

Chapter 3. built in functions help feature elementary math functions data analysis functions random number functions computational limits Chapter 3 built in functions help feature elementary math functions data analysis functions random number functions computational limits I have used resources for instructors, available from the publisher

More information

Lab 1 - Worksheet Spring 2013

Lab 1 - Worksheet Spring 2013 Math 300 UMKC Lab 1 - Worksheet Spring 2013 Learning Objectives: 1. How to use Matlab as a calculator 2. Learn about Matlab built in functions 3. Matrix and Vector arithmetics 4. MATLAB rref command 5.

More information

Laboratory 1 Octave Tutorial

Laboratory 1 Octave Tutorial Signals, Spectra and Signal Processing Laboratory 1 Octave Tutorial 1.1 Introduction The purpose of this lab 1 is to become familiar with the GNU Octave 2 software environment. 1.2 Octave Review All laboratory

More information

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control

More information

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots

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

Matlab as a calculator

Matlab as a calculator Why Matlab? Matlab is an interactive, high-level, user-friendly programming and visualization environment. It allows much faster programs development in comparison with the traditional low-level compiled

More information

Welcome to EGR 106 Foundations of Engineering II

Welcome to EGR 106 Foundations of Engineering II Welcome to EGR 106 Foundations of Engineering II Course information Today s specific topics: Computation and algorithms MATLAB Basics Demonstrations Material in textbook chapter 1 Computation What is computation?

More information

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab MATH 495.3 (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab Below is a screen similar to what you should see when you open Matlab. The command window is the large box to the right containing the

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

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB The Desktop When you start MATLAB, the desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB. The following

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

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial

CSI31 Lecture 5. Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial CSI31 Lecture 5 Topics: 3.1 Numeric Data Types 3.2 Using the Math Library 3.3 Accumulating Results: Factorial 1 3.1 Numberic Data Types When computers were first developed, they were seen primarily as

More information

AMS 27L LAB #1 Winter 2009

AMS 27L LAB #1 Winter 2009 AMS 27L LAB #1 Winter 2009 Introduction to MATLAB Objectives: 1. To introduce the use of the MATLAB software package 2. To learn elementary mathematics in MATLAB Getting Started: Log onto your machine

More information

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student

More information

Introduction to MATLAB for Engineers, Third Edition

Introduction to MATLAB for Engineers, Third Edition PowerPoint to accompany Introduction to MATLAB for Engineers, Third Edition William J. Palm III Chapter 2 Numeric, Cell, and Structure Arrays Copyright 2010. The McGraw-Hill Companies, Inc. This work is

More information

Matlab Programming Introduction 1 2

Matlab Programming Introduction 1 2 Matlab Programming Introduction 1 2 Mili I. Shah August 10, 2009 1 Matlab, An Introduction with Applications, 2 nd ed. by Amos Gilat 2 Matlab Guide, 2 nd ed. by D. J. Higham and N. J. Higham Starting Matlab

More information

ENGR 1181 Midterm Exam 2: Study Guide and Practice Problems

ENGR 1181 Midterm Exam 2: Study Guide and Practice Problems ENGR 1181 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

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD

Introduction to Computer Programming with MATLAB Matlab Fundamentals. Selis Önel, PhD Introduction to Computer Programming with MATLAB Matlab Fundamentals Selis Önel, PhD Today you will learn to create and execute simple programs in MATLAB the difference between constants, variables and

More information

Basic MATLAB Tutorial

Basic MATLAB Tutorial Basic MATLAB Tutorial http://www1gantepedutr/~bingul/ep375 http://wwwmathworkscom/products/matlab This is a basic tutorial for the Matlab program which is a high-performance language for technical computing

More information

A QUICK INTRODUCTION TO MATLAB

A QUICK INTRODUCTION TO MATLAB A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Basic operations and a few illustrations This set is independent from rest of the class notes. Matlab will be covered in recitations and occasionally

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

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Dr./ Ahmed Nagib Mechanical Engineering department, Alexandria university, Egypt Sep 2015 Chapter 5 Functions Getting Help for Functions You can use the lookfor command to find functions

More information

1 Introduction to MATLAB

1 Introduction to MATLAB 1 Introduction to MATLAB 1.1 General Information Quick Overview This chapter is not intended to be a comprehensive manual of MATLAB R. Our sole aim is to provide sufficient information to give you a good

More information

Arithmetic operations

Arithmetic operations Arithmetic operations Add/Subtract: Adds/subtracts vectors (=> the two vectors have to be the same length). >> x=[1 2]; >> y=[1 3]; >> whos Name Size Bytes Class Attributes x 1x2 16 double y 1x2 16 double

More information

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started A QUICK INTRODUCTION TO MATLAB Very brief intro to matlab Intro to matlab getting started Basic operations and a few illustrations This set is indepent from rest of the class notes. Matlab will be covered

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

Chapter 2. Outline. Simple C++ Programs

Chapter 2. Outline. Simple C++ Programs Chapter 2 Simple C++ Programs Outline Objectives 1. Building C++ Solutions with IDEs: Dev-cpp, Xcode 2. C++ Program Structure 3. Constant and Variables 4. C++ Operators 5. Standard Input and Output 6.

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

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

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

Lecture 1: What is MATLAB?

Lecture 1: What is MATLAB? Lecture 1: What is MATLAB? Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1. MATLAB MATLAB (MATrix LABoratory) is a numerical

More information

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors. 1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN

More information

1 Introduction to MATLAB

1 Introduction to MATLAB 1 Introduction to MATLAB 1.1 Quick Overview This chapter is not intended to be a comprehensive manual of MATLAB R. Our sole aim is to provide sufficient information to give you a good start. If you are

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

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011 MATLAB: The Basics Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 9 November 2011 1 Starting Up MATLAB Windows users: Start up MATLAB by double clicking on the MATLAB icon. Unix/Linux users: Start up by typing

More information

Matrix Manipula;on with MatLab

Matrix Manipula;on with MatLab Laboratory of Image Processing Matrix Manipula;on with MatLab Pier Luigi Mazzeo pierluigi.mazzeo@cnr.it Goals Introduce the Notion of Variables & Data Types. Master Arrays manipulation Learn Arrays Mathematical

More information

Maths Functions User Manual

Maths Functions User Manual Professional Electronics for Automotive and Motorsport 6 Repton Close Basildon Essex SS13 1LE United Kingdom +44 (0) 1268 904124 info@liferacing.com www.liferacing.com Maths Functions User Manual Document

More information

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices Introduction to Interactive Calculations Matlab is interactive, no need to declare variables >> 2+3*4/2 >> V = 50 >> V + 2 >> V Ans = 52 >> a=5e-3; b=1; a+b Most elementary functions and constants are

More information

Programming in MATLAB

Programming in MATLAB trevor.spiteri@um.edu.mt http://staff.um.edu.mt/trevor.spiteri Department of Communications and Computer Engineering Faculty of Information and Communication Technology University of Malta 17 February,

More information

Chapter 4: Basic C Operators

Chapter 4: Basic C Operators Chapter 4: Basic C Operators In this chapter, you will learn about: Arithmetic operators Unary operators Binary operators Assignment operators Equalities and relational operators Logical operators Conditional

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

Introductory MATLAB. Appendix A A.1 BACKGROUND A.2 STARTING WITH MATLAB. Core Topics

Introductory MATLAB. Appendix A A.1 BACKGROUND A.2 STARTING WITH MATLAB. Core Topics Appendix A Introductory MATLAB Core Topics Starting with MATLAB (A.2). Arrays (A.3). Mathematical operations with arrays (A.4). Script files (A.5). User-defined functions and function files (A.7). Anonymous

More information

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University Lesson #3 Variables, Operators, and Expressions Variables We already know the three main types of variables in C: int, char, and double. There is also the float type which is similar to double with only

More information

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras

MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras MATLAB Programming for Numerical Computation Dr. Niket Kaisare Department Of Chemical Engineering Indian Institute of Technology, Madras Module No. #01 Lecture No. #1.1 Introduction to MATLAB programming

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

Matlab Workshop I. Niloufer Mackey and Lixin Shen

Matlab Workshop I. Niloufer Mackey and Lixin Shen Matlab Workshop I Niloufer Mackey and Lixin Shen Western Michigan University/ Syracuse University Email: nil.mackey@wmich.edu, lshen03@syr.edu@wmich.edu p.1/13 What is Matlab? Matlab is a commercial Matrix

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

Introduction to PartSim and Matlab

Introduction to PartSim and Matlab NDSU Introduction to PartSim and Matlab pg 1 PartSim: www.partsim.com Introduction to PartSim and Matlab PartSim is a free on-line circuit simulator that we use in Circuits and Electronics. It works fairly

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

ANSI C Programming Simple Programs

ANSI C Programming Simple Programs ANSI C Programming Simple Programs /* This program computes the distance between two points */ #include #include #include main() { /* Declare and initialize variables */ double

More information

Course Layout. Go to https://www.license.boun.edu.tr, follow instr. Accessible within campus (only for the first download)

Course Layout. Go to https://www.license.boun.edu.tr, follow instr. Accessible within campus (only for the first download) Course Layout Lectures 1: Variables, Scripts and Operations 2: Visualization and Programming 3: Solving Equations, Fitting 4: Images, Animations, Advanced Methods 5: Optional: Symbolic Math, Simulink Course

More information