Introduction To MATLAB Introduction to Programming GENG 200

Size: px
Start display at page:

Download "Introduction To MATLAB Introduction to Programming GENG 200"

Transcription

1 Introduction To MATLAB Introduction to Programming GENG 200, Prepared by Ali Abu Odeh 1

2 Table of Contents M Files Execution Control 3 Vectors User Defined Functions Expected Chapter Duration: 6 classes. 6 Matrices 2-D Plotting 2

3 1. Introduction MATLAB, which stands for MATrix LABoratory, is a state-of-the-art mathematical software package, which is used extensively in both academia and industry. It is high- level technical computing language and interactive environment for algorithm development, data visualization, data analysis, and numeric computation. 3

4 Graphical User Interface MATLAB uses several display windows (see Figure 1.1). The default view includes command window, current directory, workspace, and command history windows. Command Window: This window offers an environment similar to scientific calculator, which will help you in performing fast experiments of your commands and finds out the results of fragments of your code. 4

5 Command History: This window will save a record of your commands you issued in the command window. Current Directory: MATLAB accesses files and saves information to a location on your hard drive given by the current directory. Workspace Window: This window will show the variables you have defined, and it will keep track of them. When you open MATLAB every time this window will be empty because you aren t defining any variables yet. 5

6 Current Directory Command Window Workspace Window Command History Window Figure 1.1 6

7 Help Menu The MATLAB help menu is very powerful. It contains detailed description of every command used in MATLAB along with illustrative examples to show the user the explanation of the command and how it can be used. To access the help menu, from the help tab select Product Help. Then you can search for any command to get detailed information. See Figure 1.2 which shows the details of the sin function. 7

8 Type the phrase you want to search for Figure 1.2 8

9 Simple variables and data assignments MATLAB presents very easy environment for defining simple variables. Remember that any simple variable (scalar) is considered as a 1- by-1 matrix. Now, if you want to define a variable in MATLAB just go directly to the command window where you will see the prompt (>>) and type the variable name and assign a numerical value and press Enter button. 9

10 When your command is executed, the MATLAB will respond by showing you the result of calculation. Note 1.1: If you are doing calculation without assigning the output to a variable (see example 1.1), the output will be assigned to a variable called ans created by MATLAB itself. Note 1.2: MATLAB is case sensitive. That is: x + y is not the same as X + y 10

11 Creating Integer Data MATLAB stores numeric data as double precision floating point (double) by default. To store data as an integer, you need to convert from double to the desired integer type. Use one of the following functions: >> x=int8(25.4) >> x=int16(25.4) >> x=int32(25.4) >> x=int64(25.4) Note: 8 or 16 or 32 or 64 bits. 11

12 Example 1.1: Calculate: 5*2*(6^4+2). >> 5*2*(6^4+2) ans = Example 1.2: Calculate: x*y+3; where x = 3, y = 4. >> x = 3 x = 3 >> y = 4 y = 4 >> x*y+3 ans = 15 12

13 After doing the previous examples, look at the workspace window. You will see the variables and results there as shown in figure 1.3 Figure

14 Note 1.3: The following commands are useful clc: clears the command window clear: removes the variables from the workspace» To delete a particular variable in freemat, type: clear variable_name» clc command will clear the temporary variable ans. Note 1.4:the symbol (%) is used for documentation and the constant π is defined in MATLAB as pi. 14

15 Example 1.3: Calculate the volume of a cylinder if height = 10 cm, radius = 5 cm. v = height*π*radius 2 >> h = 10 % height h = 10 >> r = 5 % radius r = 5 >> v = h*pi*r^2 % volume v =

16 2. Scripts (M-Files) MATLAB uses text files for saving scripts (set of instructions) and executing them rather than just entering the commands in the command window. It uses its own editor to create those text files with the extension.m, and referred to as m-files. You can create m- file by choosing: 16

17 File>New>M-File (or by clicking on the new icon on the far left of the MATLAB s toolbar). Once you created your m-file, you need to save it so that you can run and refer to it in future. However, in order to run the m-file it should be in the current directory of the MATLAB.» Example 2.1: redo example 1.3 but this time using m-file. 17

18 Figure

19 To execute the volume.m file, press F5 or from debug menu select run or from toolbar of the m-file press on the green play button (or you can write the name of the m-file on the command line and press Enter key, so in this example: >>volume). Note 2.1: Terminate any line with semicolon (;) to suppress the output 19

