Variables and Assignments

Size: px
Start display at page:

Download "Variables and Assignments"

Transcription

1 Variables and Assignments ˆ A variable is used to keep a value or values. ˆ A box which contains something. ˆ In most languages, a statement looks like var = expression, where var is a variable and expression is any arithmetic operation. 1 ˆ For example, suppose x = 0. ˆ Then run y = x + 1 and so y = 1. (Trivial.) ˆ How about x = x + 1? ˆ Actually, the assignment operator (=) is defined to assign a value to the variable, from right to left. 1 To the best of my knowledge, 1 = x is not allowed because the left-hand side of the assignment should be a space. Zheng-Liang Lu 51 / 111

2 ˆ For example, 1 >> a = 10; 2 >> b = 20; 3 >> a + b 4 5 ans = ˆ The variable ans is used by default if you don t assign one for the immediate result. ˆ If you drop the semicolon (;) in Line 2, then the immediate result will appear in the command window. 2 2 Note that you may not drop semicolons in other programming languages. For example, the semicolon is used as the end symbol of a statement in C, C++, and Java. Zheng-Liang Lu 52 / 111

3 Variable Naming ˆ Cannot begin with a number, e.g. 1x is wrong. ˆ Cannot have blanks, e.g. x 1 is wrong. ˆ Cannot contain +-*\%, e.g. x%1 ˆ Cannot be any of key words, e.g. for ˆ Cannot be the same name as any m-file ˆ Matlab is case-sensitive, e.g. A and a are two distinct letters. Zheng-Liang Lu 53 / 111

4 ˆ Variable names should always be mnemonic. 3 ˆ May use underscores ( ) or use CamelCase. 4 ˆ We avoid to use names of reserved words 5 and built-in functions. ˆ i = 1 and j = 1 by default. ˆ If you set i = 1, then i = 1 until you clear i. ˆ pi and sin are also the names which are not to be overloaded. 3 The length of name is limited to 63 characters. The function namelengthmax returns the maximum length in this machine. 4 See 5 Try iskeyword. Zheng-Liang Lu 54 / 111

5 Scalar Variables ˆ The variable x is said to be a scalar variable if x R 1 or C 1. ˆ The complex field, denoted by C, contains all the complex numbers a + bi, where i = 1, and a, b R. 6 ˆ Try x = 1 + i in the command window. ˆ Usually used for parameters of the problems. ˆ For example, pi is a default variable to store the ratio of a circle s circumference to its diameter. 6 In math, C 1 is equivalent to R 2. So x contains two double values. However, Matlab treats a complex number as an entity. Zheng-Liang Lu 55 / 111

6 Scalar Arithmetic Operators 7 7 See Table 2.1 Arithmetic Operations Between Two Scalars in Moore, p. 21. Zheng-Liang Lu 56 / 111

7 Arrays ˆ An array, is a linear data structure consisting of a collection of elements, each identified by one array index. ˆ For math, arrays could be ˆ row vectors: u R 1 n for any positive integer n ˆ column vectors: u R n 1 for any positive integer n ˆ matrices: A R n m for any positive integers n, m ˆ Arrays can be said the simplest one of data structures. Zheng-Liang Lu 57 / 111

8 Example 1 >> rowvector = [1 2 3] % [... ] is used in arrays 2 3 rowvector = >> colvector = [1; 2; 3] % semicolon used to... change rows colvector = Zheng-Liang Lu 58 / 111

9 17 18 >> A = [1 2 3; 4 5 6; 7 8 9] A = ˆ You can create an n m k matrix for n, m, k,... N. ˆ For example, a matrix takes MBytes in memory. 8 ˆ The number of dimensions of arrays is unlimited without regarding to the limit of the memory space. 8 More explicit, / 2 20 B = MB. Zheng-Liang Lu 59 / 111

10 Alternatives for Vector Creation ˆ The function linspace(start, end, npts) generates a vector of uniformly incremented values. 9 1 >> x = linspace(0, 10, 5) 2 3 x = Also try logspace. Zheng-Liang Lu 60 / 111

11 ˆ You can also create a vector by using the colon operator as follows: start : step size : end 1 >> x = 0 : 2 : x = ˆ This is widely used to create index arrays to manipulate arrays. 1 >> x = 1 : 5 % default step size = x = Zheng-Liang Lu 61 / 111

12 ˆ You could create a null vector, say: 1 >> x = 1 : -1 : x = 4 5 Empty matrix: 1-by-0 ˆ It will be useful later! Zheng-Liang Lu 62 / 111

13 ˆ Some special matrices can be initialized by the following functions: Zheng-Liang Lu 63 / 111

14 Array Addressing ˆ We often use subscripted indexing like the way in math. ˆ Rarely use linear indexing: column major order >> A(2, 3) % using subscripted indexing 2 3 ans = >> A(8) % using linear indexing 8 9 ans = How could a 1d memory store a 2d array? Zheng-Liang Lu 64 / 111

15 1 >> A([1 3], [1 3]) % range selection 2 3 ans = >> A(2, 2 : end - 1) 9 10 ans = Zheng-Liang Lu 65 / 111

