Chapters covered for the final

Size: px
Start display at page:

Download "Chapters covered for the final"

Transcription

1 Chapters covered for the final Chapter 1 (About MATLAB) Chapter 2 (MATLAB environment) Chapter 3 (Built in Functions):3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.8, 3.9 Chapter 4 (Manipulating Arrays):4.1,4.2, 4.3 (zeros, ones, diag, magic) Chapter 5 (Plotting): 5.1 (except plots of complex arrays), 5.2, 5.3(Bar graphs and histograms) Chapter 6 (User defined functions): 6.1, 6.2 Chapter 7 (User controlled I/O): 7.1, 7.2, fopen, fgetl, fprintf, fclose Chapter 8 (Logical Functions and control structures): 8.1, 8.2, 8.3, 8.4, 8.5, Chapter 9 (Matrix Algebra): 9.1 (excluding 9.1.5), 9.3 Chapter 10 (Other kind of arrays): 10.1 (excluding ), 10.2, 10.3, 10.4, 10.5

2 MATLAB as a Calculator >> 2+3/4*5 ans= Order of operations First perform calculations inside parenthesis Next, perform exponentiation operation Then perform multiplication and division operations from left to right Finally perform addition and subtraction operations from left to right

3 Numbers and Formats (Chapters 3 and 10.1) MATLAB recognizes several different kinds of numbers. The following two kinds are the most important. Integer format short 4 decimal digits uses 4 bytes (single) format long 14 decimal digits uses 8 bytes (double) Floating point format short e 4 decimal digits uses 4 bytes (single) e+000 format long e 14 decimal digits uses 8 bytes (double) e+000 All computations in MATLAB are done in double precision. The precision can be controlled by the format command. The precision can be changed by using format. >> format short changes the precision of integers to short, and therefore uses 4bytes.

4 variables Variables (Chapters 3 and 10) >> x=1.34; % Legal names consisting of letters and digits starting with a % letter. Note: net cost is not legal. Cannot use built in % function names. Note: You need to decide for every assignment statement (statement with left side = right side) whether the automatic output should be suppressed. If you decide to suppress the automatic output, end the assignment statement with ; Vectors v= [1 3 5]; %row vector: one row and 3 columns v= [1;2;3]; %column vector: 3 rows and one column v % transpose of vector v

5 Variables The Colon notation x=1:4; % will create a row vector x=[ ] x= 1.5:2.5 ; % x=[ 2.5, 1.5,.5, 1.5, 2.5] increment is one unless % specified. x= 1.5:0.5:1.0; % x=[ 1.5, 1.0, 0.5, 0.0, 0.5, 1.0] x=4: 1:1; % x=[4, 3, 2, 1] Matrices (Arrays) (Chapter 4.1) Constructing a simple matrix >> A=[ ; ; 4,11, 17]; % 3 by 3 matrices Specialized matrices: zeros, ones, diag, magic Creating a random matrix >> A=rand(3,5); % Creates a random matrix of size 3 by 5.

6 Variables (Chapters 4.2 and 9.1) Arithmetic Operators + * / \ ^ ' Matrix and array arithmetic Syntax A+B; A B; % Element by element addition A*B; A/B ; % A/B=A*inv(B); Matrix multiplication A.*B; A./B % element by element product or division A^B % A*A*A* *A: A is multiplied B times A.^B % (i,j) element of the product=a(i,j)^b(i,j) A % transpose of the matrix A.

7 For the given two given vectors, the results of various matrix and array operations on them.

8

9 Variables Concatenating matrices >> A=ones(2,5); B=rand(3,5); >> C=[A; B] % vertically concatenates A and B; C is a 5 by 5 matrix. % A and B must have the same number of columns >> E=zeros(3,2); F=diag(3); G=[A B] % Horizontally concatenates E and F; % E and F must have the same # of rows.

10 Extracting a sub-matrix

11 Colon Operator

12 One can delete rows and columns from a matrix using just a pair of square brackets. Start with >> A=[ ; ; ; ]; >>X = A; >>X(:,2) = [] % second column of X is deleted. X = Deleting rows and columns

13 MATLAB Special Variables

14 Logical Variables The logical data types represents a logical true or false using a number 1 or 0, respectively. MATLAB functions (such as feof) return logical true of false to indicate whether a certain condition is true or not. Logical functions doesn t have to be only scalar. >> x = magic(4) >= 9 x =