20 Example 2.2: Write m-file to calculate the roots of the quadratic equation. f(x) = ax 2 +bx+c where: a, b, and c are constants and a 0. Roots will be: What will be the answer if a = 2, b = 4, and c = 1? 20

21 clc clear a=2; b=4; c=1; x1=(-b-sqrt(b^2-4*a*c))/(2*a); x2=(-b+sqrt(b^2-4*a*c))/(2*a); Output: x1 = x2 =

22 3. Vectors Creating Vectors A vector is one-dimensional matrix (array) as shown in Figure 3.1 which contains data items such as: numbers. Individual items in a vector are usually referred to as elements. Vector elements have two properties: their numerical values and position (index) making them unique in a specific vector. 22

23 Element Index n-1 n There are many different ways to create a vector. The following shows how to create a vector: 23

24 3.1 Entering the values directly vector_name = [type vectors elements here] For example: a = [2, 4, 6, 8]. The commas are optional and can be omitted, that is you can write: a = [ ]. 24

25 Example 3.1: Entering values directly >> x = [ ] x = >> a = [4, 10, 12, 20] a =

26 3.2 Creating a vector with constant spacing by using colon operator: vector_name = [first element: spacing : Last element] For example: x = [1:2:10]. Note that the brackets are optional and the spacing can be omitted if the increment you need is 1. 26

27 Example 3.2: Using the colon operator >> m = [0:2:10] % vector of 1-by-6 m = >> w = 1:2:10 % vector of 1-by-5 w =

28 3.3 Using the linspace function to create a fixed number of values between two limits. vector_name = linspace(xi, xf, n). Where xi: initial limit, xf: final limit and n: number of elements in the vector. For example: x = linspace(0,10,6)» The space will be computed according to (xf-xi)/(n-1) 28

29 Example 3.3: Using linspace( ) function >> x = linspace(0,10,6) x = >> y = linspace(0,10,3) y = >> z = linspace(0,10,4) z =

30 Interesting Function! Check it out: --> x=linspace(2,8,3) x = > x=linspace(8,2,3) x = > x=linspace(-5,-1,3) x = > x=linspace(-1,-5,3) x =

31 3.4 Using built-in function: such as: ones(1,n),zeros(1,n), and rand(1,n). We will discuss them in the following examples. 31

32 Example 3.4: Creating vectors using zeros, ones and rand functions >> a=rand(1,4) a = >> b=ones(1,4) b = >> c=zeros(1,4) c =

33 >> d=6;e=3;h=4; %Three variables are defined >> x = [e d*h cos(pi/3) h^2 sqrt(h^2/d)] x =

34 Generating Random Numbers Sometimes there is a need to generate random numbers that are distributed in an interval other than (0, 1),or to have numbers that are only integers. Random numbers that distributed in a range (a, b) can be obtained by the following equation vector_name = (b-a)*rand(1,n)+a 34

35 Example 3.5: Generate a 1-by-5 vector random numbers between 0 and 10 >> a=0;b=10; >> x = (b-a)*rand(1,5)+a x = Example 3.6: Generate a 1-by-10 vector of integer random numbers from 1 to 100 >> a=1;b=100; >> x = round((b-a)*rand(1,10)+a) x =

36 Indexing and Accessing a Vector The elements of a vector can be accessed by enclosing the index of the required elements in parenthesis. If you attempt to read beyond the length of the vector or below index 1, an error will result. Example 3.7: >> A = [ ] A =

37 >> A(3) ans = 2 >> A(1) ans = 3 >> A(0)??? Attempted to access A(0); index must be a positive integer or logical. 37

38 >> A(7)??? Attempted to access A(7); index out of bounds because numel(a) = 6. Note that you can change the value of any element in a vector.» You can add to the vector but you can t assign to more than the index. A(7) = new_value (correct) A(7) (wrong) 38

39 Operations on Vectors Arithmetic Operations Since all variables in MATLAB are considered as arrays (scalar:1 1, vector: 1 n, array: n m), one should take care of how to perform: multiplication, division and exponentiation. On the other hand addition and subtraction have the syntax exactly as one would expect. 39

40 The first set of operations with vectors is element-by-element operations, not array operations, and hence, linear algebra rules do not apply in this case. Therefore, new set of symbols is required. For multiplication we will use (.*), for division we will use (./) and for exponentiation we will use (.^). Note 5:Using the dot to represent that the operation is element-by-element operation. 40

41 Note 3.1: vector by vector operation requires that both vectors should be of the same length. That is, they have the same number of elements. Example 3.8: >> A = [ ] A =