16 1 >> A(:, 2) = [] % deletion (removing the second... column vector) 2 3 A = >> B = [A, A] % merge A and A 11 B = Zheng-Liang Lu 66 / 111

17 Cells and Cell Arrays 11 ˆ An array cannot contain data of different types correctly! ˆ A cell array is a data type with indexed data containers called cells, and each cell can contain any type of data. ˆ Cell arrays commonly contain either lists of text strings, combinations of text and numbers, or numeric arrays of different sizes. 11 Basically, cell arrays do not require completely contiguous memory because Matlab does not allocate any memory for the contents of each cell when the cell array is created. However, each cell requires contiguous memory, as does the cell array header that Matlab creates to describe the array. Zheng-Liang Lu 67 / 111

18 Example 12 1 >> stock = {'TSMC', 100; 2 'GOOG', 200; 3 'AAPL', 300} 4 5 stock = 6 7 3x2 cell array 8 9 {'TSMC'} {[100]} 10 {'GOOG'} {[200]} 11 {'AAPL'} {[300]} ˆ However, the arithmetic operators cannot be applied to the cell arrays! 12 Thanks to a lively class discussion (Matlab263) on March 3, Zheng-Liang Lu 68 / 111

19 Referring to Cell Arrays ˆ Using curly braces, { } will reference the contents of a cell. 1 >> A{3, 1} 2 3 ans = 4 5 AAPL ˆ More details can be found in here. Zheng-Liang Lu 69 / 111

20 Structures and Structure Arrays ˆ A structure can be used to group related data by meaningful names, called fields. ˆ We access these fields by the dot operator. ˆ For example, 1 >> stock = struct('name', {'TSMC', 'GOOG',... 'APPL'}, 'price', {100, 200, 300}) 2 3 stock = 4 5 1x3 struct array with fields: 6 7 name 8 price Zheng-Liang Lu 70 / 111

21 ˆ More details can be found here. ˆ Widely used in object-oriented applications, such as GUI design. ˆ The arithmetic operators cannot be applied to structures, either! Zheng-Liang Lu 71 / 111

22 Symbols for Common Data Structures Zheng-Liang Lu 72 / 111

23 Summary 13,14 ˆ Parentheses ( ) ˆ Arithmetic, e.g. (x + y)/z. ˆ Input arguments of functions, e.g. sin(1), exp(1). ˆ Array addressing, e.g. A(1) refers to the first element in array A. ˆ Square brackets [ ]: only used in array operations ˆ e.g. x = [ ]. ˆ Curly brackets { }: only used in cells ˆ e.g. A = { This is Matlab class., x}. 13 Thanks to a lively class discussion (Matlab237) on April 16, You can refer to this page for more details of special characters. Zheng-Liang Lu 73 / 111

24 More Data Structures ˆ See data-types_data-types.html Some of them may not be available if your version is out-of-date. Zheng-Liang Lu 74 / 111

25 Vectorization 16 ˆ Matlab favors array operations. ˆ When two arrays have the same dimensions, addition, subtraction, multiplication, and division apply on an element-by-element basis. ˆ For example, 1 >> x = [1 2 3]; 2 >> y = [4 5 6]; 3 >> x + y 4 5 ans = More about vectorization. Zheng-Liang Lu 75 / 111

26 Element-By-Element Operations ˆ The Left division is used in the inverse matrix problems We will visit this in the chapter of matrix computation. Zheng-Liang Lu 76 / 111

27 1 >> Lecture 2 2 >> 3 >> -- Programming Basics 4 >> Zheng-Liang Lu 77 / 111

28 If debugging is the process of removing software bugs, then programming must be the process of putting them in. Edsger W. Dijkstra ( ) Zheng-Liang Lu 78 / 111

29 Introduction ˆ Decision making facilitates the usefulness of programs. ˆ For example, Self Driving Cars by Google. 18 ˆ Also, some actions (functions) are repeated for a specified number of times or until the stopping condition is satisfied. ˆ An algorithm must have the ability to alter the order of its instructions using what is called a control structure. ˆ The first principle in designing algorithms is to divide and conquer. ˆ Recall the algorithm for max(a). ˆ This feature enables engineers to solve problems of great complexity or requiring numerous calculations. 18 See Zheng-Liang Lu 79 / 111

30 Building Blocks ˆ Sequential operations: be executed in order. ˆ Selections: check which condition is satisfied and then execute the actions accordingly. ˆ Repetitions: repeat some instructions and stop while the termination condition is satisfied. Zheng-Liang Lu 80 / 111

31 Pseudo Code ˆ The pseudo code is widely used to describe algorithms. ˆ They are a mixture of natural language and mathematical expressions with common structures of programming languages. ˆ For example, 1 for each student 2 if this student's final score >= 60, then 3 get 'PASS' 4 else 5 get 'FAIL' 6 end 7 end Zheng-Liang Lu 81 / 111