15 Using logicals in array indexing Consider the following example: >> A = [1 2 3; 4 5 6; 7 8 9] A = >> B = logical([0 1 0; 1 0 1; 0 0 1]); % logical is a built in function to convert % a 0 1 array into a logical array. B = >> A(B) ans =

16 Using logicals in array indexing Consider the following example: >> A = [1 2 3; 4 5 6; 7 8 9] A = >> B = logical([0 1 0; 1 0 1; 0 0 1]); A 3x3 72 double % logical is a built in function to convert % a 0 1 array into a logical array. B = >> A(B) ans = >> whos A Name Size Bytes Class >> whos B Name Size Bytes Class B 3x3 9 logical

17 Using logicals in array indexing Consider the following example: >> A = [1 2 3; 4 5 6; 7 8 9] A = >> B = logical([0 1 0; 1 0 1; 0 0 1]); B = >> A(B) ans = >> A(B)=0; >> A A=

18 Character and String variables (section 10.3) Creating a character string >> str = 'Hello ; >> whos str Name Size Bytes Class str 1x5 10 char Creating an array strings >> name = ['Harold A. Jorgensen ';... %The column vector name has 'Assistant Project Manager';... % 3 elements; elements are 'SFTware Corp. ']; % separated by columns; blanks % padded make the length the same. name, defined above, is a two dimensional array. >> name(2,4:7) ans= ista

19 Character and String variables Creating a character string >> str = 'Hello ; >> whos str Name Size Bytes Class str 1x5 10 char Creating an array strings >> whos name Name Size Bytes Class name 3x char >> name = ['Harold A. Jorgensen ';... %The column vector name has 'Assistant Project Manager';... % 3 elements; elements are 'SFTware Corp. ']; % separated by columns; blanks % padded make the length the same. name, defined above, is a two dimensional array. >> name(2,4:7) ans= ista

20 Problem Suppose we have the following vectors each of length n LastName : an n by 10 array of characters FirstName : an n by 10 array of characters Age : an n by 1 column vector (2digits) Grade : an n by 2 array of numbers (7digits number) Prepare for each individual a line of characters containing LastName, FirstName, Age and Grade >> for i= 1:n >> s(1:55)= ; >> s(1:10)=lastname(i); >> s(16:25)=firstname(i); >> s(31:32)=num2str(age(i)); >> s(36:42) = num2str(grade(i,1)); >> s(46:52) = num2str(grade(i,2)); >> line(i,:) = s; >> end

21 Creating Character Arrays by Concatenation You can join two or more character arrays together to create a new character array. This is called concatenation. Example (horizontal concatenation) name = 'Thomas R. Lee'; title = 'Sr. Developer'; company = 'SFTware Corp. ; s = [name, ', ', title, ', ', company]; Vertical concatenation s = char(name; title; company);

22 Cell arrays of strings (section 10.4) Creating strings in a regular MATLAB character array requires that all strings in the array be of the same length. This often means that you have to pad blanks at the end of strings to equalize their length. Cell arrays of string of the following string arrays >> name = ['Harold A. Jorgensen ';... %name has 3 elements 'Assistant Project Manager';... %blanks are padded. 'SFTware Corp. ']; >> cellname=cellstr(name); % trailing blanks are stripped off >> length(cellname{3}); ans= 13

23 Cell arrays Cell arrays of string of the following string arrays >> name = ['Harold A. Jorgensen ';... %name has 3 elements 'Assistant Project Manager';... %blanks are padded. 'SFTware Corp. ']; >> cellname=cellstr(name); % trailing blanks are stripped off >> length(cellname{3}); ans= 13 Each element of cellname is an array. >> cellname{2}(11:17) ans= Project Extend the array by adding an element of different data types: >> cellname{4}=[ ]; % a row vector is the 4 the element >> cellname{4}(2:4) % accessing the 2 nd through 4 th element ans= % of the row vector cellname{4}

24 Structures (Section 10.5) Structures are MATLAB arrays with named "data containers" called fields. The fields of a structure can contain any kind of data. Building Structure Arrays Using Assignment Statements >> patient.name = 'John Doe'; >> patient.billing = ; >> patient.test = [ ; ; ];

25 Structures Building Structure Arrays Using Assignment Statements >> patient.name = 'John Doe'; >> patient.billing = ; >> patient.test = [ ; ; ]; Now entering >> patient at the command line results in Patient= name:'john Doe' billing: 127 test: [3x3 double] To expand the structure array, add subscripts after the structure name: >> patient(2).name = 'Ann Lane'; >> patient(2).billing = 28.50; >> patient(2).test = [ ; ; ];

