the federal university of technology akure by: dr w. o apena dept. of electrical and electronic...

56
The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering.

Upload: philip-gilbert

Post on 18-Jan-2018

223 views

Category:

Documents


0 download

DESCRIPTION

Case Hardware (Mother Board) Case Hardware 3

TRANSCRIPT

Page 1: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

The Federal University Of Technology Akure

By: Dr W. O Apena Dept. Of Electrical and Electronic

Engineering.

Page 2: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

2

What are computer systems?Computer systems includes: Hardware and Operating System.Computer Hardware: This is refer to as physical component of a computer system.

Review Of Computer Systems

Case Hardware Outside Hardware Network HardwareMotherboard Monitor Digital ModemCentral Processing Unit (CPU)

Key board Router

Random Access Memory (RAM)

Mouse Network Switch

Power Supply unit Battery backup (UPS) Access PortVideo Card (VC) Printer, Speaker RepeaterHard Drive (HD) - Internal Hard Drive (HD) - External Bridge

Solid State Derive Network interface card (NIC) Print Server

Optical Derive Controller Card FirewallCard Reader Sound Card

EEE 309 - Dr W O Apena

Page 3: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 3

Case Hardware (Mother Board)

Case Hardware

Page 4: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 4

Outside Hardware

Monitor

MouseKeyboard

UPSHard drive

Network Interface CardController Card Sound Card

Page 5: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 5

Network Hardware

Digital Modem

Router

Network Switch

Network Access Port

Repeater Bridge

Print Server- FOFirewall example

Page 6: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 6

Operating Systems and Utility Programs

Operating System (OS): An operating system (OS) is a set of programs containing instructions that coordinate all the activities among computer hardware devices.

A utility program performs a specific task, usually related to managing a computer, its devices, or its programs.

Note: OS and application program are interface in the system

Example OSLinux, Windows, VMS, OS/400, AIX, z/OS, the Mac OS, OS/2, UNIX, and NetWare

Page 7: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 7

Common features to most OS

Most operating systems perform similar functions that include:

managing programs, such as multitasking managing memory e.g spooling or storage buffer

and file management scheduling jobs ie assigning process(es) configuring devices accessing the Web monitoring performance ie assesses and reports

information about various system resources and devices

providing housekeeping services administering security such as users name,

password etc

Page 8: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 8

Stand-Alone OS and Network (NOS)A stand-alone OS is a complete operating system that works on a computer machine. A typical example is notebook system

Notebook computer

Page 9: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 9

A network OS (also called NOS) is an operating system that supports a network system or topology.

Note: A network topology is a collection of computers and devices connected

together via communications media or devices such as cables, telephone lines, and modems.

In most network, the server has NOS that controls access to the hardware and software in a topology and provides a centralized storage area. Other computers on the network, called clients, rely on the server(s) for resources.

NOS

NOS via cloud

Page 10: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 10

Examples of Stand-Alone OS and NOSStand-alone OS Network OS (NOS)Disk OS (DOS) – Refer to as several single user UNIX – work for both stand-alone and NOS

Window 3.X – Refer to as early operating environment with DOS

OS/2 Warp Server for E-business

Window 95 – called multitasking Netware – widely used for clients/serverWindow NT Workstation – called client OS Window NT Server – client/server networkWindow 98 – includes internet explorer and window explorer (file manager)

Active Desktop – similarly to web links Window 2000 Professional – complete OS, reliable multitasking client OS

Window 2000 Server – includes e-commerce and database

Window Millennium Edition – good for home user

Window .Net server – e-commerce applications

Window XP – fastest most reliable OS Window XP Home Edition – upgrade of millennium edition

Window XP Professional Edition – upgrade to window 2000 professional

Mac OS – macintosh OS available with ‘apple products’

Solaris – designed for e-commerce

Page 11: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 11

An OS perform these services for application program:

• Multitasking operating system where multiple programs can be running at the same time, the operating system determines which applications should run in what order and how much time should be allowed for each application before giving another application a turn.

•It manages the sharing of internal memory among multiple applications.

•It handles input and output to and from attached hardware devices, such as hard disks, printers, and dial-up ports.

•It sends messages to each application or interactive user (or to a system operator) about the status of operation and any errors that may have occurred.

Page 12: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 12

• It can offload the management of what are called batch jobs (switching printing job) so that the initiating application is freed from this work.

• On computers that can provide parallel processing

Page 13: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

13EEE 309 - Dr W O Apena

Application software and Programming languages

What is an application software?