32 Relational Operators 19 ˆ Matlab provides relational operators to make comparisons between two arrays of equal size. 19 See Table 8.1 in Moore, p Zheng-Liang Lu 82 / 111

33 Boolean (Logical) Values ˆ Boolean values are only true and false. 20 ˆ The function true and false represent logical true and logical false, respectively. 21 ˆ Boolean variable contains a boolean value. ˆ For example, 1 >> x = 1; y = 2; 2 >> w = (y > x) ~= true 3 4 w = Note that the numeric number 0 can be regarded as false in general, and nonzero numbers are regarded as true in Matlab and some programming languages. 21 The usage of true and false is similar to zeros. Zheng-Liang Lu 83 / 111

34 Masks as Filters ˆ Boolean arrays are often used as masks to manipulate arrays as an alternative to index arrays. 1 >> scores = [ ]; 2 >> haspassed = scores >= haspassed = >> scores(haspassed) 9 10 ans = Zheng-Liang Lu 84 / 111

35 Logical Operators ˆ Assume x = 0; ˆ How about 1 < x < 3? (Surprising!) Zheng-Liang Lu 85 / 111

36 Truth Table ˆ Let A and B be two Boolean variables. ˆ Then the truth table for logical operators is as follows: A B A A&B A B xor(a, B) T T F T T F T F F F T T F T T F T T F F T F F F ˆ Note that the instructions of computers, such as arithmetic operations, are implemented by logic gates See any textbook for digital circuit design. Zheng-Liang Lu 86 / 111

37 Exercise: & vs. == 23 1 >> x = [ ]; 2 >> y = [ ]; 3 >> x == y 4 5 ans = >> x & y 11 ans = Thanks to a lively class discussion (Matlab-237) on April 16, Zheng-Liang Lu 87 / 111

38 Quantifiers 24 ˆ The function all determines if all elements are true. 1 >> x = [ ]; 2 >> all(x >= 60) 3 ans = ˆ The function any determines if there is any true element in the array. 1 >> any(x >= 60) 2 ans = See Zheng-Liang Lu 88 / 111

39 More Logical Functions ˆ NaN: Not A Number, caused by and See NaN. Zheng-Liang Lu 89 / 111

40 Digress: Set Membership 27 ˆ Matlab provides useful functions such as intersect, union, unique, and setdiff. 26 ˆ For example, 1 >> x = [ ]; y = [ ]; 2 >> intersect(x, y) 3 4 ans = See 27 Thanks to a lively class discussion (Matlab263) on March 9, Zheng-Liang Lu 90 / 111

41 Logic is the anatomy of thought. John Locke ( ) This sentence is false. I know that I know nothing. anonymous Plato (In Apology, Plato relates that Socrates accounts for his seeming wiser than any other person because he does not imagine that he knows what he does not know.) Zheng-Liang Lu 91 / 111

42 Precedence of Operators See Table 1.2 Operator Precedence Rules in Attaway, p. 25. Zheng-Liang Lu 92 / 111

43 Selections ˆ Selection enables us to write programs that make decisions on. ˆ Selection structures contain one or more of the if, else, and elseif statements. ˆ The end statement denotes the end of selection structures. Zheng-Liang Lu 93 / 111

44 Example: if-else ˆ Write a program which takes a number as input. ˆ If the number is a nonnegative real number, then calculate its square root. ˆ We may use the function input which takes a number from the keyboard. 1 clear; clc; 2 3 x = input('enter a number? '); % input from keyboard 4 if x >= 0 5 sqrt(x) 6 else 7 disp([num2str(x),' is a negative number.']); 8 end Zheng-Liang Lu 94 / 111

45 Exercise: Nested Conditional Statements 1 clear; clc; 2 x = input('enter x?', 's'); 3 % Contribution by Mr. Curtis Yen on Sep. 10, w = str2num(x); 5 if isempty(w) % w is not empty if w is a number 6 disp([x, ' is not a number.']); 7 else 8 if w >= 0 9 sqrt(w) 10 else 11 disp([x ' is not a positive real number.']); 12 end 13 end ˆ Do not write a deeply nested conditional statement. Zheng-Liang Lu 95 / 111

46 Example: if-elseif-else 1 clear; clc; 2 x = input('enter x?', 's'); 3 w = str2num(x); 4 if isempty(w) % w is not empty if w is a number 5 disp([x ' is not a number.']); 6 elseif w >= 0 7 sqrt(w) 8 else 9 disp([x ' is not a positive real number.']); 10 end ˆ Can we change the order of the conditions? ˆ You can put w >= 0 in the first condition. 29 ˆ The empty set can be evaluated as false by the if statement. 29 Thanks to a lively class discussion (Matlab-260) on August 29, Zheng-Liang Lu 96 / 111

47 Example: GPA Conversion Problem 30 ˆ Write a program which converts centesimal points to GPA. ˆ Let x be the grade input. ˆ For simplicity, ˆ If 90 x 100, then x is converted to 4. ˆ If 80 x < 90, then 3. ˆ If 70 x < 80, then 2. ˆ If 60 x < 70, then 1. ˆ If x < 60, then See GPA. Zheng-Liang Lu 97 / 111

