Umal-qura university



Yüklə 0,73 Mb.
səhifə7/30
tarix23.12.2023
ölçüsü0,73 Mb.
#156716
1   2   3   4   5   6   7   8   9   10   ...   30
Signal and Systems Manual - v2full

Function Description
===============================================
Diag returns diagonal M.E. as vector
eye identity matrix
hilb Hilbert matrix
magic magic square
ones matrix of ones
rand randomly generated matrix
triu upper triangular part of a matrix tril lower triangular part of a matrix zeros matrix of zeros
===============================================

Here are some examples:



        1. Matrices of Random Entries: A 3 by 3 matrix with random entries is produced by typing

>> rand(3)
ans =



0.0470

0.9347

0.8310

0.6789

0.3835

0.0346

0.6793

0.5194

0.0535

General m‐by‐n matrices of random entries are generated with >> rand(m,n);





        1. Magic Squares: A magic square is a square matrix which has equal sums along all its rows and columns. For example:

>> magic(4)



ans =




16

2

3

13

5

11

10

8

9

7

6

12

4

14

15

1

The elements of each row and column sum to 34.

        1. Matrices of Ones: The functions

          • eye (m,n) produces an m‐by‐n matrix of ones.

          • eye (n) produces an n‐by‐n matrix of ones.




        1. Matrices of Zeros: The commands

          • zeros (m,n) produces an m‐by‐n matrix of zeros.

          • zeros (n) produces an n‐by‐n one;

If A is a matrix, then zeros (A) produces a matrix of zeros of the same size as A.

        1. Diagonal Matrices: If x is a vector, diag(x) is the diagonal matrix with x down the diagonal.

If A is a square matrix, then diag(A) is a vector consisting of the diagonal of
A. What is diag(diag(A))? Try it.
    1. MATRIX OPERATIONS

The following matrix operations are available in MATLAB:




Operator Description Operator Description
================================================
+ addition ' transpose
- subtraction \ left division
* multiplication / right division
^ power
================================================
These matrix operations apply, of course, to scalars (1‐by‐1 matrices) as well. If the sizes of the matrices are incompatible for the matrix operation, an error message will result, except in the case of scalar‐ matrix operations (for addition, subtraction, and division as well as for multiplication) in which case each entry of the matrix is operated on by the scalar.



      1. Matrix Transpose

The transpose of a matrix is the result of interchanging rows and columns. MATLAB denotes the [conjugate] transpose by following the matrix with the single‐quote [apostrophe]. For example:


>> A'
ans =



1

4

7

2

5

8

3

6

9

>> B = [1+i 2 + 2*i 3 ‐ 3*i]'


B =
1.0000 ‐ 1.0000i
2.0000 ‐ 2.0000i
3.0000 + 3.0000i

      1. Matrix Addition/Subtraction

Let matrix "A" have m rows and n columns, and matrix "B" have p rows and q columns. The matrix sum "A + B" is defined only when m equals p and n equals q, the result is n‐by‐m matrix having the element‐by‐element sum of components in A and B.


For example:
>> E = [ 2 3; 4 5.0; 6 7];
>> F = [ 1 ‐2; 3 6.5; 10 ‐45];
>> E+F

ans =
3.0000 1.0000
7.0000 11.5000

16.0000 ‐38.0000



      1. Matrix Multiplication

Matrix multiplication requires that the sizes match. If they don't, an error message is generated.


>> A*B, B*A;
>> B'*A;
>> A*A', A'*A;
>> B'*B, B*B';
Scalars multiply matrices as expected, and matrices may be added in the usual way (both are
done "element by element”):
>> 2*A, A/4;
>> A + [b,b,b];
Example:

We can use matrix multiplication to check the "magic" property of magic squares.


>> A = magic(5);
>> b = ones(5,1);
>> A*b; <== (5x1) matrix containing row sums.
>> v = ones(1,5);
>> v*A; <== (1x5) matrix containing column sum.



      1. Matrix Functions "any" and "all”

There is a function to determine if a matrix has at least one nonzero entry, any, as well as a function to determine if all the entries are nonzero, all.


>> A = zeros(1,4)
>> any(A)
>> D = ones(1,4)
>> any(D)
>> all(A)

      1. Returning more than One Value

Some MATLAB functions can return more than one value.


In the case of max the interpreter returns the maximum value and also the column index where the maximum value occurs.
>> [m, i] = max(B)
>> min(A)
>> b = 2*ones(A)
>> A*B
>> A

      1. Size of Matrix

Size of a matrix can be calculate by using function ‘size ‘.


>> x = [1 2 3 ;1 2 3];
>> s = size(x)
s =
2 3

      1. Length of Array

Length of an array can be found using function ‘length’.


>> n = [‐3:1:3];
>> l = length(n)
l =
7



      1. Finding an element in a matrix

This function can be used to find index of any particular value. Say given array is x= [0 2 4 6 8];


To find the indices of all values that are greater than 4, following is used
>> y = find(x>4)
y =
4 5


-------------------------TASK 01--------------------------
Write a program to generate a new matrix B from the matrix A given below such that each

column in the new matrix except the first one is the result of subtraction of that column from


the previous one i.e. 2nd new column is the result of subtraction of 2nd column and 1st column and so on. Copy the first column as it is in the new matrix.


3 6 9
A  1 4 8
2 8 7

-------------------------TASK 02--------------------------


Generate two 5000 sampled random discrete time signals (1 dimensional) using rand() function
i.e. rand(1, 5000). Write a program to add the two signals together using simple vector addition.


-------------------------TASK 03--------------------------


MATLAB has functions to round floating point numbers to integers. These are round, fix, ceil, and floor. Test how these functions work. Determine the output of the following:
>> f = [‐.5 .1 .5];
>> round(f)
>> fix(f)
>> ceil(f)

>> floor(f)





Yüklə 0,73 Mb.

Dostları ilə paylaş:
1   2   3   4   5   6   7   8   9   10   ...   30




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə