© All Rights Reserved

15 views

© All Rights Reserved

- Ts88 05 Kapovic Etal 0595 Slican Primer
- Mathcad Primer
- MICROCONTROLADORES MATLAB
- Image Object Segmentation
- 1
- Lecture Notes
- Levy et al 2005
- Appendix a MatlabTutorial
- Programming Patterns Some Common MATLAB Programming Pitfalls and How to Avoid Them
- Course Outline
- Wafo Tutorial 2017
- Version 3.3 _(R2011a_) EDA Simulator Link __ EDA Simulator Link Release Notes _(EDA Simulator Link™_)
- Quick-R: Data Types
- Talk_6-3-3_CST_EUC_2012
- 37-06
- Matlab_Tutorial1
- Final Project
- Manipulating Multidimensional Arrays - MATLAB & Simulink Example - MathWorks India
- 37
- LAB 1

You are on page 1of 64

matrices

operators

script and function files

flow control

plotting

Basic MATLAB

optional windows

workspace

current directory

command window

and Matlab returns a list of help topics

>> help for

MATLAB Variables

no distinction between real and integer

>>a = 3;

>>a = 3.0;

Matlab is case sensitive

>>A=3;

>>a=2;

Aa

MATLAB Variables

can use numbers and underscore in variable names

>>case34=6.45;

OK

>>case_34=6.45;

names must start with a letter

>>34case=23.45;

The variable is stored as array of characters

>>title=This is the title;

MATLAB Variables

if a variable is defined,

typing the variable name returns its value

>>a=45.57;

>>a

a=

45.57

>>a=4

>>clear a

MATLAB Variables

Matlab will echo commands unless a semi-colon is used

>>a=23.2;

>>

>>a=23.2

a=

23.2

>>

MATLAB Variables

Vectors

column vectors

1

a 2

3

>>a=[1;2;3];

>>a

a=

1

2

3

use semi-colon

to separate rows

row vectors

a 1 2 3

>>a=[1,2,3];

>>a

a=

1 2 3

use comma

to separate columns

MATLAB Variables

Matrices

2-dimensional matrices

1 2 3

a

4

5

6

>>a=[1,2,3;4,5,6];

>>a

a=

1 2 3

4 5 6

MATLAB Variables

Indexing Matrix elements

A vector is a special type of matrix

row vector is a 1 x n matrix, 1 row n columns

column vector is a n x 1 matrix, n rows 1 column

>>a=[1,2,3];

>>a(2)

ans =

2

note, a(2,1) would produce an error

because a only has one row

MATLAB Variables

Indexing Matrix elements

more examples

1 2 3

a

4

5

6

addressing

>>a(2,3)

ans =

6

>>a=[1,2,3;4,5,6];

assigning

>>a(2,2)=9;

>>a

a=

1 2 3

4 9 6

MATLAB Variables

complex-valued numbers

Typically, the variable i or j is used to represent the

complex variable; e.g.

i 1

z = a + ib

Re(z) = a

Im(z) = b

MATLAB Variables

complex-valued numbers

Unless i or j has been previously defined, Matlab assigns

i and j the complex variable value

In Matlab, a complex variable is represented in the

following format

(assuming all variables are cleared)

>>z=23+i*56;

>>z

z=

23.00 + 56.00i

>>z=23+j*56;

>>z

z=

23.00 + 56.00i

MATLAB Variables

complex-valued numbers

>>i=3;

>> z=23+i*56;

>>z

z=

>>a=sqrt(-1);

>>z=23+a*56;

>>z

z=

MATLAB Variables

complex-valued numbers

Note, a real-valued number is a special case of a

complex-valued number

assigning any element of a matrix as complex-valued

makes the entire matrix complex-valued

>>a=[1,2];

>>a

a=

1 2

>>a(1)=1+i*5;

>>a

a=

1.00+5.00i

2.00+0.00i

MATLAB Variables

Advanced data types

n-dimensional arrays

structures

cell arrays

MATLAB Operations

Basic operations

addition

subtraction

multiplication

division

right division

left division

>>a=3;b=4;

>>c1=a/b;

>>c2=a\b;

+

*

/

\

c1=0.75

c2=1.3333.

MATLAB Operations

Mixed Real and Complex valued Variables

if both variables are real-valued, a real-valued result is obtained

if one variable is complex-valued, Matlab recasts the real