42 >> B = [ ] B = >> A + 5 ans = >> A*2 ans =

43 >> A*B??? Error using ==> mtimes Inner matrix dimensions must agree. >> A.*B ans = >> A^2??? Error using ==> mpower Matrix must be square. 43

44 Logical Operations We can perform logical operations using relational operators (we will discuss logical operators in the coming sections) listed in table 3.1. Those operations can produce numerical or logical results. Operator Description < Less than <= Less than or equal to > Greater than >= Greater than or equal to Table 3.1 == Equal to ~= Not equal to 44

45 Example 3.9: >> A = [ ] A = >> B = [ ] B = >> A >= 5 ans =

46 >> A(A >= 5) ans = Return elements that are greater than or equal to 5. >> A>=B ans = Return where each element of A that is not less than the corresponding elements of B 46

47 Note 3.2: An alternative to using indexing into the vector using the logical expression is to use the find function. For example: find(a>=5) will return where index A is greater than or equal to 5. Use mod(x,y) or rem(x,y) to find the modulus, e.g. mod(5,4) equal 1. 47

48 Example 3.10: >> A = [ ] A = >> sum(a) ans = 26 >> mean(a) ans =

49 To find also the mean, you can use these library functions: >> sum(a) / length(a) >> sum(a) / numel(a) 49

50 >> [w i] = max(a) w = 10 i = 7 >> [d z] = min(a) d = -1 z = 1 Note 3.3: w, i, d, and z can be replaced by any variable. 50

51 4. MATLAB Arrays (Matrices) In the previous section we saw that vector is a simple way to group a collection of similar data items. Let us now extend the idea to include arrays confined to two dimensional arrays. Typical two dimensional array A with m rows and n columns and A a transpose array of A with n rows and m columns. 51

52 >> A = [9 9 6; 7 1 2] A = >> A ans =

53 Creating an Array As with vectors, you can create arrays in MATLAB using many different ways. The following summaries most common techniques: - You can enter the values directly using semicolon to indicate the end of a row. For example: A = [2 4 6; 1 3 5], A is 2 x 3 array. - The functions zeros(m, n) and ones(m, n) create creates arrays with m rows and n columns filled with zeros and ones respectively. 53

54 - The function rand(m, n) create an array filled with random numbers in the range from 0 to 1. -The function diag(a) where A an array, returns its diagonal as a column vector. -The function magic(m), which creates a square array of size m x m filled with numbers from 1 to m 2 organized in such a way that its rows, columns, and diagonals all add up to the same value. Note: magic doesn't work with FreeMat. 54

55 Example 4.1: >> A = [2 4 6; ] A = >> A = [2 4; 6 8] A =

56 >> B=zeros(3,3) B = >> C = [ones(2,2) zeros(2,2)] C =

57 >> rand(3,4) ans = Example 4.2: >> A = [2 3 4; 7 8 9] A =

58 >> diag(a) ans = 2 8 To access a specific element in an 2D array, just indicate the row and column of the specified element, i.e., A(row,col). Also the colon operator can be used to access array elements. 58

59 The following notations illustrate some of the different cases: A(:,n) Refers to all elements in all rows of a column n of the array A. A(n,:) Refers to all elements in all columns of a row n of the array A. A(:,m:n) Refers to all elements in all rows between columns m and n of the array A. 59

60 Operations on Arrays Addition and Subtraction: Standard addition or subtraction can be done on arrays of identical size (the same number of rows and columns). Also can be done when we want to add (subtract) a scalar value to an array. When two arrays are involved, the sum or difference is performed by adding or subtracting their corresponding elements. 60

61 But when a scalar (number) is involved, that number is added (or subtracted from) all the elements of the array. Example 4.3: >> A = [2 4 1; 3 9 5] A =

62 >> B = [1 2 3; 4 5 6] B = >> A - B ans = >> A + B ans = 62

63 >> A + 1 ans = >> B -1 ans =

64 Multiplication The multiplication * of arrays is executed by MATLAB according to the rules of linear algebra (This is known as matrix multiplication). This means that if A*B is to be executed. Then the number of columns in matrix A should equal to the number of rows in matrix B. The result is a matrix that has the same number of rows as A and the same number of columns as B. 64

65 For example: if A4x3*B3x2 will result in a new matrix C4x2. This means that A*B B*A. C4x2 = A4x3*B3x2 65

