GETTING STARTED WITH MATLAB/SIMULINK

Published on
Embed video
Share video
Ask about this video

Scene 1 (0s)

GETTING STARTED WITH MATLAB/SIMULINK. R.C. MALA MIT, Manipal.

Scene 2 (8s)

Introduction to MATLAB Matrix operations Script Files Function Files ODE solvers Plots Examples.

Scene 3 (19s)

INTRODUCTION TO MATLAB. July 22, 2013. Canara Engineering College.

Scene 4 (25s)

MATLAB - MATrix LABoratory Cleve Moler- University of New Mexico-late 1970 High level technical computing language Provides interactive environment for algorithm development, data visualization, data analysis and numeric computation.

Scene 5 (39s)

Mathematics Graphics & Visualization Programming Toolboxes On line help.

Scene 6 (47s)

Different type of files. July 22, 2013. Canara Engineering College.

Scene 7 (56s)

MATLAB screen. July 22, 2013. Canara Engineering College.

Scene 8 (1m 12s)

Elementary operations. Array : fundamental unit of data in MATLAB Vectors : Array with one dimension b= Matrix : Array with more than one dimension c =.

Scene 9 (1m 32s)

A region of memory containing an array, which is known by a user-specified name. Contents can be used or modified at any time. Variable names must begin with a letter, followed by any combination of letters, numbers and the underscore (_) character. Only the first 31 characters are significant. The MATLAB language is Case Sensitive. NAME, name and Name are all different variables. Never define a variable with the same name as a MATLAB function or command. type clear to clear the variables from the workspace.

Scene 10 (1m 53s)

Some commands which will help the user. who : lists variables in workspace.

Scene 11 (2m 11s)

Matrix operations. Array: use square brackets.. July 22, 2013.

Scene 12 (2m 24s)

Accessing a row, sub matrix and deletion. July 22, 2013.

Scene 13 (2m 39s)

+, -, *, / : basic numeric operators Ex: a+b, a-b a & b must be of same dimension a*b—columns of [a] must be equal to rows of [b] x=a/b gives the solution of xb=a; x=a*inv(b) \ : left division (matrix division) x=a\b gives the solution of ax=b; x=inv(a)*b ^ : raise to power ’ : complex conjugate transpose transpose (of matrix): non conjugate transpose det(of matrix): determinant fliplr(), flipud() : flip matrix about vertical and horizontal axes. .*, ./, .^ : Element by element operation.

Scene 14 (3m 1s)

[image] 2, .3 -2 0000 1. sooo 4] ; a—deC (a) 1 .0000 o. sooo.

Scene 15 (3m 14s)

Element by element operation , flipping of a matrix and concatenation of matrices.

Scene 16 (3m 28s)

Generating Vectors from functions: zeros(m,n)– creates a (mxn) matrix full of zeros, a=zeros(2,2) ones(m,n)– creates a (mxn) matrix full of ones, b= ones(3,4) eye(m)– creates an identity matrix, c=eye(3) rand(m,n)– creates a (mxn) random matrix, d=rand(5,5) Using colon operator:.

Scene 17 (3m 49s)

[image] size (a) max(a) max(an:). Size of an array.

Scene 18 (4m 10s)

Logical and relational operators. Logical and relational operators:.

Scene 19 (4m 23s)

Some Dummy Examples if ((a>3) & (b==5)) Some Matlab Commands; end if (a<3) Some Matlab Commands; elseif (b~=5) Some Matlab Commands; end if (a<3) Some Matlab Commands; else Some Matlab Commands; end.

Scene 20 (4m 40s)

Some Dummy Examples for i=1:100 Some Matlab Commands; end for j=1:3:200 Some Matlab Commands; end for m=13:-0.2:-21 Some Matlab Commands; end.

Scene 21 (4m 54s)

Dummy Example while ((a>3) & (b==5)) Some Matlab Commands; end.

Scene 22 (5m 4s)

Logical indexing: >> a=[1:10] a = 1 2 3 4 5 6 7 8 9 10 >> b=a>5 b = 0 0 0 0 0 1 1 1 1 1 >> c=a(b) c = 6 7 8 9 10.

Scene 23 (5m 17s)

Special values: pi:  value up to 15 significant digits i, j: sqrt(-1) Inf: infinity (such as division by 0) NaN: Not-a-Number (division of zero by zero) clock: current date and time in the form of a 6-element row vector containing the year, month, day, hour, minute, and second date: current date as a string such as 22-July-2013 eps: epsilon is the smallest difference between two numbers ans: stores the result of an expression.

Scene 24 (5m 41s)

Changing data format: >> value = 12.345678901234567; format short  12.3457 format long  12.34567890123457 format short e  1.2346e+001 format long e  1.234567890123457e+001 format short g  12.346 format long g  12.3456789012346 format rat  1000/81.