48 1 clear; clc; 2 x = input('enter points? '); 3 if x >= 90 && x <= disp('4'); 5 elseif x >= 80 && x < 90 6 disp('3'); 7 elseif x >= 70 && x < 80 8 disp('2'); 9 elseif x >= 60 && x < disp('1'); 11 else 12 disp('0'); 13 end ˆ Can we reverse the conditions? ˆ Can we place the conditions at your will? Zheng-Liang Lu 98 / 111

49 & vs. && 1 clear; clc; 2 3 x = [ ]; 4 y = [ ]; 5 6 x > 0 & y > 0 % return [ ] 7 all(x > 0) && any(y > 0) % return 0 ˆ Consider A && B. ˆ If A returns false, then B won t be evaluated. ˆ This is so-called the short-circuit operator, which facilitates time-saving. ˆ Note that the argument for if statements can be a scalar only! Zheng-Liang Lu 99 / 111

50 Another Selection Structure: switch-case ˆ The switch-case statements allow you to choose between multiple outcomes by checking the value of the target variable. ˆ For example, 1 clear; clc; 2 city = input('enter the name of a city: ', 's'); 3 switch city 4 case {'Taipei', 'New Taipei'} 5 disp('price: $100'); 6 case 'Taichung' 7 disp('price: $200'); 8 case 'Tainan' 9 disp('price: $300'); 10 otherwise 11 disp('not an option.'); % default option 12 end Zheng-Liang Lu 100 / 111

51 Why Not if? if strcmp(city, 'Taipei') strcmp(city, 'New... Taipei') 3 disp('price: $100'); 4 elseif strcmp(city, 'Taichung') 5 disp('price: $200'); 6 elseif strcmp(city, 'Tainan') 7 disp('price: $300'); 8 else 9 disp('not an option.'); 10 end ˆ Can you implement the strcmp function? 31 Thanks to a lively class discussion (Matlab-244) on August 20, Zheng-Liang Lu 101 / 111

52 Exercise ˆ We can try to replicate the functionality of strcmp by not calling it. ˆ You may use the function length to calculate the size of the string (or any arrays later) istaipei = length(city) == length('taipei') &&... 3 all(city == 'Taipei'); 4 isnewtaipei =... % Do the same thing below. 5 6 if istaipei isnewtaipei 7... % Show the ticket price. 8 elseif % Do the same thing below. 10 end Zheng-Liang Lu 102 / 111

53 Error and Error Handling ˆ You can issue an error if you do not allow the callee for some situations >> error('this is an error.'); ˆ Also, you can use a try-catch statement to handle errors. 1 try 2 % normal operations 3 catch 4 % handler operations 5 end 32 In other words, you can decide if the action can be performed. Zheng-Liang Lu 103 / 111

54 Example: Combinations ˆ For all nonnegative integers n k, ( n k) is given by ( ) n n! = k k!(n k)!. ˆ Note that factorial(n) returns n!. 1 clear; clc; 2 3 n = input('n =? '); 4 k = input('k =? '); 5 y = factorial(n) / (factorial(k) * factorial(n - k)) 6 disp('end of program.'); Zheng-Liang Lu 104 / 111

55 ˆ Try n = 2, k = 5. ˆ factorial( 3) is not allowed! ˆ So your program stops in Line 5, and terminates abnormally. ˆ The reason is that Line 5 produces an error and the program is not designed to handle it. ˆ Then Matlab takes over and kills this program try 3 y = factorial(n) / (factorial(k) *... factorial(n - k)) 4 catch e % capture the thrown exception 5 disp(['error: ' e.message]); 6 end 7 disp('end of program.'); Zheng-Liang Lu 105 / 111

56 Exercise: Divided by Zero ˆ Write a program which calculates x/y for any two real numbers x, y. ˆ The program restricts the user to do division by zero. ˆ Note that we don t use this error-handling mechanism for normal executions in regard to the performance! 1... % assume x = 1 any y = 0 2 if y == 0 3 error('divided by zero!'); 4 else 5 ans = x / y; 6 end 7... Zheng-Liang Lu 106 / 111

57 Repetitions ˆ If a group of instructions is potentially repeated, you should wrap those in a repetition structure, called loops. ˆ All loops consist of 3 parts: ˆ Find the repeated pattern for each iteration. ˆ Warp them by a loop. ˆ Set the continuation condition by defining a loop variable with some criterion. ˆ Matlab provides two different types: the for loops and the while loops. ˆ Use for loops if you know the number of iterations. ˆ Otherwise, use while loops. Zheng-Liang Lu 107 / 111

58 for Loops ˆ A for loop is the easiest choice when you know how many times you need to repeat the loop. 1 for loopvar = somearray 2 % body 3 end ˆ Particularly, we often use for loops to manipulate arrays! Zheng-Liang Lu 108 / 111

59 Zheng-Liang Lu 109 / 111

