• No results found

MATLAB includes hundreds of functions for:

N/A
N/A
Protected

Academic year: 2022

Share "MATLAB includes hundreds of functions for: "

Copied!
41
0
0

Loading.... (view fulltext now)

Full text

(1)

MATLAB FOR ENGINEERS CREDITS: 4

UNIT#1 LECTURE#1

(2)

Unit I Basics: MATLAB environment, Variables, Basic data types, Relational and Logic operators, Conditional statements, Input and Output, Loops and branching.

Unit II Matrices: Creating and Manipulating matrices, Matrix maths and Matrix functions, Colon operator, Linspace, Cross product, Dot product, Logical

functions, Logical indexing, 3-dimensional arrays, Cell arrays, Structures, Plotting:

2-D and 3-D plots: Basic plots, subplots, Histograms, Bar graphs, Pie charts.

Unit III M-file scripts: Creating, saving and running an M-file, Creating and running of a function, Function definition line, H1 and help text lines, Function body, Sub- functions, Nested functions, File I/O handling, M-file debugging.

Unit – IV Simulink: Introduction, Block diagram, Functions, Creating and working with models, Defining and managing signals, Running a simulation, analyzing the results.

Unit V Applications: Root finding, Data analysis, Statistical functions, Polynomials, Curve fitting, Interpolation, Ordinary differential equations, Integration and

differentiation, Signal processing applications, Circuit analysis applications, Control system applications.

(3)

*D Hanselman and B Littlefield

Mastering Matlab 7, Pearson Education.

A Gilat Matlab: An Introduction with Applications, John Wiley and Sons, 2004.

Y Kirani Singh and B B Chaudhari

Matlab Programming, Prentice Hall of India, 2007

*Steven T Karris Introduction to Simulink with Engineering Applications, 2nd edition, Orchard Publication, 2008

(4)

MATLAB is too broad for our purposes in this course.

The features we are going to require is

MATLAB

Programming Basic

Operations SIMULINK

Mathematical, Logical, Relational Operations on various data types,

Various Plots, operation on matrix

Sim Power System

(5)

1. Basic Mathematics equivalent to senior secondary level.

2. Basic programming skills

3. Basic Electrical Engineering.

4. And that’s all what is required to start with EEE -278.

(6)

MATLAB is a software package for doing numerical

computation. It was originally designed for solving linear algebra type problems using matrices. It’s name is derived from MATrix LABoratory

MATLAB has since been expanded and now has built-in

functions for solving problems requiring data analysis, signal processing, optimization, and several other types of scientific computations. It also contains functions for 2-D and 3-D

graphics and animation.

(7)

MATLAB includes hundreds of functions for:

Data analysis and visualization,

Numeric and symbolic computation, Engineering and Scientific graphics,

Modeling, simulation, and prototyping,

Eigenvalue, singular value

(8)

By Default we have three windows opening up during launch

1. Command Window 2. Workspace

3. Command History

In addition to above we have other windows also like Figure window

Editor window

Current directory window

(9)

MATLAB Command

Window

(10)

File

(11)

Edit

(12)

View

(13)

View

(14)

View

(15)

Web

(16)

Help

(17)
(18)

Pressing the up arrow in the command window will bring up the last command entered

This saves you time when things go wrong

If you want to bring up a command from some time in the past type the first letter and press the up arrow.

The current working directory should be set to a directory of your own

18

(19)

Every programming language has its specific ways of recognizing data types for data handling.

MATLAB has following Data Types Scalars

Characters Arrays

Strings

Cell-arrays Structures

(20)

Any Number which can represent a quantity or measure is known as scalar

Includes integers, complex numbers, floating point numbers

Example

4, 3+5i, -23.45 etc

(21)

Any single alphanumeric symbol enclosed in a single quote is a character constant.

Example

‘2’, ‘e’, ‘A’ etc

5 and ‘5’ are different data

(22)

Any two or more alphanumeric symbols enclosed in a single quote is a string data.

A String is an array of character.

Example

‘IBEMA’, ‘7743789’ etc.

‘IBEMA’==[‘I’, ’B’, ‘E’, ‘M’, ‘A’]

(23)

A MATLAB matrix is a rectangular array of numbers Scalars and vectors are regarded as special cases of matrices

MATLAB allows you to work with a whole array at

a time

(24)

You can create matrices (arrays) of any size using a combination of the methods for creating vectors

List the numbers using ‘,’ to separate each column and then ‘;’ to define a new row

24

(25)

You can also use built in functions to create a matrix