Scene 25 (5m 56s)

Displaying the output using fprintf %d integer %f floating point format %e exponential format %g either floating point or exponential format, whichever is shorter \n new line character \t tab character Ex: >> fprintf( 'Result is %d', 3 ) Result is 3 >> fprintf( 'x = %0.2f', pi ) x = 3.14 >> fprintf( 'x = %6.4f', pi ) x = 3.1416 >> fprintf( 'x = %d\ny = %d\n', 3, 13 ) x = 3 y = 13.

Scene 26 (6m 17s)

Hierarchy of operations: Processing order of operations is important parentheses (starting from the innermost) exponentials (from left to right) multiplications and divisions (from left to right) additions and subtractions (from left to right) >> x = 3 * 4 + 12 / 2 x = 18.

Scene 27 (6m 32s)

How is Script file created Main menu-File-New-m or script.

Scene 28 (6m 53s)

[image] Eile edit Tools Help script Col. Type your code here.

Scene 29 (7m 11s)

A complex program may be divided into several functions. These functions can improve readability of the code, as well as promote re-usability of the code. Each function must be saved into a different file, with the filename similar to the function. The format of a function is: function returnValue = fcnName(inputValue) Ex: Convert rectangular co-ordinates to polar using function file.

Scene 30 (7m 39s)

Ordinary Differential Equation solver Solves differential equations of the form y’=f(t,y) Types of solvers: ode23, ode45,ode113, ode15s, ode23tb etc Always begin with ode45 Format [t,y]=ode45(‘fname’, tspan, x0) where fname- function file name where differential equations are written tspan=[initial time final time] x0=initial state.

Scene 31 (7m 57s)

MATLAB can produce two dimensional x-y plots and three-dimensional plots, displaying images and even creating and playing movies. Options (2-D) plot, loglog, semilogx, semilogy, bar, hist, stem, polar, contour 3D plots plot3, contour3, surf, mesh, slice, view Graphic commands title, xlabel, ylabel, text, grid, axis, clf, ginput, gtext, hold Line types solid - dotted : dashed -- dashdot -. Point types point . plus + star * circle o cross x Color red r, green g, blue b, yellow y , magenta m, cyan c, white w, black k Multiple plots subplot(mnp) options : 221 211 121 .....

Scene 32 (8m 24s)

Ex1: plot f(t) = sin(t) for 0  t  10 clear; clc; clf; % To plot f(t) = sin(t) t = 0 : 0.01 : 10; y = sin(t); plot(t,y) To draw with green colour & star marker plot(t,y,’*g’).

Scene 33 (8m 39s)

Ex2: plot the circular helix x(t)=sin(t), y(t)=cos(t) and z(t)=t, 0 t  20. t=0:0.1:20; x=sin(t);y=cos(t);z=t plot3(t,x,y) Ex3: plot x1=sin(t) and x2=sin(3t) for 0 t  10 using 1) hold and 2) subplot >> t=0:0.1:10; >> x1=sin(t);x2=sin(3*t); >> plot(t,x1,'m');hold Current plot held >> plot(t,x2,'k').

Scene 34 (8m 58s)

>> t=0:0.1:10; >> x1=sin(t);x2=sin(3*t); >> subplot(121),plot(t,x1,'m'),grid; >> subplot(122),plot(t,x2,'g'),grid; Problem 1 Plot the function y=sin(x). /x for -4   x  4. x=-4*pi:0.1:4*pi; y=sin(x)./x; plot(x,y).

Scene 35 (9m 17s)

Problem 2 Generate a random matrix A of dimension 10x5. For each value inside the matrix, if its value is above 0.5, then change it to ‘1’. otherwise change it to ‘0’. Count the number of ‘1’s in the matrix and display the number. A=rand(10,5); B=A>o.5; C=sum(sum(B)) Problem 3 Plot the dc transient response of a series RL circuit with R = 1 , L = 1 H, and V=10 V. Switch is closed at t = 0. V=iR+Ldi/dt; di/dt=(V-iR)/L.

Scene 36 (9m 38s)

[image] Editor • C. ram Files\MA File Edit Tet Go cell -In + Tools Debug Desktop Wndow Help plot transient :egpcnge of a genes RL circuit global V R Z: ' ' 101,0); plot (t, i).

Scene 37 (9m 55s)

References. [1] Rudra Pratap, Getting started with MATLAB : A quick Introduction for Scientists and Engineers, OUP, 2009 [2] MATLAB User guide, Mathworks Inc.

Scene 38 (10m 7s)

THANK YOU Any Queries?. July 22, 2013. Canara Engineering College.