An application software is a program or group of programs designed for end users and it is use to carry out operations for a specific application. Note:

Application software may simply be referred to as an application such as MATLAB package, Statistical Package for Social Sciences –SPSS, etc.

Application software cannot run on itself but is dependent on system software to execute

Page 14: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 14

Interactions of Hardware, System and Application Software

System software consists of programs that control the operations of a computer and its devices. Note: System software serves as the interface between a user, the application software, and the computer’s hardware.

Interaction Diagram

Page 15: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 15

Dependency of Application Software

Page 16: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 16

Identify the role of the user interface

The role of user (s) interface are:

confirm application software operation(s)check data validity or instruction controls input(s) of data and instructions monitor response(s) and output displayed on

the computer screen (graphical user interface - GUI).

Note: A graphical user interface (GUI) combines text

and graphics Visual images to make software easier to use

and be monitored.

Page 17: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 17

Programming LanguagesProgramming languages are set of instructions through which one tells the computer(s) to do the desired task.

These set of instructions written in human readable computer language is called Source Code.

Every program has two parts, namely:

code – instruction(s)

data – variable(s) and parameters

There are two models of programming, namely:

Structured Programming e.g MATLAB, C programme and FORTRAN

Object Oriented Programming e.g UML

Page 18: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 18

Problem Solving Techniques in Programming

To develop the solution for the given problem, the following programming techniques are used.

(1) Algorithm (2) Flow chart (3) Pseudo codes (4) Decision table

1. Algorithm

The word ‘Algorithm’ is the name of one Persian author meaning rules of

restoration and reduction. Once the problem is analysed, its solution is

broken into a number of sample steps. A problem in a finite sequence is

called an algorithm.

Page 19: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 19

Properties of an Algorithm Finiteness: An algorithm must always terminate after a

finite

number of steps.

Definiteness: Each step must be clearly defined that actions

carried out must be unambiguous.

Input: Input should be provided at the beginning of algorithm.

Output: Algorithm must produce on or more output.

Effectiveness: All the operations defined must be sufficiently basic

that they can be done exactly in finite length of time manually.

Page 20: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 20

Structure of AlgorithmStart

Step 1:

Step 2:

Step 3:

.

.

.

Step n:

End

Basic Statements Used and Examples

i. Algorithm always begins with the word ‘Start’ and ends with ‘stop’ the word

ii. Step wise solution is written in distinguished steps.

iii Input Statement: Algorithm takes one or more inputs to process. The statements used to indicate the input is Read a or Input b.

ExampleLet a , b be the names of the Input

Input a or Read a

Input b or Read b

Where a and b are variable names.

Page 21: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 21

vi. Output Statements: Algorithm produces one or more outputs. The

statement used to show the output is output a or print b.

Syntax: Output variable name

Print variable name

Example: output a or print a

output b or print b

where a and b are variable names.

Page 22: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 22

V. Assignment Statements: Processing can be done using the assignment statement.

i.e. L.H.S = R.H.S

On the L.H.S is a variable. While on the R.H.S is a variable or a constant or an expression. The value of the variable, constant or the expression on the R.H.S is assigned in L.H.S.

The L.H.S and R.H.S should be of the same type. Here ‘ = ’ is called assignment operator.

Example:Let the variables be x, y.

The product be z this can be represented by as

Read x, y

Z = x * y

Page 23: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 23

vi. Order in which the steps of an algorithm are executed is divided in to 3

types namely

Sequential Order

Example: Task : Write an algorithm to add two numbers.

Step 1 : Start

Step 2 : Read a

Step 3 : Read b

Step 4 : Add a , b

Step 5 : Store in d

Step 6 : Print d

Step 7 : End

Page 24: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 24

Conditional OrderBased on fact that the given condition is met or not the algorithm selects

the next step to do. If statements are used when decision has to be

made. Different format of if statements are available they are:

a) Syntax: If

if (condition)

Then {set of statements S1}

b) Syntax – if else (condition)

if (condition)

else

Then {set of statements S1}

Then {set of statements S2}

c) Syntax – Nested if else (con.)

If (condition 1)

Then S1

Else

If (condition 2)

Then S2

Else

Then S3

Page 25: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 25

Iterative OrderHere algorithm repeats the finite number of steps over and over till the condition is not meet. Iterative operation is also called as looping operation.

Add ‘n’ natural numbers till the sum is 5.

Step 1 : Start

Step 2 : set count to 0

Step 3 : add 1 to count

Step 4 : if count is less than 5,

