You are on page 1of 17

SIGNALS AND SYSTEMS LAB

LABSHEET EXCERCISE -1

1.Type the following commands and observe closely what happens after each instruction

1a) help sqrt

SQRT Square root.

SQRT(X) is the square root of the elements of X. Complex

results are produced if X is not positive.

1b) x= sqrt(4)

x=

1c) y=sqrt(9)

y=

1d) who

Your variables are:

x y

1e) Who

??? Undefined function or variable 'Who'.

1f)whos

Name Size Bytes Class Attributes

x 1x1 8 double
y 1x1 8 double

1g) z=sin(3.14)

z=

0.0016

1h) whos

Name Size Bytes Class Attributes

x 1x1 8 double

y 1x1 8 double

z 1x1 8 double

1i) clc

clears command window

1j) who

your variables are:

x y z

1k) clear

erases the workspace

1l) who

no variable appears

1m) size(x)

??? Undefined function or variable 'x'.

1n) a=[1 2 3]

a=

1 2 3

b=[3 4 5]
b=

3 4 5

>> a*b

??? Error using ==> mtimes

Inner matrix dimensions must agree.

>> a.*b

ans =

3 8 15

1o) C=[a b]

C=

1 2 3 3 4 5

1p) zeros(4)

ans =

0 0 0 0

0 0 0 0

0 0 0 0

0 0 0 0

1q)zeros(1,3)

ans =

0 0 0
1r)ones(1,2)

ans =

1 1

1s)P=[zeros(1,3) 1 1 ones(1,2)]

P=

0 0 0 1 1 1 1

1t. P=[zeros(3,1) 1 1 ones(1,2)]


??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

1u.Y=1:0.5:5
Y=

Columns 1 through 7

1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 4.0000

Columns 8 through 9

4.5000 5.0000

1v.M=[1 2 3
456
7 8 9]
M=

1 2 3
4 5 6
7 8 9

>> fprintf('%f\n',M);
1.000000
4.000000
7.000000
2.000000
5.000000
8.000000
3.000000
6.000000
9.000000
??? X= M[1,:]
|
Error: Unbalanced or unexpected parenthesis or bracket.

2.

2a) Method 1
A=[ 3 12 6 8
5 3 9 11
1 2 14 7
10 5 3 6]

A=

3 12 6 8
5 3 9 11
1 2 14 7
10 5 3 6

Method 2
A=[3 12 6 8;5 3 9 11;1 2 14 7;10 5 3 6]

A=

3 12 6 8
5 3 9 11
1 2 14 7
10 5 3 6

Method 3

A=[3,12,...

6,8

5,3,...

9,11

1,2,...

14,7

10,5,...

3,6]
A=

3 12 6 8

5 3 9 11

1 2 14 7

10 5 3 6

Method 4

A=[3,12,6,8;5,3,9,11;1,2,14,7;10,5,3,6];

>> disp(A)

3 12 6 8

5 3 9 11

1 2 14 7

10 5 3 6

2b) Y=A'

Y=

3 5 1 10

12 3 2 5

6 9 14 3

8 11 7 6
Z=inv(A)

Z=

-0.0490 -0.0607 0.0296 0.1421

0.0979 -0.0831 0.0091 0.0113

-0.0140 -0.0920 0.1286 0.0373

0.0070 0.2165 -0.1211 -0.0982

2c) B=size(A)

B=

4 4

2d) X= A(2,1:4)

X=

5 3 9 11

>> Y=A(1:4,3)

Y=

14

3
2e) X*Y

ans =

216

2h)

fprintf('%f',a)

fprintf('%f\n',a)

3.000000

5.000000

1.000000

10.000000

12.000000

3.000000

2.000000

5.000000

6.000000

9.000000

14.000000

3.000000

8.000000

11.000000

7.000000

6.000000
>>

2f) X.*Y

??? Error using ==> times

Matrix dimensions must agree.

2g) A(4,:)=[1 5 9 0]

A=

3 12 6 8

5 3 9 11

1 2 14 7

1 5 9 0

2i) fliplr(A)

ans =

8 6 12 3
11 9 3 5
7 14 2 1
6 3 5 10

2j) D=diag(A)

D=

3
3
14
6

2k) V=diag(diag(A))

V=
3 0 0 0
0 3 0 0
0 0 14 0
0 0 0 6

2l)Z=eye(4)
Z=

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1

2m) cat(2,A,Z)

ans =

3 12 6 8 1 0 0 0
5 3 9 11 0 1 0 0
1 2 14 7 0 0 1 0
10 5 3 6 0 0 0 1

3.w=(0:0.01:1)

w=(0:0.01:1)

w=

Columns 1 through 7

0 0.0100 0.0200 0.0300 0.0400 0.0500 0.0600

Columns 8 through 14

0.0700 0.0800 0.0900 0.1000 0.1100 0.1200 0.1300

Columns 15 through 21

0.1400 0.1500 0.1600 0.1700 0.1800 0.1900 0.2000

Columns 22 through 28

0.2100 0.2200 0.2300 0.2400 0.2500 0.2600 0.2700


Columns 29 through 35

0.2800 0.2900 0.3000 0.3100 0.3200 0.3300 0.3400