variable as complex and then performs the operation. The

result is complex-valued

however, the type casting is done internally, the real-valued

variable remains real after the operation

MATLAB Operations

Other (Scalar) Operations

Math representation

z yx

Matlab interpretation

>>z=y^x;

y ex

>>y=exp(x);

y ln(x)

>>y=log(x);

y log(x)

>>y=log10(x)

>>y=sin(x);

>>y=asin(x);

>>y=cos(x);

>>y=acos(x);

>>y=tan(x);

>>y=atan(x);

MATLAB Operations

Examples

y x

>>y=x^0.5;

>>y=x^(1/2);

>>y=sqrt(x);

real or complex, negative or positive

for x < 0, y is complex. Matlab assumes you allow complex

valued numbers. If y is not to be complex, you must

provide error checking.

MATLAB Operations

Matrices

Only matrices of the same dimension can be added and subtracted

For multiplication, the inner dimensions must be the same

1 2 3

A

4

5

6

2 3 4

B

5

6

7

Error

No error

>>D=A+B;

>>D=AB;

>>D=A*C;

>>D=C*A;

4 5

C 6 7

8 9

Matrix multiplication

not commutative

>>D=A+C;

>>D=A*B;

>>D=B*A;

MATLAB Operations

Left(\) and Right(/) Matrix division

Math representation

Matlab interpretation

C A 1B

>>C=A\B;

C BA 1

>>C=B/A;

(linearly independent rows/columns)

MATLAB Operations

Matrix Transpose

Math representation

C AT

Matlab interpretation

>>C=A;

1 2 3

A

4

5

6

a 1 j2 3 j4

>>B=A;

>>b=a;

1 4

B 2 5

3 6

1 j2

b

j4

MATLAB m-files

Two types of m-files

script files

collection of commands that Matlab executes

when the script is run

function files

collection of commands which together

represent a function, a procedure or a method

MATLAB m-files

To create an m-file, open the Matlab text editor

MATLAB m-files

Script Files

On the command line

>>x=3.0;

>>y=x^2;

>>y

y=

9.0

>>

On the command line

>>test

y=

9.0

>>

MATLAB m-files

Script Files

script files share the workspace memory

>>x=5.0;

>>test

>>y

y=

25.0

>>

test.m script

MATLAB m-files

Script Files

script files can call other script files

inner.m script

>>outter

y=

36.0

>>

outter.m script

MATLAB m-files

Function Files

Matlab identifies function files from script files by

using the function and return keywords

the same name as the function

MATLAB m-files

Function Files

The function file x2.m

>>r=3;

>>d=x2(r);

>>d

d=

9.0

>>

>>h=x2(4.2);

>>h

h=

17.64

>>

MATLAB m-files

Function Files

Multiple Inputs and Outputs

inputs in parentheses ( )

MATLAB m-files

Function Files

variables created in the function are not retained

in the workspace, except for the output variables

variables, except for the inputs

workspace variables. Changing their value inside the

function has no effect on their value in the workspace.

The while and if statements

while expression

statements

end

if expression

statements

end

if expression

statements1

else

statements2

end

false equivalent to zero

true equivalent to any non-zero number

statements, any valid Matlab command

evaluating expression

any valid equation

a=4;

b=5;

c=5;

ifa+b True

ifbc False

watch out for round-off

and word length error

ifsin(0) False

ifsin(pi) True

sin(pi)=1.22e16

conditional operators

==equal to

<less than

>greater than

<=less than or equal to

>=greater than or equal to

~=not equal to

logical operators

&and

|or

while(3<=a)&(a<=5)

The for statement

for index = start : [increment :] end

statements

end

index, start, increment, and end do not need to be integer valued

increment is optional, if increment is not specified

increment defaults to 1

index can be incremented positive (increment > 0) or

negative (increment < 0)

loop stops when index > end (or index < end)

example

MATLAB Plotting

Basic 2D plotting functions

plot(x1,y1[,x2,y2,x3,y3.....])

xlabel(xaxisname)

ylabel(yaxisname)

title(graphname)

Additional functions

gridon

gridoff

axis([xmin,xmax,ymin,ymax])

MATLAB Plotting

example y = sin(t)

MATLAB Plotting

example y = sin(t)

a graph of y = sin(t)

MATLAB Plotting

example y = sin(t)

a graph of y = sin(t)

>>graphsin

>>

MATLAB Plotting