Repeat steps 3 & 4

Step 5 : otherwise print count

Step 6 : End

Example

Page 26: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 26

2 Flow chartAlgorithm for large problems; complex and there by difficult to write code. Problem

analysts found ‘Flow charts’ an easier way to solve the problem. The

other names of flow chart are flow diagram, process chart, and business flow diagram. Limitations

Alterations and modifications: If alterations are required, the flowchart

may require re-drawing completely, then appear complex.

Types of flow chart

1. System flow chart

2. Program flow chart

Page 27: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

27EEE 309 - Dr W O Apena

Symbols Used in FlowchartsThe flow chart being symbolic representation standard symbols is used for

each specific operation.

Start or end of the programmer

Computational steps or processing function of program

Input or output operationDecision making and branching

Connector or joining of two parts of program

Subroutine

Database Document printout

Print

Page 28: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 28

Example: Draw a flowchart to find greater of 2 numbers

Lets the two number be ‘a and b’ Start

Read a, b

Is a<b

Print a

Print b

Yes

stop

Page 29: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 29

Pseudo codes This is an informal high-level description of the operating principle of a computer

program or other algorithm.

Page 30: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 30

MATLAB: Introduction and user interface

This is an interactive software program for solving numerical

computations, it can perform powerful operations using just one or two

commands. MATLAB is a good package for scientist and professional. It is

use for complex calculation in a better platform. It has comprises of

1000s of function in multitasking domainMATLAB EnvironmentsIt has 3 important window depending on the version

1. Command window – where operations are carried out

2. Workspace window – ‘variable’ and ‘ans’

3. Command history – shows history of operation done with date and time.

Page 31: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 31

Commonly used command

‘clc’ in command window – clear all operation(s) on command window

‘clear’ in-specific - to delete specific variable or ans in workspace window % - to make note or expression, (;) do note operateExamples in simple algebraic operation

>> a=6a = 6>> b=7b = 7>> a+b

ans = 13

a=6, b=7

Note: see the

definitions of variable

in workspace window,

such vector and

matrix.

b-a

ans =

1

Page 32: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 32

Multiplication, Power and Division OperationsNote: second function of key 8 (*) is use for multiplication and 6(^) while division (/)

a*b % a multiply b

ans = 42

>>a^b % a raised to power of b

ans = 279936

Note - negative sign in MATLAB

There are distinct difference in

-a^a and (-a)^a

MATLAB will see as -1 * a^a

Examples:

-2^2

ans =

-4

(-2)^2

ans =

4

a/b % a divided by b

ans = 0.8571

(a*b*a)/(a+b)

ans =

19.3846

Page 33: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 33

Variable definition and GUI

x=[0:0.1:10]; % take variable of x from 0 at interval of 0.1 to 10.

plot (x, sin(x))

Note: study the GUI display and practice all the menu with the graph

Assignment

x=[0 :0.1: 5];(a)plot (x, cos(x)) ; determine using the GUI menu.

(i) Minimum of the graph (ii) y = -0.8, x =?

Plot (x, sin (x))

(b)plot (x, sin (x))

(i) Maximum of the graph

(ii) What is y at x=1 or 3

Note: ‘who’ will tell you all the existing variable.

‘whos’ will tell detailed information.

X=[0: 0.1: 5]

Page 34: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 34

Example 1[x y ] = meshgrid (-8 : 0.5 : 8);

>> r = sqrt (x.^2 + y.^2) + eps;>> z = sin(r) ./ r;

>> mesh(z);

plot(x,y), xlabel('x'), ylabel('exp(-1.2x)*sin(20x)'),axis([0 5 -1 1])Example 2

Example 3

x = [1: 5];y = [50,98,75,80,98];bar(x,y), xlabel('Student'),ylabel('Score'),title('Final Exam')

[x,y] = meshgrid (-2*pi:0.1:2*pi);>> z = cos(x).*sin(y);>> mesh(x,y,z),xlabel('x'),ylabel('y'),zlabel('z')Note: replace surfc with mesh to revealed surface reflection.

Example 4

Page 35: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 35

r = sqrt(x.^2 + y.^2) + eps;>> [x y ] = meshgrid(-8 : 0.5 : 8);>> r = sqrt(x.^2 + y.^2) + eps;>> z = sin(r) ./ r;>> surf(x,y,z,'facecolor','interp','edgecolor','none', ...'facelighting','phong')

Note: colormap jetdaspect([5 5 1])axis tightview(-50, 30)camlight left