66 Example 4.4: >> A=[1 2 3; 4 5 6;7 8 9] %3x3 A = >> B=[2 3 ;-4 7;5 5] %3x2 B =

67 >> A*B ans = >> B*A??? Error using ==> mtimes Inner matrix dimensions must agree. 67

68 Identity Matrix and Inverse of Matrix Identity Matrix is a square matrix in which the diagonal elements are 1 s and the rest of the elements are 0 s. When the identity matrix multiplies another matrix (multiplication should be done according to linear algebra), that matrix is unchanged. That is: A*I = I*A=A. The identity matrix can be generated in MATLAB using eye(n) which will create n x n identity matrix. 68

69 Inverse of a matrix is best explained using the following illustration. The matrix B is the inverse of matrix A if when the two matrices are multiplied product is the identity matrix. Both matrices must be square and the order can be A*B or B*A. The inverse of matrix A can be written as A -1. In MATLAB you can find the inverse using the two commands: inv(a) or raise to the power of -1, that is: A^-1. The following example illustrates both identity and inverse matrices. 69

70 For a 2 x 2 matrix A = a c b d The matrix inverse is A 1 = 1 A d c b a 1 ad bc d c b a 70

71 Example 4.5: >> A=[2 1 4;4 1 8;2-1 3] %Create the Matrix A A = >> B=inv(A) %use inv() to find the inverse of A B =

72 >> A*B %multiplication of A and B gives I ans = >> A^-1 % use power of -1 to find the inverse of A ans = >> B- A^-1 %what the answer for this command? 72

73 Right Division & Left Division Solve the following linear equations: x + 2y = 4 2x y =3 By solving x and y, you will find that x=2 and y=1. 73

74 Left Division >> a=[1 2;2-1] a = >> b=[4;3] b = 4 3 >> x=a\b x =

75 Right Division >> a=[1 2;2-1] a = >> b=[4 3] b = 4 3 >> x=b/a x =

76 Element-By-Element Operations These operations are carried out on each element of the array. Note that these operations are performed on arrays of the same size. Example 4.6: >> A=[1 2 3;4 5 6] % Define 2x3 array A A =

77 >> B=[5 7 4;6 2 9] % Define 2x3 array B B = >> A*B??? Error using ==> mtimes Inner matrix dimensions must agree. >> A.*B ans =

78 >> A./B ans = >> A.^2 ans =

79 Applying Library Functions Example 4.7: >> A=[1 5 70;pi 2*pi 3*pi] % Define 2x3 array A = >> sin(a) % Apply the sin function ans =

80 >> sqrt(a) % Apply the sqrt function ans = MATLAB has a large built-in Library functions. For example: sum(a): treats the columns of A as vectors, returning a row vector of the sums of each column. 80

81 std(a): returns a row vector containing the standard deviation of the elements of each column of A. det(a):return the determinant of a square array Example 4.8: >> A=[2 4 6;3 5 7;1 2 3] A =

82 >> sum(a) % Apply the sum function ans = >> std(a) % Apply the standard deviation ans = >> sort(a) % Sorting array in an ascending order ans =

83 >> max(a) % finding the maximum value for every column ans = >> mean(a) ans = >> max(mean(a)) ans =

84 5. Execution Control Relational and Logical Operators & AND Operates on two operands (A&B). If both results are true, the result is true. Otherwise the result is false. OR Operates on two operands (A B). If either one or both are true, the result is true, Otherwise, the result is false. 84

85 ~ NOT Operates on one operand (~A). The result is true if the operand is false and false if the operand is true 85

86 if statements if evaluates a logical expression and executes a block of statements based on whether the logical expressions evaluates to true (logical 1) or false (logical 0). The general structure is as follows. 86

87 if logical_expression 1 statements elseif logical_expression 2 statements.. elseif logical_expression n statements else default statements end» Note: elseif is one word without space. 87

88 The function disp(... ) is used to display a text. Actually, this function can also be used to display an array without printing its name, for example: disp(a), where A is an array. The function input( ) will ask the user to enter a number, i.e. n=input( Enter an Integer: ), then this message will appear on the command line waiting for the user to enter a number and then assigns the value to n. 88

89 » Important Note: If you use input command in your m file then, run the program by typing its name in the command window and not by pressing the run button.» Important Note : There will be no difference whether we surround the condition with parentheses or not in if statements. if (round(n/2) == n/2) if round(n/2) == n/2 89

90 Example 5.1: Write an m file to find if the number is Even or Odd. clear;clc; n = input('enter an integer number: '); if round(n/2) == n/2 disp('even') % disp('...') used to display text else disp('odd') end 90