Adding a Legend for multiple graphs

legend remembers

the order the graphs

were plotted

List of Experiments

MATLAB Programming:

1. Basic programs

---- Average of the 10 numbers

---- Finding the roots of a given Equation

---- Generation of cosine and square wave

2. Formation of Bus admittance matrix for a given bus data.

---- With Shunt Admittances

---- With Tap changing Transformer between the buses

3. Find the Bus voltages of a given bus data using Gauss-siedel method.

4. Find the Bus voltages of a given bus data using Newton- Raphson method

Introduction

to

MATLAB SIMULINK

setting integration properties

setting initial conditions

input types

getting data to the workspace

Simulink Basics

Simulink Basics

open an existing one

Simulink Example

Best thing to do is to go through an example

&

y& c1y& c0 y b0f (t)

Simulink Example

Get an equivalent block diagram for the system

use mouse to drag blocks into

the model window and to

connect blocks with arrows

Simulink Example

Simulink Example

add the step input block

Simulink Example

Simulink Example

Now, double click the blocks to open and set the blocks parameters

set gain value

set output format to array

Simulink Example

To set the simulation parameters.

set numerical integration type

Simulink Example

Time to run the simulation

click the run button to begin the simulation

Simulink Example

the workspace.

This variable contains the time values used in the simulation,

important for variable time integration types

Simulink also will create the output variable(s) you specified

Simulink Example

>>plot(tout,yoft)

graph of the step response

Simulink Example

Another approach to solving the 2nd order single DOF

problem, is to cast it as a 1st order 2 DOF problem

x1 y

x 2 y&

x&1 x 2

x&2 bo f c1x 2 co x1

y Cx

x1

x

x 2

0

A

c o

uf

C 1 0

1

c1

0

B

bo

Simulink Example

1st Order State-Space Models

Simulink Example

Multi Input Multi Output Systems

use Mux and Demux blocks to combine and extract vector signals

Objective: To study the operation.

Software used:

Circuit Diagram/ Program *:

Theory***:

Procedure:

Model Calculations:

Model Graphs **:

Report:

Conclusion:

(* for the programming -- Flowchart, Algorithm, has to be written)

(** graphs have to drawn in the graph sheets for executing the problem)

(***included while writing the record only)

List of Experiments

MATLAB Simulink:

1.Design a Half wave rectifier with Resistive load using Diodes and Thyristors

2. Design a Full wave rectifier with Resistive load using Diodes and Thyristors

3. Conduct an Open Circuit and Short circuit test on a Single phase Transformer

4. Build a Single phase and Three phase Transmission line (Pi line).

- Ts88 05 Kapovic Etal 0595 Slican PrimerUploaded byGoran Buncic Buki
- Mathcad PrimerUploaded byajroc
- MICROCONTROLADORES MATLABUploaded byEIEE
- Image Object SegmentationUploaded byPuneet Sharma
- 1Uploaded byPratyushAgarwal
- Lecture NotesUploaded byBittu
- Levy et al 2005Uploaded bybaruaeee
- Appendix a MatlabTutorialUploaded byNick Johnson
- Programming Patterns Some Common MATLAB Programming Pitfalls and How to Avoid ThemUploaded byAnoop Karnik
- Course OutlineUploaded byABrighterYellow
- Wafo Tutorial 2017Uploaded byMarc
- Version 3.3 _(R2011a_) EDA Simulator Link __ EDA Simulator Link Release Notes _(EDA Simulator Link™_)Uploaded bymynameisbill
- Quick-R: Data TypesUploaded byChungil Chae
- Talk_6-3-3_CST_EUC_2012Uploaded byMohammad Mousavik
- 37-06Uploaded bykodandaram
- Matlab_Tutorial1Uploaded bySam
- Final ProjectUploaded byPravat Satpathy
- Manipulating Multidimensional Arrays - MATLAB & Simulink Example - MathWorks IndiaUploaded byAnonymous lGK9Y6
- 37Uploaded bysanchit
- LAB 1Uploaded byShabbir Memon
- UntitledUploaded bygokulmtla
- LECTURE 2 CHE210 computer lab (Week 2).pdfUploaded byshodmon
- 02_GENN004m_ArithmeticOperationsUploaded byBishoy Emile
- Lab Report 07Uploaded byMuhammad Shayan
- Matlab LessonUploaded byAvisha N Avisena
- Freq Plan StepsUploaded byIvan Kokorin
- IJNME Eigenvalues RevUploaded byAdenilson Swokowski
- FundEngiMaths_Stud2016_1Uploaded byTuổi Thơ Bị Bắt
- dsp lab 04Uploaded byUsama Javed
- 10.1.1.117Uploaded byporkpiehat

