SnS_Lab_Exp_1.pdf

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Transcript

Signals & Systems Laboratory Department of Electronics and Communication Engineering Experiment No.1 1 Aim Define and use variables in MATLAB. Perform basic arithmetic operations (addition, subtraction, multiplication, division) wit...

Signals & Systems Laboratory Department of Electronics and Communication Engineering Experiment No.1 1 Aim Define and use variables in MATLAB. Perform basic arithmetic operations (addition, subtraction, multiplication, division) with these variables. Create vectors and matrices in MATLAB. Use built-in functions to perform operations such as trans- pose, determinant, and inverse of a matrix. 2 Software Required * MATLAB 3 Basic commands 3.1 Variable declaration Integer type declaration a = 3; b = 5; Character type declaration a1 = ”hello”; Vector declaration a2 = [1 2 3 4]; or a21 = [1, 2, 3, 4]; − − − − > row vector a3 = [1; 2; 3; 4]; − − − − > column vector 3.2 Defining vectors in a given interval Linspace(x1,x2,n): Linspace is generates n points. The spacing between the points is (x2-x1)/(n-1). b2 = linspace(−5, 5, 10); Logspace: Vector of logarithmically spaced numbers. c = logspace(a, b); Vector with Specified Number of Values c1 = logspace(a, b, 7); 3.3 Random Numbers Matrix of random value with size 10x10. d = rand(10); Generate a 5-by-5 matrix of normally distributed random numbers. d1 = randn(5); Page 1 Generate a 10-by-1 column vector of uniformly distributed random integers from the sample interval [-5,5]. d2 = randi([−5, 5], 10, 1); 3.4 Operators Initializing two matrices as f = [1 2 3; 4 5 6; 7 8 9]; and g = [1 4 5; 2 5 8; 4 6 3]; Addition g1 = f + g; Subtraction g2 = f − g; Multiplication g3 = f ∗ g; Division g4 = f /g; Exponentiation g5 = f ∧ 2; Element-wise multiplication g6 = f. ∗ g; Element-wise division g7 = f./g; Element-wise exponentiation g8 = f. ∧ g; 3.5 Relational and Logical operators Initializing two vectors as h1 = [1 2 3 4 5]; and h2 = [5 4 3 2 1]; Greater than h3 = h1 > h2; Equal h4 = h1 == h2; Less than h5 = h1 < h2; Greater than or equal / and h6 = h1 >= 2 & h1 4; Page 2 3.6 Loop: For and If/else Figure 1: code for z and v function 3.7 Visualizing the data plot( X , Y ) Creates a 2-D line plot of the data in Y versus the corresponding values in X. To plot a set of coordinates connected by line segments, specify X and Y as vectors of the same length. To plot multiple sets of coordinates on the same set of axes, specify at least one of X or Y as a matrix. plot(t, z); hold on Retains plots in the current axes so that new plots added to the axes do not delete existing plots. New plots use the next colors and line styles based on the Color Order and Line Style Order. hold on; plot(t, v); Sets the hold state to off hold of f ; For opening a new figure f igure; subplot subplot(m,n,p) divides the current figure into an m -by- n grid and creates axes in the position specified by p. subplot(211); stem stem(x,y) plots the data sequence, Y , at values specified by X. stem(z); subplot(212); stem(v); Page 3 Semi-logarithmic plot Initializing two vectors as x1 = 0 : 0.1 : 10; and y1 = exp(x1); Semilogy(x1, y1); Log-log scale plot Initializing two vectors as x2 = Logspace(−1, 2); and y2 = exp(x2); Loglog(x2, y2); 4 Results Write on your own. 5 Conclusion Write on your own. Page 4

Tags

MATLAB arithmetic operations matrix operations engineering
Use Quizgecko on...
Browser
Browser