91 while Loop while logical_expression statements end Example 5.2: Write m file to Generate sequence of even numbers clc;clear; x=2 while x>=2 & x<=10 x=x+2 end 91

92 for Loop for i = initial_value : step_size : final_value statements end Example 5.3: Write an m file to Generate sequence of numbers. clc;clear; for i=1:3:10 x=i^2 end 92

93 function fprintf( ) is similar to the function printf that used in c language and it will do the same job. The general format of this function is: fprintf(format, variable) Example 5.4: clc;clear; for i=1:3:10 x=i^2; fprintf('x = %d\n',x) % Try to use disp(x) end % or use disp('x=',x) 93

94 Example 5.5: a vector is given by A = [-5,-17,- 3,8,0,-1,12,-4,-6,6,-7,17]. Write an m-file that doubles the negative odd elements. clc;clear A = [-5,-17,-3,8,0,-1,12,-4,-6,6,-7,17]; disp('a Before = ') disp(a) for i=1:length(a) if (A(i)<0) & (A(i)/2 ~= round(a(i)/2)) A(i) = A(i)*2; end end disp('a After = ') disp(a) 94

95 6. User Defined Functions User defined functions must be stored in a separate m-file and in your directory of work. And the m-file that contains your function should be saved with same name as the function. The general definition of a function is as follows: function [output_vars] = function_name (input_vars) function code body 95

96 Note that if you have one output variable, then omit the brackets [ ]. Those only used if you have more than output variable. Example 6.1: Write a MATLAB function file for y= x 2 +2x+3. Then calculate f(0) and f(3). Solution: create a new m-file, save it as f.m and then write your code. Figure below shows the required function. 96

97 The name of the function and the name of the file must be the same. 97

98 You can call the function in the command line using its name as follows: >> f(0) ans = 3 >> f(6) ans = 51 Example 6.2: Write MATLAB function to calculate the area and circumference of a circle for given radius r. 98

99 function [area,cercom]=circle(radius) % Function to compute area and % circumference of a circle area = pi*radius^2; cercom = 2*pi*radius; >> [a,c]=circle(4) a = c =

100 >> circle(4) ans = >> [area,cercomference]=circle(4) area = cercomference =

101 7. 2-D Plots plot(xvalues, yvalues, style-option ) Where xvalues and yvalues are vectors of the same length containing x and y coordinates of points on the graph. style-option is an optional arguments that specifies the color, the line style (e.g., solid, dashed, dotted,etc.) and the point-marker style (e.g., o, +, *, etc.). 101

102 Style Option The style-option in the plot command is a character string that consists of one, two or three characters that specify the color and/or line style as shown below. Color style-option Line style-option Marker style-option y yellow - solid + plus sign m magenta -- dashed o circle c cyan : dotted * asterisk r red -. dash-dot x x-mark g green. point b blue ^ up triangle w white s square k black d diamond 102

103 Examples plot(x,y) plots y vs. x with a blue solid line (default). plot(x,y,'r') plots y vs. x with a red solid line. plot(x,y,':') plots y vs. x with a dotted line. plot(x,y,'b--') plot y vs. x with a blue dashed line. plot(x,y,'+') plot y vs. x as unconnected points. marked by

104 Example 7.1: Plot the function y = x cos(6x), where -2 x 4 using different line styles, the step size is 0.01 clc;clear x=-2:0.01:4; y=3.5.^(-0.5*x).*cos(6*x); figure(1) plot(x,y) figure(2) plot(x,y,'r') 104

105 figure(3) plot(x,y,':') figure(4) plot(x,y,'b--') figure(5) plot(x,y,'+') 105

106 106

107 107

108 Example 7.2: clc;clear x= -pi:1/pi:pi; y= cos(x); z= sin(x); plot(x,y,'g--',x,z,'r-.') % Add grid lines grid on 108

109 Formatting a Plot A figure that contains a plot needs to be formatted to have a specific look and to display information in addition to the graph itself. Consider the following commands: xlabel( x-axis label ) ylabel( y-axis label ) title( title of the figure ) axis([xmin xmax ymin ymax]) 109

110 Example 7.3: clc;clear t = 0:0.001:1; f = 15; y = cos(2*pi*f*t); plot(t,y,'--') xlabel('time (sec)') ylabel('cos(2\pift)') title('t vs. cos(2\pift)') grid on 110