Columns 36 through 42

0.3500 0.3600 0.3700 0.3800 0.3900 0.4000 0.4100

Columns 43 through 49

0.4200 0.4300 0.4400 0.4500 0.4600 0.4700 0.4800

Columns 50 through 56

0.4900 0.5000 0.5100 0.5200 0.5300 0.5400 0.5500

Columns 57 through 63

0.5600 0.5700 0.5800 0.5900 0.6000 0.6100 0.6200

Columns 64 through 70

0.6300 0.6400 0.6500 0.6600 0.6700 0.6800 0.6900

Columns 71 through 77

0.7000 0.7100 0.7200 0.7300 0.7400 0.7500 0.7600

Columns 78 through 84

0.7700 0.7800 0.7900 0.8000 0.8100 0.8200 0.8300

Columns 85 through 91

0.8400 0.8500 0.8600 0.8700 0.8800 0.8900 0.9000

Columns 92 through 98

0.9100 0.9200 0.9300 0.9400 0.9500 0.9600 0.9700

Columns 99 through 101

0.9800 0.9900 1.0000

length(w)
ans =

101

4) x=[1 6 9 2]

x=

1 6 9 2

>> y=[2 0 3 8]

y=

2 0 3 8

>> x+y

ans =

3 6 12 10

>> x.*y

ans =

2 0 27 16

5) conj(3+7i)

ans =

3.0000 - 7.0000i

>> j=ans

j=

3.0000 - 7.0000i
>> abs(j)

ans =

7.6158

>> phase(j)

ans =

-1.1659

7.) WHO List current variables.

WHO lists the variables in the current workspace.

In a nested function, variables are grouped into those in the nested

function and those in each of the containing functions. WHO displays

only the variables names, not the function to which each variable

belongs. For this information, use WHOS. In nested functions and

in functions containing nested functions, even unassigned variables

are listed.

WHOS lists more information about each variable.

WHO GLOBAL and WHOS GLOBAL list the variables in the global workspace.

WHO -FILE FILENAME lists the variables in the specified .MAT file.

WHO ... VAR1 VAR2 restricts the display to the variables specified. The

wildcard character '*' can be used to display variables that match a

pattern. For instance, WHO A* finds all variables in the current

workspace that start with A.


WHO -REGEXP PAT1 PAT2 can be used to display all variables matching the

specified patterns using regular expressions. For more information on

using regular expressions, type "doc regexp" at the command prompt.

Use the functional form of WHO, such as WHO('-file',FILE,V1,V2),

when the filename or variable names are stored in strings.

S = WHO(...) returns a cell array containing the names of the variables

in the workspace or file. You must use the functional form of WHO when

there is an output argument.

Examples for pattern matching:

who a* % Show variable names starting with "a"

who -regexp ^b\d{3}$ % Show variable names starting with "b"

% and followed by 3 digits

who -file fname -regexp \d % Show variable names containing any

% digits that exist in MAT-file fname

WHOS List current variables, long form.


WHOS is a long form of WHO. It lists all the variables in the current
workspace, together with information about their size, bytes, class,
etc.

In a nested function, variables are grouped into those in the nested


function and those in each of the containing functions, each group
separated by a line of dashes. In nested functions and in functions
containing nested functions, even uninitialized variables are listed.

WHOS GLOBAL lists the variables in the global workspace.


WHOS -FILE FILENAME lists the variables in the specified .MAT file.
WHOS ... VAR1 VAR2 restricts the display to the variables specified.
The wildcard character '*' can be used to display variables that match
a pattern. For instance, WHOS A* finds all variables in the current
workspace that start with A.

WHOS -REGEXP PAT1 PAT2 can be used to display all variables matching
the specified patterns using regular expressions. For more information
on using regular expressions, type "doc regexp" at the command prompt.

Use the functional form of WHOS, such as WHOS('-file',FILE,V1,V2), when


the filename or variable names are stored in strings.

S = WHOS(...) returns a structure with the fields:


name -- variable name
size -- variable size
bytes -- number of bytes allocated for the array
class -- class of variable
global -- logical indicating whether variable is global
sparse -- logical indicating whether value is sparse
complex -- logical indicating whether value is complex
nesting -- struct with the following two fields:
function -- name of function where variable is defined
level -- nesting level of the function
persistent -- logical indicating whether variable is persistent
You must use the functional form of WHOS when there is an output
argument.

Examples for pattern matching:


whos a* % Show variable names starting with "a"
whos -regexp ^b\d{3}$ % Show variable names starting with "b"
% and followed by 3 digits
whos -file fname -regexp \d % Show variable names containing any
% digits that exist in MAT-file fname

8.B=sym(x^2+5*x+6)

B=

x^2 + 5*x + 6

>> solve(B)

ans =

-3
-2
9. E=[1 5 6]

E=

1 5 6

roots(E)

ans =

-3.0000
-2.0000

10. U=[ 4 5 6 7]

U=

4 5 6 7

>> mean(U)

ans =

5.5000

>> median(U)

ans =

5.5000

sum(U)

ans =

22

11. y=int('x^2')

y=
1/3*x^3

12.y=int('x^3+x^2+1',0,5)

y=

2435/12

You might also like