26 Structures Now entering >> patient at the command line results in 1x2 struct array with fields: name billing test

27 Structures Accessing Data in Structure Arrays Accessing patient records >> patient(1) ans = name: 'John Doe billing: 127 test: [3x3 double] To access a particular field >> str= patient(2).name str = Ann Lane

28 Input and Output (Sections 7.1, 7.2) User defined input >> z=input( Enter a value ) Samples of input values: numeric 12, , 12.09e+01 arrays [1, 2, 3; 4, 5, 6] string hello, it s % takes input from the command window If you are entering a string (a character arrays in MATLAB) without quotes around the string, the input statement should look like >> x=input( Enter your string, s )

29 Syntax >> tline = fgetl(fid) Input from Files (fgetl) tline = fgetl(fid) returns the next line of the file associated with the file identifier fid. If fgetl encounters the end of file indicator, it returns 1. fgetl is intended for use with files that contain newline characters. Examples The example reads every line of the input file fid=fopen( inputfile.dat, r ); %file inputfile.dat is opened for reading while ~feof(fid) tline = fgetl(fid); %reads the contents of the next line as a string disp(tline) %displays the line end fclose(fid);

30 Output Output Options disp(x) % displays the variable x. Note that there is no semicolon(;) disp( Displays the message )

31 Syntax Formatted Output fprintf (Section 7.2) >> count = fprintf( fid, format, A,...) fprintf(fid, format, A,...) formats the data in A under control of the specified format string, and writes it to the file associated with file identifier fid. fprintf returns a count of the number of bytes written if semicolon is missing.

32 fprintf (examples) >> students = 25; >> fprintf('there are %f students in CMPT 102\n', students); There are students in CMPT 102 (if fid was provided, the output would have been to the file. The structure of the line remains the same) >> fprintf('there are %5.2f students in CMPT 102 \n', students); There are students in CMPT 102