111 Subplots The command subplot( ) can be used to set and design the required layout. subplot(rows,columns,index) This function divides the graphics window into rows x columns sub-windows and puts a certain plot in a position specified by the index. For example the two commands subplot(2,2,3), plot(x,y) divides the graphics window into 4 sub-windows and places the plot of y vs. x in the third sub-window. 111

112 clc;clear t = -0.5:0.001:0.5; f = 15; x = cos(2*pi*f*t); y = sin(2*pi*f*t); z = sinc(2*pi*f*t); w = 0.5*t-0.5; subplot(2,2,1) plot(t,x) grid on title('cosine vs. time') 112

113 subplot(2,2,2) plot(t,y) grid on title('sine vs. time') subplot(2,2,3) plot(t,z) grid on title('sinc vs. time') subplot(2,2,4) plot(t,w) grid on title('w vs. time') 113

114 114

115 References: Slides, ERU team of instructors. 115

Introduction to MATLAB

Introduction to MATLAB GENG 200 Introduction to Programming Faculty of Engineering, ERU Table of Contents 1. Getting Started with MATLAB... 3 1.1 Introduction... 3 1.2 Graphical User Interface... 3 1.3 Help Menu... 4 1.4 Basic

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

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

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

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

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

Lecture 2: Variables, Vectors and Matrices in MATLAB

Lecture 2: Variables, Vectors and Matrices in MATLAB Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables

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

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

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

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

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix. MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

More information

Introduction to Matlab

Introduction to Matlab What is Matlab? Introduction to Matlab Matlab is software written by a company called The Mathworks (mathworks.com), and was first created in 1984 to be a nice front end to the numerical routines created

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

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

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

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

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

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

MATLAB SUMMARY FOR MATH2070/2970

MATLAB SUMMARY FOR MATH2070/2970 MATLAB SUMMARY FOR MATH2070/2970 DUNCAN SUTHERLAND 1. Introduction The following is inted as a guide containing all relevant Matlab commands and concepts for MATH2070 and 2970. All code fragments should

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

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

Introduction to MATLAB LAB 1

Introduction to MATLAB LAB 1 Introduction to MATLAB LAB 1 1 Basics of MATLAB MATrix LABoratory A super-powerful graphing calculator Matrix based numeric computation Embedded Functions Also a programming language User defined functions

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

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

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

Matlab Tutorial and Exercises for COMP61021

Matlab Tutorial and Exercises for COMP61021 Matlab Tutorial and Exercises for COMP61021 1 Introduction This is a brief Matlab tutorial for students who have not used Matlab in their programming. Matlab programming is essential in COMP61021 as a

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

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

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

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

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

Matlab Tutorial for COMP24111 (includes exercise 1)

Matlab Tutorial for COMP24111 (includes exercise 1) Matlab Tutorial for COMP24111 (includes exercise 1) 1 Exercises to be completed by end of lab There are a total of 11 exercises through this tutorial. By the end of the lab, you should have completed the

More information

Introduction to MATLAB 7 for Engineers

Introduction to MATLAB 7 for Engineers PowerPoint to accompany Introduction to MATLAB 7 for Engineers William J. Palm III Chapter 2 Numeric, Cell, and Structure Arrays Copyright 2005. The McGraw-Hill Companies, Inc. Permission required for

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

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

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

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis Introduction to Matlab 1 Outline What is Matlab? Matlab desktop & interface Scalar variables Vectors and matrices Exercise 1 Booleans Control structures File organization User defined functions Exercise

More information

LabVIEW MathScript Quick Reference

LabVIEW MathScript Quick Reference Telemark University College Department of Electrical Engineering, Information Technology and Cybernetics LabVIEW MathScript Quick Reference Hans-Petter Halvorsen, 2012.06.14 Faculty of Technology, Postboks

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

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

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

PowerPoints organized by Dr. Michael R. Gustafson II, Duke University Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

More information

selected topic in transportation 2552/2. 1 Prepared by Lect.Weerakaset Suanpaga

selected topic in transportation 2552/2. 1 Prepared by Lect.Weerakaset Suanpaga 203484 selected topic in transportation 2552/2 Introduction ti to MATLAB 1 Prepared by Lect.Weerakaset Suanpaga Outline Introduction and where to get MATLAB Data structure: matrices, vectors and operations

More information

Introduction to MATLAB

Introduction to MATLAB CHEE MATLAB Tutorial Introduction to MATLAB Introduction In this tutorial, you will learn how to enter matrices and perform some matrix operations using MATLAB. MATLAB is an interactive program for numerical

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