- 188892789 Introduction to Digital Control Systems Lecture NotesUploaded byEric Kerr
- 16f877a pic controller.docUploaded byyuvakirani
- 89c51 MCU.docUploaded byyuvakirani
- 433 mhz rf remote control.docxUploaded byyuvakirani
- 8085 MicroprocessorUploaded byauromaaroot1
- 89s8252 MCU.docUploaded byyuvakirani
- 74LS244 latch.docUploaded byyuvakirani
- 555.docxUploaded byyuvakirani
- m1_lec2Uploaded byMudit Pharasi
- MATHEMATICAL MODELLING OF SAMPLING PROCESSUploaded byNishant Saxena
- zero and first order holdUploaded bynirmal_inbox
- Dcs Unit 4 notesUploaded byyuvakirani
- Simulation Lab PPT.pptUploaded byyuvakirani
- Engish Latin Roots listUploaded byyuvakirani
- DCS_Course_outline_C_.docxUploaded byyuvakirani
- Steam TurbineUploaded byyuvakirani
- 2Data Structures and Program MethodologyUploaded byyuvakirani
- Board Wise Numbers JEE Adv 2015 18-6-15Uploaded byyuvakirani
- AbhyudayaTecSchoolUploaded byyuvakirani
- APEAMCET2015 Instructions to Candidates 3Uploaded byyuvakirani
- Autonomous Exam ScheduleUploaded byyuvakirani
- Electrical+Machines+By+U.A.Bakshi-+M.V.Bakshi+1+and+2+chaptersUploaded bykrishna_teja_1
- Capital PunishmentUploaded byyuvakirani
- ems measurementsUploaded byyuvakirani

- Derivatives and Risk ManagementUploaded byabhishekrameshnag
- CONFVAL_UserGuideUploaded byzainul19261
- pr125_sl Epson Perfection Scanner 1250Uploaded bySvetlin Ranguelov
- EBS Integration Pre-requisitesv1.1Uploaded byprakash9565
- 1Uploaded bySharib Ahmad
- Third_Experience.pdfUploaded byTudor Serbanescu
- Data Acquisition IntroductionUploaded byRafael Flores
- DLD_EXP_6_STUDENT_MANUAL.pdfUploaded byS M Akash
- Calculating Poker Probabilities With a Simple Excel Spreadsheet _ Poker SavvyUploaded bylysakowski
- An Optimized Dna Extraction Protocol for Isolation of High Quality Genomic Dna From Camphor Containing Timber Tree Species Dryobalanops Beccarii DyerUploaded byIJSTR Research Publication
- Project SegmentationUploaded bycrispinsean
- Antennas and Propagation for Wireless Systems.pdfUploaded byJorge Marcillo
- ChE 121 Course Details_ UWaterlooUploaded byjsaeed786
- TEXT AND AUDIO DATA HIDING USING LSB AND DCT A REVIEW APPROACHUploaded byIJIERT-International Journal of Innovations in Engineering Research and Technology
- Lesson Guides Book 4 v0.2Uploaded byMelinda Rafael
- GavrilaUploaded byTaha
- Compa Cio Man 411Uploaded bykeinin87
- Protocol FISH InvitrogenUploaded byantonior
- Simocode TermsUploaded byArunava Basak
- TDPUploaded byFlorin Nite
- lec7Uploaded byAnonymous 8f2veZf
- Attachment 2 Landmark Drilling Apps DATASHEETUploaded byGilles Gitta
- Glass Acoustic Information USUploaded bySanjin Mehmedika
- Cross Shaft Design From the Aspect of CapacityUploaded byBlaza Stojanovic
- LF21N451 Spec SheetUploaded byDj Costy
- Aco AISI 1020.pdfUploaded byIbsonh
- DocUploaded byDulika Rukshan
- Mesin Mri Id-16-00108 0 Rsudkotasemarang 160803 Id879Uploaded bypoladwipa
- AutoGroundDesignUploaded byScott Newton
- Yale-YJLHook---YJC680.pdfUploaded byscofiel1