33 fprintf (examples) Example Create a text file called exp.txt containing a short table of the exponential function. x = 0:.1:1; y = [x; exp(x)]; %y has two rows fid = fopen('exp.txt', w'); fprintf(fid, '%6.2f %12.8f\n', y); fclose(fid) Now examine the contents of exp.txt: exp.txt=

34 fprintf (examples) Example The commands B = [ ; ] fprintf('x is %6.2f meters or %8.3f mm\n', 9.9, 9900, B) display the lines X is 9.90 meters or mm X is 8.80 meters or mm X is 7.70 meters or mm

35 fprintf (examples) Example To insert a single quotation mark in a string, use two single quotation marks together. For example: fprintf('it''s Friday.\n') displays on the screen: It's Friday.

36 Format String Format String The format argument is a string containing ordinary characters. A conversion specification controls the output format. Conversion specifications begin with the % character and contain these optional and required elements: Width and precision fields (optional) A subtype specifier (optional) Conversion character (required)

37 format string You specify these elements in the following order: Start of conversion %12.5e conversion character specificaton Field width Precision

38 Type field format Type field Result %f fixed point, or decimal point %e exponential notation %g whichever is shorter, %f or %e %d integer %s string of characters

39 Syntax Logical Operators: Elementwise & ~ (Chapter 8) expr1 & expr2 %expr1 and expr2 are any logical expressions expr1 expr2 % an expression is logical if its value is either true or false ~expr The symbols &,, and ~ are the logical array operators AND, OR, and NOT. These operators are commonly used in conditional statements, such as if and while, to determine whether or not to execute a particular block of code.

40 Logical Operators: Elementwise & ~ (Chapter 8) The examples shown in the following table use vector inputs A and B, where >>A = [ ]; B = [ ];

41 Find built in functions Syntax >> ind = find(x) >> [row,col] = find(x) ind = find(x) locates all nonzero elements of array X, and returns the linear indices of those elements in vector ind. [row,col] = find(x) returns the row and column indices of the nonzero entries in the matrix X. >> ind=find(x>20) locates all elements of array X greater than 20, and returns the linear indices of those elements in vector ind. [row,col] = find(x>20) returns the row and column indices of the greater than 20 entries in the matrix X.

42 Example 1 X = [ ]; Find built in functions (Examples) indices = find(x) %returns linear indices for the nonzero entries of X. indices = Example 2 You can use a logical expression to define X. For example, >> find(x > 2) % returns linear indices corresponding to the entries of X that are greater than 2. ans = 3 8 9

43 Example 3 The following find command >> X = [3 2 0; 5 0 7; 0 0 1]; >> [r,c,v] = find(x) Find built in functions (Examples) returns a column vector of row indices of the nonzero entries of X r = a column vector of column indices of the nonzero entries of X c = and a column vector containing the nonzero entries of X. v = Other examples form the text.

44 Basic plotting (Chapter 5.1) Consider two vectors: >>x=[0:2:18]; %x=[ ] >>y=[ ]; >>plot(x,y); %A graph of x versus y is created in %the figure window. >>title( First attempt ); >>xlabel( independent variable ); >>ylabel( dependent variable );

45

46 More features of plot >>plot(x,y, m )% connected line is magenta colored. >>xlim([0 25]) % x-axis range >>ylim([0 25]) % y-axis range. the graph now looks like

47

48 Multiple plot It is possible to overlay more than one graph in one plot >> hold on %Overlay the following graphs >> plot(x1,y1) >> plot(x2,y2) >>plot(x3,y3) >>hold off %Print now

49 Specifying the Color and Size of Markers You can also specify other line characteristics using graphics properties (refer the text for a description of these properties): *LineWidth Specifies the width (in points) of the line. *EdgeColor Specifies the color of the marker. * FaceColor Specifies the color of the face of filled markers. * Size Specifies the size of the marker in units of points. For example, these statements, x = pi:pi/10:pi; y = tan(sin(x)) sin(tan(x)); plot(x,y,' rs','linewidth',2,... EdgeColor','k',... FaceColor','g',... Size',10)

50

51 Scripts and functions (Chapter 6.1) Files that contain code in the MATLAB language are called Mfiles. You create M files using a text editor, then use them as you would any other MATLAB function or command. There are two kinds of M files: Scripts, which do not accept input arguments or return output arguments. They operate on data in the workspace. Functions, which can accept input arguments and return output arguments. Internal variables are local to the function. To view the contents of an M file, for example, myfunction.m, use >> type myfunction

52

53

54 M files: Functions

55 Control of flow Structures The FOR construct The FOR construct is a control construct used to repeat a set of calculations or operations a definite (or pre determined) number of times. The syntax of the for loop is for expression statements end

56 MATLAB Iteration Structures (I)

57 Vectorized Operations (for efficient code)

58 Control of flow Structures The WHILE construct The WHILE construct is related to the FOR construct in that it creates a loop that repeats a set of statments. The primary difference is in the number of times the loop statements are executed. A for loop repeats a predetermined number of times (set by the nature of the loop expression). A while loop repeats an indefinite (and potentially infinite) number of times. The syntax of the while loop is while logical_expression statements end

59 MATLAB Iteration Structures (II)

60 Control of flow Structures The IF/ELSE construct An IF construct is a decision construct as opposed to a repeat construct. The if construct allows you to conditionally (or optionally) execute blocks of code. The simplest form of the if construct has the following syntax if logical_expression block #1 statements else default statements end

61 Control of flow Structures The IF/ELSE construct The general form of the if construct if logical_expression #1 block #1 statements elseif logical_expression #2 block #2 statements : elseif logical_expression #k block #k statements : elseif logical_expression #n block #n statements : else default statements end

62 Control of flow Structures

63 Control of flow Structures The SWITCH construct The syntax is: switch switch_expression case case_expression_list #1 block #1 case case_expression_list #2 block #2 : case case_expression_list #k block #k : case case_expression_list #n block #n otherwise default block end

64 Programming Question1 Compute the value of pi using the following series How many terms are needed to obtain an accuracy where two consecutive terms differ by 1e 12? What is the value of the computed Pi?

65 function [value n]=computepi(delta) Solution to Question 1 %Compute the value of Pi using the equation given in question 1 % till two successive values during the iteration differ by less than delta. format long e previousvalue=realmax; current=0; finish=false; n=1; while ~finish current= current+1/((2*n 1)^2*(2*n+1)^2); if abs(current previousvalue) < delta value=sqrt(current*16+8); finish=true; end previousvalue=current; n=n+1; end >> [a,b]=computepi(1e-12) a = e+000 b = 502

66 Programming Question 2 The Fibonacci numbers are computed according to the following relation: F n = F n 1 + F n 2 with F 0 = F 1 = 1. a. Compute the first 100 Fibonacci numbers. b. For the first 50 Fibonacci numbers, compute the ratio F n / F n 1 It is claimed that this ratio approaches the value of the golden mean ( (1 + sqrt(5))/2 ). What do your results show?

67 Solution to Question 2 function [firstn firstnratio goldenratio]=fibonacci(n) % Solving Question 2 % firstn: vector of length n: firstn(i) contains the ith value % firstnratio: vector of length n:firstnratio(i) contains F(i)/F(i 1). firstn(1)=1; firstn(2)=2; firstnratio(1)=1; firstratio(2)=1; for i=3:n firstn(i)=firstn(i 1)+firstN(i 2); firstnratio(i)=firstn(i)/firstn(i 1); end goldenratio=(1+sqrt(5))/2;

68 Programming Question 3 The present value of an annuity (a yearly sum of money) may be computed from the formula P = (A/i) [(1 + i)n 1]/(1 + i)n where A is the annuity (in $/year), i is the nominal yearly interest rate (in decimal form), n is the number of years over which the annuity is paid and P is the present value ($). (For example computation: If i = 0.15 (15%), A = $100/year and n = 10 years then P = $ ) If you won the $1,000,000 State Lottery and the Lottery offered you the choice of $500,000 today or $50,000/year for 20 years, which would you take? You can assume an inflation (interest) rate of 5%.

69 Programming Question 4 The following algorithm for computing pi is found on a web page*: 1. Set a = 1; b = 1/sqrt(2); t = 1/4; x = 1; 2. Repeat the following commands until the difference between a and b is within some desired accuracy: y = a; a = (a + b)/2; b = sqrt(b*y); t = t x*(y a)^2; x = 2*x; 3. From the resulting values of a, b and t, an estimate of pi is Pi_est = ((a + b)^2)/(4*t); How many repeats are needed to estimate pi to an accuracy of 1e 8? 1e 12? Compare the performance of this algorithm to the result from Exercise 1, above. *

70 Programming Question 5 Create a function that generates random arrays of integers beween a and b, inclusive. Use the definition line function A = randint(a,b,m,n) where a and b define the (inclusive) range and M and N define the size of the output array (rows and columns, respectively). a. Test your function with the following piece of code: x = randint(10,17,100000,1); hist(x,10:17) % The resulting histogram should be nearly flat from 10 to 17. % Pay particular attention to the endpoints of the distribution. b. Test your function with the following pieces of code: x = randint( 30,5,100000,1); hist(x, 30:5) x = randint( 45, 35,100000,1); hist(x, 45: 35) x = randint(7, 2,100000,1); hist(x, 2:7)

71 Example 6

72 Read the file students.dat and store the lines in a cell array. function C=file2cell(fName) % reads the lines from file fname fid=fopen(fname, r ); % First two lines are read and discarded fgetl(fid); % line 1 fgetl(fid); % line 2 linenumber=1; % First data line while ~feof(fid) s=fgetl(fid); C{lineNumber}=s; linenumber=linenumber+1; %next line index end fclose(fid);

73 Extract the information on each line and store them in arrays. (Structure data types are used for elegance) function StudentData=extract(C) % Extracting information in cell array C. for i=1:length(c) StudentData(i).Firstname=C{i}(1:10); % Firstname is extracted StudentData(i).Lastname=C{i}(15:24); % Lastname is extracted StudentData(i).Age=str2num(C{i}(30:31)); %Age is extracted StudentData(i).Sex=str2num(C{i}(37)); % Sex field StudentData(i).Grade(1)=str2num(C{i}(40:43)); %Grades are picked StudentData(i).Grade(2)=str2num(C{i}(50:53)); StudentData(i).Grade(3)=str2num(C{i}(60:63)); StudentData(i).Grade(4)=str2num(C{i}(70:73)); StudentData(i).Grade(5)=str2num(C{i}(80:end)); end

74 Compute statistics, such as average age, average grade in each semester, overall average. function [Average, Overall]= statistics(studentdata); % Average is a structure data containing Age average and grade average Average.Age=0; %initialization for i=1:5 Average.Grade(i)=0; end Overall=0; N=length(StudentData); for i=1:n % all N records are visited Average.Age=Average.Age + StudentData(i).Age; % Age is summed for j=1:5 Average.Grade(j)=Average.Grade(j)+StudentData(i).Grade(j); Overall=Overall+ StudentData(i).Grade(j); end end Average.Age=Average.Age/N; for j=1:5 Average.Grade(j)=Average.Grade(j)/N; end Overall=Overall/N;

75 Remove every 8 th record from the student data. function [NewStudentData NewC]=Delete(StudentData,C) % Removing every 8 th record. Three new records are added. N=length(StudentData); newcount=1; % line count of the reduced data for i=1:n % line count of the current data if rem(i,8) ~= 0 % if it is not the 8 th record, copy. NewStudentData(newCount)=StudentData(i); NewC{newCount}=C{i}; newcount=newcount+1; end end

76 Add at least three new student records (you generate the data by hand). function [EditedStudentData,EditedC]=Insert(NewStudentData,NewC,AddData); % Records in AddData are added to NewStudentData to produce EditedStudentData. % EditedC is the cell array of the data in EditedStudentData. EditedStudentData=NewStudentData; EditedC=NewC; m=length(adddata); N=length(NewStudentData); for i=1:m EditedStudentData(N+1).Firstname=AddData(i).Lastname; EditedStudentData(N+1)Lastname=AddData(i).Firstname; EditedStudentData(N+1).Age=AddData(i).Age; EditedStudentData(N+1).Sex=AddData(i).Sex; for j=1:5 EditedStudentData(N+1).Grade(j)=AddData(i).Grade(j); end N=N+1; end % Create ProcessedC for i=1:m s(1:90)= ; s(1:10)=adddata(i).firstname;s(15:24)=adddata(i).lastname; s(30:31)=num2str(adddata(i).age); s(37)=num2str(adddata(i).sex); s(40:45)=num2str(adddata(i).grade(1)); s(50:55)=num2str(adddata(i).grade(2)); s(60:65)=num2str(adddata(i).grade(3)); s(70:75)=num2str(adddata(i).grade(4)); s(80:85} = num2str(adddata(i).grade(5)); EditedC{N+1}=s; N=N+1; end;

77 Sort the data using the Age key and store the data in a file called Processed-students.dat. function ProcessedC=SortedList(EditedStudentData, EditedC) % ProcessedC contains the records in increasing Age N=length(EditedStudentData); % N = number of records for i=1:n Age(i)=EditedStudentData(i).Age; % Collecting the Age array end; [SortedAge,Index]=sort(Age); % Age array is sorted; Index gives the rank % Copy the data for i=1:n ProcessedC{i}=EditedC{Index(i)}; end % Write the file fid=fopen( Processed-students.dat, w ); for i = 1:N fprintf(fid, %s, ProcessedC{i}); fprintf(fid, \n ); end fclose(fid); end

Low-Level File I/O. 1. Open a file. 2. Read or write data into the file. 3. Close the file. Zheng-Liang Lu 1 / 14

Low-Level File I/O. 1. Open a file. 2. Read or write data into the file. 3. Close the file. Zheng-Liang Lu 1 / 14 Low-Level File I/O Low-level file I/O functions allow the most control over reading or writing data to a file. However, these functions require that you specify more detailed information about your file

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

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial 1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

More information

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

An Introduction to MATLAB

An Introduction to MATLAB An Introduction to MATLAB Day 1 Simon Mitchell Simon.Mitchell@ucla.edu High level language Programing language and development environment Built-in development tools Numerical manipulation Plotting of

More information

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

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

More information

Getting To Know Matlab

Getting To Know Matlab Getting To Know Matlab The following worksheets will introduce Matlab to the new user. Please, be sure you really know each step of the lab you performed, even if you are asking a friend who has a better

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

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

Quick MATLAB Syntax Guide

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

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

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

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

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

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

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

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors. Physics 326G Winter 2008 Class 2 In this class you will learn how to define and work with arrays or vectors. Matlab is designed to work with arrays. An array is a list of numbers (or other things) arranged

More information

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1 MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED Christian Daude 1 Introduction MATLAB is a software package designed to handle a broad range of mathematical needs one may encounter when doing scientific

More information

CSE 123. Lecture 9. Formatted. Input/Output Operations

CSE 123. Lecture 9. Formatted. Input/Output Operations CSE 123 Lecture 9 Formatted Input/Output Operations fpintf function writes formatted data in a user specified format to a file fid fprintf Function Format effects only the display of variables not their

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

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

Matlab Tutorial: Basics

Matlab Tutorial: Basics Matlab Tutorial: Basics Topics: opening matlab m-files general syntax plotting function files loops GETTING HELP Matlab is a program which allows you to manipulate, analyze and visualize data. MATLAB allows

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

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

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

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

Stokes Modelling Workshop

Stokes Modelling Workshop Stokes Modelling Workshop 14/06/2016 Introduction to Matlab www.maths.nuigalway.ie/modellingworkshop16/files 14/06/2016 Stokes Modelling Workshop Introduction to Matlab 1 / 16 Matlab As part of this crash

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

Scalars and Variables

Scalars and Variables Chapter 2 Scalars and Variables In this chapter, we will discuss arithmetic operations with scalars (numbers, really an array with only one element) and variables. Scalars can be used directly in calculations

More information

LAB 2 VECTORS AND MATRICES

LAB 2 VECTORS AND MATRICES EN001-4: Intro to Computational Design Tufts University, Department of Computer Science Prof. Soha Hassoun LAB 2 VECTORS AND MATRICES 1.1 Background Overview of data types Programming languages distinguish

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

Importing and Exporting Data

Importing and Exporting Data Class14 Importing and Exporting Data MATLAB is often used for analyzing data that was recorded in experiments or generated by other computer programs. Likewise, data that is produced by MATLAB sometimes

More information

MATLAB GUIDE UMD PHYS401 SPRING 2012

MATLAB GUIDE UMD PHYS401 SPRING 2012 MATLAB GUIDE UMD PHYS40 SPRING 202 We will be using Matlab (or, equivalently, the free clone GNU/Octave) this semester to perform calculations involving matrices and vectors. This guide gives a brief introduction

More information

An Introductory Tutorial on Matlab

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

More information

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

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

Desktop Command window

Desktop Command window Chapter 1 Matlab Overview EGR1302 Desktop Command window Current Directory window Tb Tabs to toggle between Current Directory & Workspace Windows Command History window 1 Desktop Default appearance Command

More information

Introduction to MATLAB Practical 1

Introduction to MATLAB Practical 1 Introduction to MATLAB Practical 1 Daniel Carrera November 2016 1 Introduction I believe that the best way to learn Matlab is hands on, and I tried to design this practical that way. I assume no prior

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

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

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

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window. EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses

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

function [s p] = sumprod (f, g)

function [s p] = sumprod (f, g) Outline of the Lecture Introduction to M-function programming Matlab Programming Example Relational operators Logical Operators Matlab Flow control structures Introduction to M-function programming M-files:

More information

Worksheet 6. Input and Output

Worksheet 6. Input and Output Worksheet 6. Input and Output Most programs (except those that run other programs) contain input or output. Both fortran and matlab can read and write binary files, but we will stick to ascii. It is worth

More information

Using the fprintf command to save output to a file.

Using the fprintf command to save output to a file. Using the fprintf command to save output to a file. In addition to displaying output in the Command Window, the fprintf command can be used for writing the output to a file when it is necessary to save

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

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands

How to Use MATLAB. What is MATLAB. Getting Started. Online Help. General Purpose Commands How to Use MATLAB What is MATLAB MATLAB is an interactive package for numerical analysis, matrix computation, control system design and linear system analysis and design. On the server bass, MATLAB version

More information

Mathematical Operations with Arrays and Matrices

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

More information

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

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 GUIDE UMD PHYS401 SPRING 2011

MATLAB GUIDE UMD PHYS401 SPRING 2011 MATLAB GUIDE UMD PHYS401 SPRING 2011 Note that it is sometimes useful to add comments to your commands. You can do this with % : >> data=[3 5 9 6] %here is my comment data = 3 5 9 6 At any time you can

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

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

Today s topics. Announcements/Reminders: Characters and strings Review of topics for Test 1

Today s topics. Announcements/Reminders: Characters and strings Review of topics for Test 1 Today s topics Characters and strings Review of topics for Test 1 Announcements/Reminders: Assignment 1b due tonight 11:59pm Test 1 in class on Thursday Characters & strings We have used strings already:

More information

MBI REU Matlab Tutorial

MBI REU Matlab Tutorial MBI REU Matlab Tutorial Lecturer: Reginald L. McGee II, Ph.D. June 8, 2017 MATLAB MATrix LABoratory MATLAB is a tool for numerical computation and visualization which allows Real & Complex Arithmetics

More information

Access to Delimited Text Files

Access to Delimited Text Files Access to Delimited Text Files dlmread(filename, delimiter) reads ASCII-delimited file of numeric data. dlmwrite(filename, M, delimiter) writes the array M to the file using the specified delimiter to

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

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA

MATLAB for beginners. KiJung Yoon, 1. 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA MATLAB for beginners KiJung Yoon, 1 1 Center for Learning and Memory, University of Texas at Austin, Austin, TX 78712, USA 1 MATLAB Tutorial I What is a matrix? 1) A way of representation for data (# of

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 INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs).

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs). L A B 6 M A T L A B MATLAB INTRODUCTION Matlab is a commercial product that is used widely by students and faculty and researchers at UTEP. It provides a "high-level" programming environment for computing

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 Introductory Course Computer Exercise Session