Introduction to Matlab

Introduction to Matlab Introduction to Matlab November 22, 2013 Contents 1 Introduction to Matlab 1 1.1 What is Matlab.................................. 1 1.2 Matlab versus Maple............................... 2 1.3 Getting

More information

MATLAB Basics. Mohamed Taha. Communication Engineering Department Princess Sumaya University Page 1 of 32. Full Screen.

MATLAB Basics. Mohamed Taha. Communication Engineering Department Princess Sumaya University Page 1 of 32. Full Screen. Mohamed Taha Communication Engineering Department Princess Sumaya University mtaha@psut.edu.jo Page 1 of 32 1 What is It is an abbreviation to MATrix LABoratory Front end for a matrix library It is an

More information

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example:

Eric W. Hansen. The basic data type is a matrix This is the basic paradigm for computation with MATLAB, and the key to its power. Here s an example: Using MATLAB for Stochastic Simulation. Eric W. Hansen. Matlab Basics Introduction MATLAB (MATrix LABoratory) is a software package designed for efficient, reliable numerical computing. Using MATLAB greatly

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 Vocabulary. Gerald Recktenwald. Version 0.965, 25 February 2017

MATLAB Vocabulary. Gerald Recktenwald. Version 0.965, 25 February 2017 MATLAB Vocabulary Gerald Recktenwald Version 0.965, 25 February 2017 MATLAB is a software application for scientific computing developed by the Mathworks. MATLAB runs on Windows, Macintosh and Unix operating

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

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

AMS 27L LAB #2 Winter 2009

AMS 27L LAB #2 Winter 2009 AMS 27L LAB #2 Winter 2009 Plots and Matrix Algebra in MATLAB Objectives: 1. To practice basic display methods 2. To learn how to program loops 3. To learn how to write m-files 1 Vectors Matlab handles

More information

MATLAB and Numerical Analysis

MATLAB and Numerical Analysis School of Mechanical Engineering Pusan National University dongwoonkim@pusan.ac.kr Teaching Assistant 김동운 dongwoonkim@pusan.ac.kr 윤종희 jongheeyun@pusan.ac.kr Lab office: 통합기계관 120호 ( 510-3921) 방사선영상연구실홈페이지

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab What is Matlab The software program called Matlab (short for MATrix LABoratory) is arguably the world standard for engineering- mainly because of its ability to do very quick prototyping.

More information

What is Matlab? A software environment for interactive numerical computations

What is Matlab? A software environment for interactive numerical computations What is Matlab? A software environment for interactive numerical computations Examples: Matrix computations and linear algebra Solving nonlinear equations Numerical solution of differential equations Mathematical

More information

Chapter 2. MATLAB Fundamentals

Chapter 2. MATLAB Fundamentals Chapter 2. MATLAB Fundamentals Choi Hae Jin Chapter Objectives q Learning how real and complex numbers are assigned to variables. q Learning how vectors and matrices are assigned values using simple assignment,

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

AN INTRODUCTION TO MATLAB

AN INTRODUCTION TO MATLAB AN INTRODUCTION TO MATLAB 1 Introduction MATLAB is a powerful mathematical tool used for a number of engineering applications such as communication engineering, digital signal processing, control engineering,

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Math 339 Fall 2013 First, put the icon in the launcher: Drag and drop Now, open Matlab: * Current Folder * Command Window * Workspace * Command History Operations in Matlab Description:

More information

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

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

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014 PS 12a Laboratory 1 Spring 2014 Objectives This session is a tutorial designed to a very quick overview of some of the numerical skills that you ll need to get started. Throughout the tutorial, the instructors

More information

EE 301 Signals & Systems I MATLAB Tutorial with Questions

EE 301 Signals & Systems I MATLAB Tutorial with Questions EE 301 Signals & Systems I MATLAB Tutorial with Questions Under the content of the course EE-301, this semester, some MATLAB questions will be assigned in addition to the usual theoretical questions. This

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

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

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University MATLAB Fundamentals Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University Reference: 1. Applied Numerical Methods with MATLAB for Engineers, Chapter 2 &

More information

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

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

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

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

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

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab

DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab Islamic University of Gaza Faculty of Engineering Electrical Engineering Department 2012 DSP Laboratory (EELE 4110) Lab#1 Introduction to Matlab Goals for this Lab Assignment: In this lab we would have

More information

Matlab Introduction. Scalar Variables and Arithmetic Operators

