matlab

27
Engineering with MATLAB Department of Electrical Engineering HCET Aditi Tiwari

Transcript of matlab

Engineeringwith MATLAB

Department of Electrical EngineeringHCET

Aditi Tiwari

IntroductionTo MATLAB

What is MATLAB?MATrix LABoratory

Does Matrix OperationsThousands of inbuilt functionsToolBoxesGUIS

A programming LanguageA complete software packageSimulink Modeling toolsEDA tools

LAYOUT

A Simple Start:Add two VariablesNo definitions needed, no classes neededOn command window type:

Type C to see the valueC=9

>>A=5;>>B=4;>>C=A+B;

Editors:Editors are used to store codes Code is nothing but just a set of linesM Files are used in MATLAB having

extension .mTypes:

Script File Set of code lines

Function File A code implementing some functions like sin, cos

exp (they are inbuilt)

Defining Matrices:Just write all the entries separated by the

space or comma and enclosed in a bracket []A=[1 2 3 2] OrA=[1,2,3,2]For column matrix, put semicolon ; in

betweenA=[1;2;3;2]

Importance of Matrix: Not just as a transformation

Also set of data or samplesElectrical SignalsPerformance outputsImages

Also as model representationPolynomialsTransfer functionsNeural Networks

Polynomials:

These are some of thePolynomials you haveCome across.

Polynomials in MATLABA polynomial can be represented in the form

of coefficients. For example, if you want to write

You have to just write [1 2 2 5]Each number represents the value of

coefficients.

This will be represented as [1 0 2 5]

System Modeling using Matrix:Recall the well known example of LCR

circuit:

Output across resistor V0=R.iModeled using matrix as

INPUT

OUTPUT

Similarly a Motor SystemA Motor Speed System

We write its state equations:

Transfer Functions

Polynomials[K2][1 2 K2]

Neural SystemsSystems modeled as a set of transformation

with neurons as Weight matrixes

Problems with Other ProgrammingLanguagesNo Matrix operationsFor Loops everywhereLots of unnecessary lines

Matrixswith MALTAB

Define MatrixsMix , and ; to make 2 D matrix

A=[1 2 3 2; 1 3 2 1;2 3 6 1]Make A 1 to 10 Matrix

A=[1 2 3 4 5 6 7 8 9 10];Make 1 to 100

Tired??Use colon :Which mean “TO”

A=[1:100];

Colon (:) = TO[1:4]

Gives a vector from 1 to 41 2 3 4

[1:0.5:4]Gives a vector from 1 to 4 with step 0.5

1 1.5 2 2.5 3 3.5 4

[0:0.1:2*pi]Gives a vector containing 0 to 2π

OperatorsMatrix Operators

Y=A^2Y=A^B

X=A*BDot Operators

Y=A.^2X=A.*BY=A.^B

More with MatrixsFunctionsSubscripting

Typical MATLAB functionsMathematical

sqrtsin,cos,tanLog, exp

CreationoneszeroseyeRand

Informationsizelength

Typical MATLAB functionsMatrix Operations

sumdiagtranspose or ‘invdeteigfliplrreshapeflipudrot90repmat

Concatenation of MatricesSuppose A, B, C are matricesIf we write [A B] or [A,B]If we write [A;B]Similarly [A B C] and [A;B;C][[A B];C]

Crete a with size 4x5 With elements from 3to7\

uGP

Arn-1

N=[1:20]

Y=2*(1/2).^(N-1)