>> A = zeros(2, 4)

creates a matrix called A with 2 rows and 4 columns containing the value 0

>> A = zeros(5) or >> A = zeros(5, 5)

creates a matrix called A with 5 rows and 5 columns

You can also use:

>> ones(rows, columns)

>> rand(rows, columns)

Note: MATLAB always refers to the first value as the number of Rows then the second as the number of Columns

25

(26)

The matrix indices begin from 1 (not 0 (as in C)) The matrix indices must be positive integer

Given:

A(-2), A(0)

Error: ??? Subscript indices must either be real positive integers or logicals.

A(4,2)

Error: ??? Index exceeds matrix dimensions.

(27)

A vector is a list of numbers

Use square brackets [] to contain the numbers

To create a row vector use ‘,’ to separate the content

27

(28)

To create a column vector use ‘;’ to separate the content

28

(29)

A row vector can be converted into a column vector by using the transpose operator ‘

29

(30)

Create vector with equally spaced intervals

>> x=0:0.5:pi x =

0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000

Create vector with n equally spaced intervals

>> x=linspace(0, pi, 7) x =

0 0.5236 1.0472 1.5708 2.0944 2.6180 3.1416

Equal spaced intervals in logarithm space

>> x=logspace(1,2,7) x =

10.0000 14.6780 21.5443 … 68.1292 100.0000

Note: MATLAB uses pi to represent , uses i or j to represent imaginary unit

(31)

A cell-array is a special type of array, where the elements can be of different data types.

They are distinguished from the simple arrays by using braces, instead of square brackets for enclosing the

elements.

Example

{‘AHMED’, 34, ‘RING ROAD’}

A Cell array can contain other cell-arrays

(32)

A Structure is also a different data type to store various related data types using meaningful field names.

They are written in name-value combination using the word struct.

Example

Struct(‘field1’, data1, ‘field2’, data2, ‘field3’, data3)

(33)

Handling data directly in computation is inconvienient for varoius reasons so data are assigned names called variables

Variables Names

1.Can be any string of upper and lower case letters along with numbers and underscores but it must begin with a letter

2.Should not be keywords or program name as IF, WHILE, ELSE, END, SUM, etc.

3.Names are case sensitive

Value

This is the data that is associated to the variable;

The data is accessed by using the name.

Variables have the type of the last thing assigned to them

Re-assignment is done silently – there are no warnings if you overwrite a variable with something of a different type.

33

(34)

Valid

Mean3, avg1, first_value etc Invalid

1stvalue, second-value, dec.hex etc

(35)

No need for types. i.e.,

All variables are created with double precision unless specified and they are matrices.

After these statements, the variables are 1x1 matrices with double precision

int a;

double b;

float c;

Example:

>>x=5;

>>x1=2;

(36)

Singletons

To assign a value to a variable use the equal symbol ‘=‘

>> A = 32

To find out the value of a variable simply type the name in

36

(37)

To make another variable equal to one already entered

>> B = A

The new variable is not updated as you change the original value

Note: using ; suppresses output

37

(38)

The value of two variables can be added together, and the result displayed…

>> A = 10

>> A + A

…or the result can be stored in another variable

>> B = A + A

38

(39)

You can use the command “clear all” to delete all the variables present in the workspace

You can also clear specific variables using:

>> clear Variable_Name

39

(40)

Addition

(+)

(-) Subtraction

(*) Multiplication

(/) Division

(^) Power

(’)

Complex conjugate transpose

(41)

THANK YOU

References

Related documents

The objective of this unit is to highlight the key characteristic of various facilities including hospitality and catering facilities, Tourism Facilities and identify the

Rapid urbanization and industrialization raised the need to protect property assets, given an opportunity to the global facility management market. Over the past

Unit-I Definition of Data Structure, Types of Data Structures, Abstract Data Type (ADT), Algorithms: Algorithm Concepts, Definition of Algorithm, Objectives of

Unit I: Introduction to Python- Python data structures, data types, indexing and slicing, vectors, arrays, developing programs, functions, modules and packages, data structures

• Path that MATLAB uses to search for script and function files. • Default path contains all built in MATLAB

• Path that MATLAB uses to search for script and function files. • Default path contains all built in

In the most recent The global risks report 2019 by the World Economic Forum, environmental risks, including climate change, accounted for three of the top five risks ranked

Matlab-Simulink based simulation results of BL-PFC Zeta converter based two stage LED driver (a) Input output waveforms, (c) Active and passive components half AC cycle