Matlab Introduction. Scalar Variables and Arithmetic Operators Matlab Introduction Matlab is both a powerful computational environment and a programming language that easily handles matrix and complex arithmetic. It is a large software package that has many advanced

More information

Getting Started with Matlab

Getting Started with Matlab Chapter Getting Started with Matlab The computational examples and exercises in this book have been computed using Matlab, which is an interactive system designed specifically for scientific computation

More information

Introduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018)

Introduction to MATLAB Programming. Chapter 3. Linguaggio Programmazione Matlab-Simulink (2017/2018) Introduction to MATLAB Programming Chapter 3 Linguaggio Programmazione Matlab-Simulink (2017/2018) Algorithms An algorithm is the sequence of steps needed to solve a problem Top-down design approach to

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

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals ELEN E384: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals 1 Introduction In the last lab you learn the basics of MATLAB, and had a brief introduction on how vectors

More information

Table of Contents. Basis CEMTool 7 Tutorial

Table of Contents. Basis CEMTool 7 Tutorial PREFACE CEMTool (Computer-aided Engineering & Mathematics Tool) is a useful computational tool in science and engineering. No matter what you background be it physics, chemistry, math, or engineering it

More information

MATLAB Tutorial III Variables, Files, Advanced Plotting

MATLAB Tutorial III Variables, Files, Advanced Plotting MATLAB Tutorial III Variables, Files, Advanced Plotting A. Dealing with Variables (Arrays and Matrices) Here's a short tutorial on working with variables, taken from the book, Getting Started in Matlab.

More information

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College

Introduction to Matlab to Accompany Linear Algebra. Douglas Hundley Department of Mathematics and Statistics Whitman College Introduction to Matlab to Accompany Linear Algebra Douglas Hundley Department of Mathematics and Statistics Whitman College August 27, 2018 2 Contents 1 Getting Started 5 1.1 Before We Begin........................................

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

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

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

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group Introduction to MATLAB Simon O Keefe Non-Standard Computation Group sok@cs.york.ac.uk Content n An introduction to MATLAB n The MATLAB interfaces n Variables, vectors and matrices n Using operators n Using

More information

McTutorial: A MATLAB Tutorial

McTutorial: A MATLAB Tutorial McGill University School of Computer Science Sable Research Group McTutorial: A MATLAB Tutorial Lei Lopez Last updated: August 2014 w w w. s a b l e. m c g i l l. c a Contents 1 MATLAB BASICS 3 1.1 MATLAB

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

Getting started with MATLAB

Getting started with MATLAB Sapienza University of Rome Department of economics and law Advanced Monetary Theory and Policy EPOS 2013/14 Getting started with MATLAB Giovanni Di Bartolomeo giovanni.dibartolomeo@uniroma1.it Outline

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab 1 Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control Using of M-File Writing User

More information

CS129: Introduction to Matlab (Code)

CS129: Introduction to Matlab (Code) CS129: Introduction to Matlab (Code) intro.m Introduction to Matlab (adapted from http://www.stanford.edu/class/cs223b/matlabintro.html) Stefan Roth , 09/08/2003 Stolen

More information

Lab #1 Revision to MATLAB

Lab #1 Revision to MATLAB Lab #1 Revision to MATLAB Objectives In this lab we would have a revision to MATLAB, especially the basic commands you have dealt with in analog control. 1. What Is MATLAB? MATLAB is a high-performance

More information

Summer 2009 REU: Introduction to Matlab

Summer 2009 REU: Introduction to Matlab Summer 2009 REU: Introduction to Matlab Moysey Brio & Paul Dostert June 29, 2009 1 / 19 Using Matlab for the First Time Click on Matlab icon (Windows) or type >> matlab & in the terminal in Linux. Many

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

MATLAB Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB built-in functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos,

More information

A Quick Tutorial on MATLAB. Zeeshan Ali

A Quick Tutorial on MATLAB. Zeeshan Ali A Quick Tutorial on MATLAB Zeeshan Ali MATLAB MATLAB is a software package for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It's name

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

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in

This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in This module aims to introduce Precalculus high school students to the basic capabilities of Matlab by using functions. Matlab will be used in subsequent modules to help to teach research related concepts

More information

MATLAB Project: Getting Started with MATLAB

MATLAB Project: Getting Started with MATLAB Name Purpose: To learn to create matrices and use various MATLAB commands for reference later MATLAB functions used: [ ] : ; + - * ^, size, help, format, eye, zeros, ones, diag, rand, round, cos, sin,

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