60 Example 1 for i = 1 : 10 2 disp(i); 3 end ˆ Can you show the odd integers from 1 to 9? 1 for student = {'Arthur', 'Alice'} 2 disp(cell2mat(student)); 3 % remember to take things out of cells 4 end ˆ Clearly, Matlab has for-each loops, which is an enhanced one compared to the naive one in C. ˆ Note that we use the function cell2mat so that a string stored in the cell can be extracted as a string. Zheng-Liang Lu 110 / 111

61 Example: Find Maximum (Revisited) 1 clear; clc; 2 3 x = [ ]; % input list 4 max = x(1); 5 for i = 2 : 7 6 if max < x(i) 7 max = x(i); 8 end 9 end 10 max ˆ Can you find the location of the maximum element? ˆ Try to find the minimum element and its location. Zheng-Liang Lu 111 / 111

Arrays. ˆ An array, is a linear data structure consisting of a collection of elements, each identified by one array index. ˆ For math, arrays could be

Arrays. ˆ An array, is a linear data structure consisting of a collection of elements, each identified by one array index. ˆ For math, arrays could be Arrays ˆ An array, is a linear data structure consisting of a collection of elements, each identified by one array index. ˆ For math, arrays could be ˆ row vectors: u R 1 n for any positive integer n ˆ

More information

Selections. Zheng-Liang Lu 91 / 120

Selections. Zheng-Liang Lu 91 / 120 Selections ˆ Selection enables us to write programs that make decisions on. ˆ Selection structures contain one or more of the if, else, and elseif statements. ˆ The end statement denotes the end of selection

More information

Structure Array 1 / 50

Structure Array 1 / 50 Structure Array A structure array is a data type that groups related data using data containers called fields. Each field can contain any type of data. Access data in a structure using dot notation of

More information

IEEE Floating-Point Representation 1

IEEE Floating-Point Representation 1 IEEE Floating-Point Representation 1 x = ( 1) s M 2 E The sign s determines whether the number is negative (s = 1) or positive (s = 0). The significand M is a fractional binary number that ranges either

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

More information

false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

