Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation.

Similar presentations


Presentation on theme: "Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation."— Presentation transcript:

1 Prof. N. P. Jadhav Presented by

2 Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation and visualization. What is MATLAB ? Provides interactive environment with hundreds of built in functions for technical computations, graphics, animations. Built in functions which provide excellent tools for linear algebra, data analysis, signal processing, optimization, ODE systems, control systems and many more…

3 Use of MATLAB includes – Math and computation Algorithm development Data acquisition Modeling, simulation and prototyping Data analysis, exploration and visualization Scientific and engineering graphics Application development, including graphical user interface building

4 Getting Started Starting of MATLAB UIW Method 1 Start > All Programs > MATLAB > MATLAB (icon) Method 2 Desktop > MATLAB icon

5 Getting Started Click on the MATLAB icon on your PC desktop

6 Getting Started A = [ 16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1 ] Note 1: Separate the elements of row with blanks or commas. Note 2: Use semicolon (;) to indicate the end of each row. Note 3: Surround the entire list of elements with square brackets, [ ] Hit enter, to display the result as follows, A = 16 3213 510118 96712 415141 Matrix : A = [ 16,3,2,13; 5,10,11,8; 9,6,7,12; 4,15,14,1 ] OR

7 Getting Started Magic square of matrix : Commands : sum, transpose, diagonal of matrix sum(A) …………. hit enter for result A` …………. hit enter for result sum(A` )` …………. hit enter for result diag(A) …………. hit enter for result sum(diag(A)) …………. hit enter for result sum(diag(fliplr(A))) …………. hit enter for result this will flips a matrix from left to right.

8 Magic square of matrix : Commands : subscripts of matrix Element of row i & column j of A is denoted by A(i, j) Getting Started A ( i, j ) number in i rownumber in j column represent a row represent a column

9 Magic square of matrix : Commands : subscripts of matrix Getting Started e.g. A(1,4) means, a number in a matrix which is exactly at 1 st row and 4 th column. A = 16 3213 510118 96712 415141

10 Magic square of matrix : Commands : subscripts of matrix Getting Started e.g. A(1,4) + A(2,4) + A(3,4) + A(4,4) A = 16 3213 510118 96712 415141

11 Swapping columns in Matrix : Getting Started observee.g. Type : B = magic(4) Type : A = B (:, [1 3 2 4] ) A = B (:, [1 3 2 4] ) compute the result 1 st column remains as it is 3 rd column becomes 2 nd 2 nd column becomes 3 rd 4 th column remains as it is

12 Colon Operator : integer Getting Started e.g. 1 : 10 Row vector containing integers from 1 to 10, having increment of 1 i.e. unit spacing. result - 1 2 3 4 5 6 7 8 9 10 decremente.g. 100 : -7 : 50 Obtain non unit spacing, with decrement of -7. result - 100 93 86 79 72 65 58 51

13 Colon Operator : Getting Started incremente.g. -5 : 0.05 : 5 Obtain non unit spacing, with increment of 0.05. incrementllly 0 : pi/4 : pi Obtain non unit spacing, with increment of pi/4. result - 0 0.7854 1.5708 2.3562 3.1416

14 Operators : Getting Started expressions + Addition - Subtraction * Multiplication / Division \ Left division (described in “Linear Algebra” in the MATLAB documentation) ^ Power ' Complex conjugate transpose ( ) Specify evaluation order

15 Arrays : Getting Started operators + Addition - Subtraction.* Element-by-element multiplication./ Element-by-element division.\ Element-by-element left division.^ Element-by-element power.' Unconjugated array transpose

16 Matrix : Getting Started Unit Multiplication e.g. a = [1 2 3; 4 5 6] b = [4 5 6; 7 8 9] Observe this: a*b …… results “Error” a.*b …… done the unit multiplication c = [1 2 3] c = c’ ………….. (transpose of matrix) Observe this: a*c b*c

17 Format function : Getting Started The format function controls the numeric format of the values displayed. e.g. x = [ 4/3 1.2345e – 6 ] Type & Observe – format short format short e format short g format long format long e format long g format bank format rat format hex format compact

18 Command Line Editing : Getting Started KeyControl Key for MATLAB Standard Operation Up arrowCtrl + P Recall previous line. Works only at command line if you previously used the up arrow or Ctrl + P. Down arrowCtrl + NRecall next line. Works only at the prompt if you Left arrowCtrl + BMove back one character. Right arrowCtrl + FMove forward one character. Ctrl + Right arrow None Move right one word. Ctrl + Left arrow None Move left one word.

19 Command Line Editing : Getting Started KeyControl Key for MATLAB Standard Operation HomeCtrl + AMove to beginning of current statement. EndCtrl + EMove to end of current statement. NoneCtrl + HomeMove to top of Command Window. NoneCtrl + EndMove to end of Command Window. EscCtrl + UClear command line when cursor is at the prompt. Otherwise, move cursor to the prompt.

20 Command Line Editing : Getting Started KeyControl Key for MATLAB Standard Operation DeleteCtrl + DDelete character after cursor. BackspaceCtrl + HDelete character before cursor. NoneCtrl + KCut contents (kill) to end of command line. NoneShift + HomeSelect from cursor to beginning of statement. NoneShift + EndSelect from cursor to end of statement.

21 Command Line Editing : Getting Started KeyControl Key for MATLAB Standard Operation NoneCtrl + C or Ctrl + Break Stop execution of whatever is currently running, if feasible.

22 Practice : Getting Started Calculate and Observe : 1. 1 + 2 x 3 …………….(i) 1+2*3………..…..(ii) (1+2)*3 2. ……. ….1/2 + 3^2 + 4/5 * 6/7.……… 1/(2+3^2) + 4/5 * 6/7 Parentheses :

23 Practice : Getting Started

24 Practice : Getting Started

25 Basic 2D plot Getting Started Graphics Basic command for 2D plot plot ( xvalues, yvalues, ‘style option’ )

26 Basic 2D plot Getting Started Graphics Practice : %2D plot demo x = - 5 : 0.05 : 5; y = x.*cos (x.^2).*exp ( - x); plot (x, y) axis ( [ -5, 0, -600, 600 ] ) xlabel (‘X variable’); ylabel (‘function value y’); title (‘plot of y vs x’) legend ( ‘y-variation’ );

27 Basic 2D plot Getting Started Graphics Practice : %2D plot demo t=0:pi/20:2*pi; y=exp(sin(t)); plot (t, y) xlabel (‘X Axis’); ylabel (‘Plot Y Axis’); title (‘One y Axis’) %2D plot demo t=0:pi/20:2*pi; y=exp(sin(t)); plotyy (t,y,t,y, ‘plot’, ‘stem’) xlabel (‘X Axis’); ylabel (‘Plot Y Axis’); title (‘Two y Axis’) Type 1: Type 2:

28 Basic 2D plot Getting Started Graphics Practice : %2D plot demo x = 0 : pi/100 : 2*pi; y = sin (x); plot (x, y) xlabel (‘x = 0:2 \ pi’) ylabel (‘Sine of x’) title (‘Plot of Sine Function’, ‘FontSize’, 12)

29 Basic 2D plot Getting Started Graphics Practice : Multiple Data Sets in One Graph %2D plot demo x = 0 : pi/100 : 2*pi; y = sin (x); y2 = sin (x -.25); y3 = sin (x -.5); plot (x, y, x, y2, x, y3) legend (‘sin(x)’, ‘sin(x -.25)’, ‘sin(x -.5)’) xlabel (‘x = 0:2 \ pi’) ylabel (‘Sine of x’) title (‘Plot of Sine Function’, ‘FontSize’, 12)

30 Basic 2D plot Getting Started Graphics Practice : Specifying Line Style and Color in Graph %2D plot demo x = linspace (0,2*pi,100); figure (1) plot ( x, sin (x) ) xlabel (‘x’), ylabel (‘sin (x)’) title (‘Sine Plot’) grid on Contd…..

31 Basic 2D plot Getting Started Graphics Practice : Specifying Line Style and Color in Graph It is possible to specify color, line style and markers (such as plus sign or circle) when you plot your data using the plot command: plot ( x, y, ‘color_style_marker’) color_style_marker is a string containing from one to four characters (enclosed in a single quotation marks) constructed from a color, a line style and a marker type. The strings are composed of combinations of the following elements :

32 Basic 2D plot Getting Started Graphics Practice : Specifying Line and Marker Colors in Graph TypeValuesMeanings Color'c' 'm' 'y' 'r' 'g' 'b' 'w' 'k' cyan magenta yellow red green blue white black

33 Basic 2D plot Getting Started Graphics Practice : Specifying Line Styles in Graph Line style'-' '--' ':' '.-' no character solid dashed dotted dash-dot no line TypeValuesMeanings

34 Basic 2D plot Getting Started Graphics Practice : Specifying Marker types in Graph TypeValuesMeanings Marker type'+' 'o' '*' 'x' 's' 'd' '^' 'v' '>' '<' 'p' 'h' no character or none plus mark unfilled circle asterisk letter x filled square filled diamond filled upward triangle filled downward triangle filled right-pointing triangle filled left-pointing triangle filled pentagram filled hexagram no marker

35 Basic 2D plot Getting Started Graphics Practice : Specifying Line Style and Color in Graph Contd….. plot ( x, sin (x), ‘ks’) plot ( x, sin (x), ‘r’ ) plot ( x, sin (x), ‘r:+’) In above problem type this commands and observe :

36 Basic 2D plot Getting Started Graphics Adding plots in an Existing Graph The MATLAB hold command enables you to add plot to an existing graph, when you type : hold on Now MATLAB does not replace the existing graph when you issue another plotting command; it adds the new data to the current graph, rescaling the axis if necessary.

37 Basic 2D plot Getting Started Graphics Adding plots in an Existing Graph E.g. These statements first create a counter plot of the peaks function, then superimpose a pseudo color plot of the same function. [ x, y, z ] = peaks; pcolor ( x, y, z ) shading interp hold on contour ( x, y, z, 20, ‘k’ ) hold off The hold on command combines the pcolor plot with the counter plot in one figure.

38

39

40

41


Download ppt "Prof. N. P. Jadhav Presented by. Overview of MATLAB environment MATLAB is an interactive, matrix-based system for scientific and engineering numeric computation."

Similar presentations


Ads by Google