MATLAB Introductory Course Computer Exercise Session MATLAB Introductory Course Computer Exercise Session This course is a basic introduction for students that did not use MATLAB before. The solutions will not be collected. Work through the course within

More information

Introduction to MATLAB

Introduction to MATLAB Introduction to MATLAB Introduction MATLAB is an interactive package for numerical analysis, matrix computation, control system design, and linear system analysis and design available on most CAEN platforms

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

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

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

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

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

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

Mathworks (company that releases Matlab ) documentation website is:

Mathworks (company that releases Matlab ) documentation website is: 1 Getting Started The Mathematics Behind Biological Invasions Introduction to Matlab in UNIX Christina Cobbold and Tomas de Camino Beck as modified for UNIX by Fred Adler Logging in: This is what you do

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

ES 117. Formatted Input/Output Operations

ES 117. Formatted Input/Output Operations ES 117 Formatted Input/Output Operations fpintf function writes formatted data in a user specified format to a file fid fprintf Function Format effects only the display of variables not their values through

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

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

JME Language Reference Manual

JME Language Reference Manual JME Language Reference Manual 1 Introduction JME (pronounced jay+me) is a lightweight language that allows programmers to easily perform statistic computations on tabular data as part of data analysis.

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

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

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

CITS2401 Computer Analysis & Visualisation