Page 36: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 36

Factorial, Square Roots and nth Roots

MATLAB does not understand (!) in the sign notation.It understand word in ‘factorial (n)’

Example: >> factorial (8)ans = 40320

Square roots

Factorial

The package understand sqrt (N) = N^(1/2)

sqrt (16)

ans =

4

Nth roots The system understand nth roots as (X, nth)

>> 16^(1/2)

ans =

4

>> nthroot(81,2)

ans =

9

>> nthroot(125,3)

ans =

5

Page 37: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 37

Symbolic MathematicsUsing symbolic sign has wide range of application, it will be linked to sqrt.

>> sqrt (80)

ans =

8.9443

Put ‘ans’ in sym

>> sym(ans) ans = 4*5^(1/2)

pretty(ans) 1/2 4 5

sym(sqrt (1025)) ans = 5*41^(1/2)

>> pretty(ans) 1/2 5 41

>> double (ans)

ans =

32.0156

Simple form

double(ans)

ans =

8.9443

Simple form

Page 38: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 38

Further readings and MATLAB work

Complex number

Trigonometry

Hyperbolic Function

Logarithm and exponential

Page 39: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 39

Vector and ComponentMATLAB does not understand vector in the physical locations of I, j and k or x, y and z

Rather MATLAB understands definitions of vectors in variables as shown for x and y:

x=[ 4 7 9]

x = 4 7 9

>> y=[3 2 6]

y = 3 2 6

The statement above revealed direction of the vector

Note: Any of the element could be called for e.g x(n)

>> x(3)

ans =

9

>> y(2)

ans =

2

Page 40: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 40

More examples:

>> x(3)*y(2)

ans =

18

>> (x(3)*y(2)) / x(2)

ans =

2.5714

>> x(1) / y(1)

ans =

1.3333

>> (y(2)/x(2))/y(3)

ans =

0.0476

Note: value of

vector(s) could be

changed on

workspace. It will

pose like a spread

sheet for

alteration

Page 41: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 41

Additions, Subtraction and Multiplication of Vector(s) Addition of vectors Subtraction of vector Multiplication of

vector by scalar>> x

x = 4 7 9

>> y

y = 3 2 6

>> z=x + y

z =

7 9 15

>> x

x = 4 7 9

>> z

z = 7 9 15

>> x-z

ans =

-3 -2 -6

>> x=[ 2 5 7]x = 2 5 7

>> y=[6 3 8]y = 6 3 8

>> (2-5^2)*(x-y)

ans =

92 -46 23

Page 42: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 42

Creating Larger Vectors from Existing Variables

MATLAB allows you to append vectors together to create new ones. Let u and v betwo column vectors with m and n elements respectively that we have created inMATLAB.

Example >> A = [8; 4; 5];

B = [2; 6; 7];

>> D = [A; B]

D =

8 4 5 2 6 7

Column Row>> A=[8, 4, 5]

A = 8 4 5

>> B= [2, 6, 7]B =

2 6 7

>> D = [A,B]D =

8 4 5 2 6 7

Page 43: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 43

Creating Vectors with Uniformly Spaced Elements

It is possible to create a vector with elements that are uniformly spaced by anincrement q, where q is any real number.

x = [xi : q : xn]

Where xi = first number, q= the real number interval and xn is the last number

Example>> x = [0:2:12]

x =

0 2 4 6 8 10 12

Page 44: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 44

Creating Stream of Vectors in ExponentialThe set of x values can be used to create a list of points representing the valuesof some given function.

For example, suppose that y = exp (x)

x = [0:0.1:1];>> y= exp (x)

y =

Columns 1 through 9

1.0000 1.1052 1.2214 1.3499 1.4918 1.6487 1.8221 2.0138 2.2255

Columns 10 through 11

2.4596 2.7183

Note: you could have y=x.^2

Page 45: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 45

Characterizing a Vector

The length command returns the number of elements that a vector contains

>> A=[8, 4, 5]

A =

8 4 5

>> length(A)

ans =

3

Example

Length Maximum

>> max(A)

ans =

8

Minimum

>> min(A)

ans =

4

Page 46: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 46

Magnitude of a VectorTo perform this operation, we will first take the dot product of a vector with itself. This is done by using array multiplication (.*).

First let’s define a vector:

>> A

A =

8 4 5

>> A.*A

ans =

64 16 25

>> sum(ans)

ans =

105

>> mag=sqrt(105)

mag =

10.2470

Note: Practice magnitude of complex number