false, import, new 1 class Lecture2 { 2 3 Data types, Variables, and Operators 4 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 45

More information

Logic is the anatomy of thought. John Locke ( ) This sentence is false.

Logic is the anatomy of thought. John Locke ( ) This sentence is false. Logic is the anatomy of thought. John Locke (1632 1704) This sentence is false. I know that I know nothing. anonymous Plato (In Apology, Plato relates that Socrates accounts for his seeming wiser than

More information

Data Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87

Data Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87 Data Types Java is a strongly-typed 1 programming language. Every variable has a type. Also, every (mathematical) expression has a type. There are two categories of data types: primitive data types, and

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 Programming with Applications

Introduction to Matlab Programming with Applications Introduction to Matlab Programming with Applications Zheng-Liang Lu Department of Computer Science and Information Engineering National Taiwan University Matlab 289 Summer 2017 Class Information ˆ The

More information

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28

Control Structures. March 1, Dr. Mihail. (Dr. Mihail) Control March 1, / 28 Control Structures Dr. Mihail March 1, 2015 (Dr. Mihail) Control March 1, 2015 1 / 28 Overview So far in this course, MATLAB programs consisted of a ordered sequence of mathematical operations, functions,

More information

Introduction to Matlab Programming with Applications

Introduction to Matlab Programming with Applications Introduction to Matlab Programming with Applications Zheng-Liang Lu Department of Computer Science and Information Engineering National Taiwan University Matlab 256 Summer 2015 Class Information Official

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

Boolean Logic & Branching Lab Conditional Tests

Boolean Logic & Branching Lab Conditional Tests I. Boolean (Logical) Operations Boolean Logic & Branching Lab Conditional Tests 1. Review of Binary logic Three basic logical operations are commonly used in binary logic: and, or, and not. Table 1 lists

More information

Lesson 3: Basic Programming Concepts

Lesson 3: Basic Programming Concepts 3 ICT Gaming Essentials Lesson 3: Basic Programming Concepts LESSON SKILLS After completing this lesson, you will be able to: Explain the types and uses of variables and operators in game programming.

More information

The return Statement

The return Statement The return Statement The return statement is the end point of the method. A callee is a method invoked by a caller. The callee returns to the caller if the callee completes all the statements (w/o a return

More information

Operators. Java operators are classified into three categories:

Operators. Java operators are classified into three categories: Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

More information

Arithmetic Compound Assignment Operators

Arithmetic Compound Assignment Operators Arithmetic Compound Assignment Operators Note that these shorthand operators are not available in languages such as Matlab and R. Zheng-Liang Lu Java Programming 76 / 141 Example 1... 2 int x = 1; 3 System.out.println(x);

More information

MATLAB TUTORIAL WORKSHEET

MATLAB TUTORIAL WORKSHEET MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent

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

++x vs. x++ We will use these notations very often.

++x vs. x++ We will use these notations very often. ++x vs. x++ The expression ++x first increments the value of x and then returns x. Instead, the expression x++ first returns the value of x and then increments itself. For example, 1... 2 int x = 1; 3

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

Computer Programming in MATLAB

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

More information

1 class Lecture3 { 2 3 "Selections" // Keywords 8 if, else, else if, switch, case, default. Zheng-Liang Lu Java Programming 88 / 133

1 class Lecture3 { 2 3 Selections // Keywords 8 if, else, else if, switch, case, default. Zheng-Liang Lu Java Programming 88 / 133 1 class Lecture3 { 2 3 "Selections" 4 5 } 6 7 // Keywords 8 if, else, else if, switch, case, default Zheng-Liang Lu Java Programming 88 / 133 Flow Controls The basic algorithm (and program) is constituted

More information

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 172 / 225

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 172 / 225 1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 172 / 225 Functions The first thing of the design of algorithms is to divide and conquer. A large and complex problem would be solved by couples

More information

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

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

More information

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

EGR 111 Introduction to MATLAB

EGR 111 Introduction to MATLAB EGR 111 Introduction to MATLAB This lab introduces the MATLAB help facility, shows how MATLAB TM, which stands for MATrix LABoratory, can be used as an advanced calculator. This lab also introduces assignment

More information

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221

1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221 1 >> Lecture 3 2 >> 3 >> -- Functions 4 >> Zheng-Liang Lu 169 / 221 Functions Recall that an algorithm is a feasible solution to the specific problem. 1 A function is a piece of computer code that accepts

More information

1 class Lecture3 { 2 3 "Selections" // Keywords 8 if, else, else if, switch, case, default. Zheng-Liang Lu Java Programming 89 / 137

1 class Lecture3 { 2 3 Selections // Keywords 8 if, else, else if, switch, case, default. Zheng-Liang Lu Java Programming 89 / 137 1 class Lecture3 { 2 3 "Selections" 4 5 } 6 7 // Keywords 8 if, else, else if, switch, case, default Zheng-Liang Lu Java Programming 89 / 137 Flow Controls The basic algorithm (and program) is constituted

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

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

Method Invocation. Zheng-Liang Lu Java Programming 189 / 226

Method Invocation. Zheng-Liang Lu Java Programming 189 / 226 Method Invocation Note that the input parameters are sort of variables declared within the method as placeholders. When calling the method, one needs to provide arguments, which must match the parameters

More information

Relational and Logical Operators

Relational and Logical Operators Relational and Logical Operators Relational Operators Relational operators are used to represent conditions (such as space 0 in the water tank example) Result of the condition is either true or false In

More information

Dr Richard Greenaway

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

More information

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

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

More information

9. Elementary Algebraic and Transcendental Scalar Functions

9. Elementary Algebraic and Transcendental Scalar Functions Scalar Functions Summary. Introduction 2. Constants 2a. Numeric Constants 2b. Character Constants 2c. Symbol Constants 2d. Nested Constants 3. Scalar Functions 4. Arithmetic Scalar Functions 5. Operators

More information

MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs

MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs MATLAB Laboratory 10/07/10 Lecture Chapter 7: Flow Control in Programs Lisa A. Oberbroeckling Loyola University Maryland loberbroeckling@loyola.edu L. Oberbroeckling (Loyola University) MATLAB 10/07/10

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

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB:

Variables are used to store data (numbers, letters, etc) in MATLAB. There are a few rules that must be followed when creating variables in MATLAB: Contents VARIABLES... 1 Storing Numerical Data... 2 Limits on Numerical Data... 6 Storing Character Strings... 8 Logical Variables... 9 MATLAB S BUILT-IN VARIABLES AND FUNCTIONS... 9 GETTING HELP IN MATLAB...

More information

Introduction to Engineering gii

Introduction to Engineering gii 25.108 Introduction to Engineering gii Dr. Jay Weitzen Lecture Notes I: Introduction to Matlab from Gilat Book MATLAB - Lecture # 1 Starting with MATLAB / Chapter 1 Topics Covered: 1. Introduction. 2.

More information

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

Scientific Computing with MATLAB

Scientific Computing with MATLAB Scientific Computing with MATLAB Dra. K.-Y. Daisy Fan Department of Computer Science Cornell University Ithaca, NY, USA UNAM IIM 2012 2 Focus on computing using MATLAB Computer Science Computational Science

More information

Chapter 7: Programming in MATLAB

Chapter 7: Programming in MATLAB The Islamic University of Gaza Faculty of Engineering Civil Engineering Department Computer Programming (ECIV 2302) Chapter 7: Programming in MATLAB 1 7.1 Relational and Logical Operators == Equal to ~=

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

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath

UNIT - I. Introduction to C Programming. BY A. Vijay Bharath UNIT - I Introduction to C Programming Introduction to C C was originally developed in the year 1970s by Dennis Ritchie at Bell Laboratories, Inc. C is a general-purpose programming language. It has been

More information

Scanner Objects. Zheng-Liang Lu Java Programming 82 / 133

Scanner Objects. Zheng-Liang Lu Java Programming 82 / 133 Scanner Objects It is not convenient to modify the source code and recompile it for a different radius. Reading from the console enables the program to receive an input from the user. A Scanner object

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

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

Relational and Logical Operators. MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs. Examples. Logical Operators.

Relational and Logical Operators. MATLAB Laboratory 10/07/10 Lecture. Chapter 7: Flow Control in Programs. Examples. Logical Operators. Relational and Logical Operators MATLAB Laboratory 10/07/10 Lecture Chapter 7: Flow Control in Programs Both operators take on form expression1 OPERATOR expression2 and evaluate to either TRUE (1) or FALSE

More information

Selection Statements

Selection Statements Selection Statements by Ahmet Sacan selection statements, branching statements, condition, relational expression, Boolean expression, logical expression, relational operators, logical operators, truth

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 Introduction to MATLAB Dr./ Ahmed Nagib Mechanical Engineering department, Alexandria university, Egypt Spring 2017 Chapter 4 Decision making and looping functions (If, for and while functions) 4-1 Flowcharts

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

egrapher Language Reference Manual

egrapher Language Reference Manual egrapher Language Reference Manual Long Long: ll3078@columbia.edu Xinli Jia: xj2191@columbia.edu Jiefu Ying: jy2799@columbia.edu Linnan Wang: lw2645@columbia.edu Darren Chen: dsc2155@columbia.edu 1. Introduction

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

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

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA

Starting with a great calculator... Variables. Comments. Topic 5: Introduction to Programming in Matlab CSSE, UWA Starting with a great calculator... Topic 5: Introduction to Programming in Matlab CSSE, UWA! MATLAB is a high level language that allows you to perform calculations on numbers, or arrays of numbers, in

More information

Introduction to Matlab

Introduction to Matlab Introduction to Matlab Andreas C. Kapourani (Credit: Steve Renals & Iain Murray) 9 January 08 Introduction MATLAB is a programming language that grew out of the need to process matrices. It is used extensively

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

Relational and Logical Statements

Relational and Logical Statements Relational and Logical Statements Relational Operators in MATLAB A operator B A and B can be: Variables or constants or expressions to compute Scalars or arrays Numeric or string Operators: > (greater

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

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

(Not Quite) Minijava

(Not Quite) Minijava (Not Quite) Minijava CMCS22620, Spring 2004 April 5, 2004 1 Syntax program mainclass classdecl mainclass class identifier { public static void main ( String [] identifier ) block } classdecl class identifier

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

Dr. Iyad Jafar. Adapted from the publisher slides

Dr. Iyad Jafar. Adapted from the publisher slides Computer Applications Lab Lab 5 Programming in Matlab Chapter 4 Sections 1,2,3,4 Dr. Iyad Jafar Adapted from the publisher slides Outline Program design and development Relational operators and logical

More information

Repetition Structures Chapter 9

Repetition Structures Chapter 9 Sum of the terms Repetition Structures Chapter 9 1 Value of the Alternating Harmonic Series 0.9 0.8 0.7 0.6 0.5 10 0 10 1 10 2 10 3 Number of terms Objectives After studying this chapter you should be

More information

Lecture (03) Arrays. By: Dr. Ahmed ElShafee. Dr. Ahmed ElShafee, ACU : Spring 2018, HUM107 Introduction to Engineering

Lecture (03) Arrays. By: Dr. Ahmed ElShafee. Dr. Ahmed ElShafee, ACU : Spring 2018, HUM107 Introduction to Engineering Lecture (03) Arrays By: Dr. Ahmed ElShafee ١ Dr. Ahmed ElShafee, ACU : Spring 2018, HUM107 Introduction to Engineering Characters and Strings Strings are defined by delimiting text with single quotation

More information

1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

1 class Lecture2 { 2 3 Elementray Programming / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 41 / 68 Example Given the radius

More information

APPM 2460 Matlab Basics

APPM 2460 Matlab Basics APPM 2460 Matlab Basics 1 Introduction In this lab we ll get acquainted with the basics of Matlab. This will be review if you ve done any sort of programming before; the goal here is to get everyone on

More information

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression

\n is used in a string to indicate the newline character. An expression produces data. The simplest expression Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING

7/8/10 KEY CONCEPTS. Problem COMP 10 EXPLORING COMPUTER SCIENCE. Algorithm. Lecture 2 Variables, Types, and Programs. Program PROBLEM SOLVING KEY CONCEPTS COMP 10 EXPLORING COMPUTER SCIENCE Lecture 2 Variables, Types, and Programs Problem Definition of task to be performed (by a computer) Algorithm A particular sequence of steps that will solve

More information

ˆ Note that we often make a trade-off between time and space. ˆ Time complexity ˆ Space complexity. ˆ Unlike time, we can reuse memory.

ˆ Note that we often make a trade-off between time and space. ˆ Time complexity ˆ Space complexity. ˆ Unlike time, we can reuse memory. ˆ We use O-notation to describe the asymptotic 1 upper bound of complexity of the algorithm. ˆ So O-notation is widely used to classify algorithms by how they respond to changes in its input size. 2 ˆ

More information

SECTION 1: INTRODUCTION. ENGR 112 Introduction to Engineering Computing

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

More information

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

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

More information

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines. Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Exercise. Write a program which allows the user to enter the math grades one by one (-1 to exit), and outputs a histogram.

Exercise. Write a program which allows the user to enter the math grades one by one (-1 to exit), and outputs a histogram. Exercise Write a program which allows the user to enter the math grades one by one (-1 to exit), and outputs a histogram. Zheng-Liang Lu Java Programming 197 / 227 1... 2 int[] hist = new int[5]; 3 //

More information

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++

Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ Laboratory 0 Week 0 Advanced Structured Programming An Introduction to Visual Studio and C++ 0.1 Introduction This is a session to familiarize working with the Visual Studio development environment. It

More information

Computer Programming C++ (wg) CCOs

Computer Programming C++ (wg) CCOs Computer Programming C++ (wg) CCOs I. The student will analyze the different systems, and languages of the computer. (SM 1.4, 3.1, 3.4, 3.6) II. The student will write, compile, link and run a simple C++

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. 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 Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Introduction to Internet of Things Prof. Sudip Misra Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture - 23 Introduction to Arduino- II Hi. Now, we will continue

More information

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = ( Floating Point Numbers in Java by Michael L. Overton Virtually all modern computers follow the IEEE 2 floating point standard in their representation of floating point numbers. The Java programming language

More information

MATLAB 1. Jeff Freymueller September 24, 2009

MATLAB 1. Jeff Freymueller September 24, 2009 MATLAB 1 Jeff Freymueller September 24, 2009 MATLAB IDE MATLAB Edi?ng Window We don t need no steenkin GUI You can also use MATLAB without the fancy user interface, just a command window. Why? You can

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

Dr. Relja Vulanovic Professor of Mathematics Kent State University at Stark c 2008

Dr. Relja Vulanovic Professor of Mathematics Kent State University at Stark c 2008 MATH-LITERACY MANUAL Dr. Relja Vulanovic Professor of Mathematics Kent State University at Stark c 2008 1 Real Numbers 1.1 Sets 1 1.2 Constants and Variables; Real Numbers 7 1.3 Operations with Numbers

More information

Scilab Programming. The open source platform for numerical computation. Satish Annigeri Ph.D.

Scilab Programming. The open source platform for numerical computation. Satish Annigeri Ph.D. Scilab Programming The open source platform for numerical computation Satish Annigeri Ph.D. Professor, Civil Engineering Department B.V.B. College of Engineering & Technology Hubli 580 031 satish@bvb.edu

More information

Cloning Arrays. In practice, one might duplicate an array for some reason. One could attempt to use the assignment statement (=), for example,

Cloning Arrays. In practice, one might duplicate an array for some reason. One could attempt to use the assignment statement (=), for example, Cloning Arrays In practice, one might duplicate an array for some reason. One could attempt to use the assignment statement (=), for example, 1... 2 T[] A = {...}; // assume A is an array 3 T[] B = A;

More information

1 class Lecture5 { 2 3 "Methods" / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 0 / Zheng-Liang Lu Java Programming 176 / 199

1 class Lecture5 { 2 3 Methods / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 0 / Zheng-Liang Lu Java Programming 176 / 199 1 class Lecture5 { 2 3 "Methods" 4 5 } 6 7 / References 8 [1] Ch. 5 in YDL 9 [1] Ch. 20 in YDL 0 / Zheng-Liang Lu Java Programming 176 / 199 Methods 2 Methods can be used to define reusable code, and organize

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

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop

Announcements. Lab Friday, 1-2:30 and 3-4:30 in Boot your laptop and start Forte, if you brought your laptop Announcements Lab Friday, 1-2:30 and 3-4:30 in 26-152 Boot your laptop and start Forte, if you brought your laptop Create an empty file called Lecture4 and create an empty main() method in a class: 1.00

More information

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have

CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have CSCI 131, Midterm Exam 1 Review Questions This sheet is intended to help you prepare for the first exam in this course. The following topics have been covered in the first 5 weeks of the course. The exam

More information

Lecture 1: Hello, MATLAB!

Lecture 1: Hello, MATLAB! Lecture 1: Hello, MATLAB! Math 98, Spring 2018 Math 98, Spring 2018 Lecture 1: Hello, MATLAB! 1 / 21 Syllabus Instructor: Eric Hallman Class Website: https://math.berkeley.edu/~ehallman/98-fa18/ Login:!cmfmath98

More information

Relational & Logical Operators, Selection Statements

Relational & Logical Operators, Selection Statements Relational & Logical Operators, Selection Statements by Ahmet Sacan selection statements, branching statements, condition, relational expression, Boolean expression, logical expression, relational operators,

More information

Section 1.1 Definitions and Properties

Section 1.1 Definitions and Properties Section 1.1 Definitions and Properties Objectives In this section, you will learn to: To successfully complete this section, you need to understand: Abbreviate repeated addition using Exponents and Square

More information

Computational Finance

Computational Finance Computational Finance Introduction to Matlab Marek Kolman Matlab program/programming language for technical computing particularly for numerical issues works on matrix/vector basis usually used for functional

More information