CITS2401 Computer Analysis & Visualisation FACULTY OF ENGINEERING, COMPUTING AND MATHEMATICS CITS2401 Computer Analysis & Visualisation SCHOOL OF COMPUTER SCIENCE AND SOFTWARE ENGINEERING Topic 3 Introduction to Matlab Material from MATLAB for

More information

7 Control Structures, Logical Statements

7 Control Structures, Logical Statements 7 Control Structures, Logical Statements 7.1 Logical Statements 1. Logical (true or false) statements comparing scalars or matrices can be evaluated in MATLAB. Two matrices of the same size may be compared,

More information

Matlab Programming Arrays and Scripts 1 2

Matlab Programming Arrays and Scripts 1 2 Matlab Programming Arrays and Scripts 1 2 Mili I. Shah September 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 Matrix

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

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

Introduction To MATLAB Introduction to Programming GENG 200

Introduction To MATLAB Introduction to Programming GENG 200 Introduction To MATLAB Introduction to Programming GENG 200, Prepared by Ali Abu Odeh 1 Table of Contents M Files 2 4 2 Execution Control 3 Vectors User Defined Functions Expected Chapter Duration: 6 classes.

More information

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

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

More information

Compact Matlab Course

Compact Matlab Course Compact Matlab Course MLC.1 15.04.2014 Matlab Command Window Workspace Command History Directories MLC.2 15.04.2014 Matlab Editor Cursor in Statement F1 Key goes to Help Information MLC.3 15.04.2014 Elementary

More information

ECE Lesson Plan - Class #3 Script M-files, Program Control, and Complex Numbers

ECE Lesson Plan - Class #3 Script M-files, Program Control, and Complex Numbers ECE 201 - Lesson Plan - Class #3 Script M-files, Program Control, and Complex Numbers Script M-files : A script file is an external file that contains a sequence of MATLAB. By typing the filename, subsequent

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

Introduction to MATLAB

Introduction to MATLAB Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming

More information

Introduction to MATLAB programming: Fundamentals

Introduction to MATLAB programming: Fundamentals Introduction to MATLAB programming: Fundamentals Shan He School for Computational Science University of Birmingham Module 06-23836: Computational Modelling with MATLAB Outline Outline of Topics Why MATLAB?

More information

Teaching Manual Math 2131

Teaching Manual Math 2131 Math 2131 Linear Algebra Labs with MATLAB Math 2131 Linear algebra with Matlab Teaching Manual Math 2131 Contents Week 1 3 1 MATLAB Course Introduction 5 1.1 The MATLAB user interface...........................

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

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