Page 47: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 47

Dot and Cross Product of Vector(s)

Dot Product

The dot product of vector and y

>> xx =

2 5 7

>> yy =

6 3 8

>> dot (x, y)ans =

83

Cross ProductMATLAB does not understand direct cross product

but it can be treated in transpose

>> x‘ % transpose of x

ans =

2 5 7

>> y

y =

6 3 8

>> cross (x', y)

ans =

19 26 -24

Page 48: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 48

Referencing Vector ComponentsMATLAB has several techniques that can be used to reference one or more of thecomponents of a vector. The ith component of a vector v can be referenced bywriting v(i)

>> A = [12; 17; -2; 0; 4; 7; 11; 19; 27];

>> A(3)

ans =

-2

Example: Note: v(:) tells MATLAB to list all of thecomponents of the vector:

Example

>> A(3:6)

ans =

-2 0 4 7

Page 49: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 49

Basic Operations with Matrices

A matrix is a two-dimensional array of numbers (row and column). To

create a matrix in MATLAB, we enter each row as a sequence of comma

or space delimited numbers, and then use semicolons to mark the end

of each row.

B= [2 0 1; 1 7 4; 3 0 1]

B =

2 0 1 1 7 4 3 0 1

>> A = [-1,6; 8, 11]

A =

-1 6 8 11

Page 50: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 50

Addition And Subtraction of Matrix Two matrices having the same number of rows and columns, addition and subtraction

operation is possibleAddition Subtraction

>> A = [5 3; 0 8];

>> B = [2 7; 4 1];

>> A+B

ans =

7 10 4 9

>> A = [5 3; 0 8];

>> B = [2 7; 4 1];

>> A-B

ans =

3 -4 -4 7

Page 51: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 51

Transpose of Matrix

The transpose of a matrix is compute by switches the rows and columns in a matrix.

Example

>> D = [1 5 4; 5 3 6; 5 8 2]

D =

1 5 4 5 3 6 5 8 2

>> D'

ans =

1 5 5 5 3 8 4 6 2

Transpose

Page 52: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 52

Matrix Multiplication

Considering two matrices A and B. A is an m × p matrix and B is a p × n matrix, theycan be multiplied together to produce an m × n matrix. To do this in MATLAB, we simply write A*B.

Note: Keep in mind that if the dimensions of the two matrices are not correct, the operation will generate an error.>> A = [1 5 4; 5 3 6; 5 8 2];

>> B = [6 3 2; 4 2 6; 7 4 3];

>> A*B

ans =

54 29 44 84 45 46 76 39 64

>> (A*B)'

ans =

54 84 76 29 45 39 44 46 64

Transpose

Page 53: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 53

Divisions of MatrixPerforming left (\) and right (/) division on an array. This works by matchingcomponent by component, so the arrays have to be of the same size

Note: Array left division is indicated by writing C = A.\B (this is the same as C = B./A)

>> AA = 1 5 4 5 3 6 5 8 2

>> BB = 6 3 2 4 2 6 7 4 3

>> C=B.\A

C = 0.1667 1.6667 2.0000 1.2500 1.5000 1.0000 0.7143 2.0000 0.6667

>> C=A./B

C = 0.1667 1.6667 2.0000 1.2500 1.5000 1.0000 0.7143 2.0000 0.6667

Page 54: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 54

Referencing Matrix Elements

A = [1 5 3; 9 5 0; 7 2 9]

A =

1 5 3 9 5 0 7 2 9

>> A(2,3)

ans =

0

Individual elements and columns in a matrix can be referenced using MATLAB.

Consider the matrix

We can pick out the element at row position m and column position n by typingA(m,n).

For example:

Page 55: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 55

Referencing Column(s)

Note: To reference all the elements in the ith column we write A(:,i)

Example:

A(:,2)

ans =

5 5 2

A =

1 5 3 9 5 0 7 2 9

Note: To pick out the elements in the ith through jth columns we type A(:,i:j).

>> A(:,2:3)

ans =

5 3 5 0 2 9

Page 56: The Federal University Of Technology Akure By: Dr W. O Apena Dept. Of Electrical and Electronic Engineering

EEE 309 - Dr W O Apena 56

Referencing cont.

Note: The elements in the second and third rows that are also in the fi rst andsecond columns, in the same matrix

>> A

A =

1 5 3 9 5 0 7 2 9

>> A(2:3,1:2)

ans =

9 5 7 2

Example:

>> A(1,1)

ans =

1

Note: Picking particular number.