Presentation is loading. Please wait.

Presentation is loading. Please wait.

MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.

Similar presentations


Presentation on theme: "MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations."— Presentation transcript:

1 MATLAB Lecture 1 염익준

2 Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations. implements the MATLAB programming language and provides a extensive library of predefined functions. 2

3 Advantages Ease of use Platform independence Predefined functions Device-independent plotting Graphical user interface MATLAB compiler 3

4 Disadvantages Cost GNU Octave for free 4

5 MATLAB Programming 5

6 Variables and Arrays The fundamental data unit is the array. classified as either vectors or matrices. Naming –must begin with a letter –only first 63 characters are significant –make sure uniqueness –give your variables descriptive and easy to remember names –create a data dictionary –case sensitive 6

7 Initializing Variables var = expression; var = 40i; var2 = var/5; x=1; y=2; array = [1 2 3 4]; array2 = [1, 2, 3, 4]; array3 = [1 2 3; 4 5 6]; the number of elements in every row of an array must be the same, and so in every column. a = [0 1+7]; b = [a(2) 7 a]; 7

8 Initializing Variables with shortcut expressions –first:incr:last –x = 1:2:10 –y = 1:10 with built-in functions –a = zeros(2); –b = zeros(2, 3); –c = ones(3, 4); with Keyboard input –in1 = input(‘Enter data: ‘); –in2 = input(‘Enter data: ‘, ‘s’); 8

9 Multidimensional Arrays c(:,:,1) = [1 2 3; 4 5 6]; c(:,:,2) = [7 8 9; 10 11 12]; Storing arrays in memory –column major order Accessing multidimensional arrays with one dimension 9

10 Subarrays limiting the range of an array –a = [1 2 3; 4 5 6; 7 8 9]; –b = a(1:2, 1:2); end keyword –c = a(2:end, 2:end); a(1:2, 1:2) = 1; 10

11 Special Values pi i, j inf: division by zero nan: not a number zero divided by zero clock date eps ans 11

12 Displaying Output Data str = ‘ikjun yeom’; disp(str); Formatted output –fprintf() 12

13 Data Files save and load 13

14 Operations For Arithmetic operations –a +b, a – b, a * b, a / b, a^b Array and matrix operations –+, -,.*, *,./,.\, /, \.^ Precedence –parentheses –exponentials –multiplications and divisions –additions and subtractions 14

15 Common Functions abs(x), acos(x), angle(x), asin(x), atan(x), cos(x), exp(x), log(x), max(x), min(x), mod(x, y), sqrt(x), tan(x) ceil(x), fix(x), floor(x), round(x) char(x), double(x), int2str(x), num2str(x), str2num(x) 15

16 Plotting x = 0:10; y = x.^2 – 10.*x + 15; plot(x, y) title, xlabel, ylabel, grid, hold, legend, xrange, yrange, etc.. 16

17 Debugging Syntax error run-time error logical error 17


Download ppt "MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations."

Similar presentations


Ads by Google