problem_lab_02_sol_s08

# problem_lab_02_sol_s08 - Solutions, ECE220 Problem Lab #2...

This preview shows pages 1–5. Sign up to view the full content.

Solutions, ECE220 Problem Lab #2 Signal Plots, Vectors, Matrices, and Linear Equations Date: Week of January 28, 2008 The main goal of this lab is to give you practice on: (a) signal calculation, processing and plotting, and, (b) vectors, matrices and linear equations. You will have an opportunity to see how this stuﬀ is used in ﬁelds such as (digital) sound processing. Feel free to experiment with the MATLAB scripts and GUIs in any way you want; work at your own pace. Do not worry if you do not ﬁnish everything in the allocated time. ————————————————————————————– I. Vector and Matrix operations 1. Work out problem 5.7. Solution. Use the following MATLAB script ( File: problem5 7.m ) %Define vectors r = [1; 2; 3; 4]; c = [5 6 7 8]; r1 = [-1; 2; -3; 4]; c1 = [5 -6 7 -8]; %Dimensionality of r and c dim_r = length(r) dim_c = length(c) %Transposes of r and c r_trans = r’ c_trans = c’ %Sum s = r + r1 1

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
s = r + r1 %Difference d = c - c1 d = c - c1 %Element-wise multiplication m1 = r * r1 m1 = r .* r1 %Element-wise multiplication m2 = c * c1 m2 = c .* c1 %Element-wise division d1 = r ./ r1 d1 = r ./ r1 %Element-wise division d2 = c ./ c1 d2 = c ./ c1 %Multiplication m3 = 5c m3 = 5*c %Division d3 = c/4 d3 = c/4 %Norm of r, c, s and m3 norm_r = norm(r) norm_c = norm(c) norm_s = norm(s) norm_m3 = norm(m3) The script will return the following results: dim_r = 4 dim_c = 4 r_trans = 1 2 3 4 c_trans = 5 6 7 8 s = 0 4 0 8 d = 0 12 0 16 2
m1 = -1 4 -9 16 m2 = 25 -36 49 -64 d1 = -1 1 -1 1 d2 = 1 -1 1 -1 m3 = 25 30 35 40 d3 = 1.2500 1.5000 1.7500 2.0000 norm_r = 5.4772 norm_c = 13.1909 norm_s = 8.9443 norm_m3 = 65.9545 2. Work out problem 5.10. Solution. Use the following MATLAB script: ( File: problem5 10.m ) %Define matrices A = [2 0 -1 -1 0 -2]; B = [1 1 -1 -2 3 0 -1 1 0]; %Transposes of A and B A_trans = A’ B_trans = B’ %Multiplication C1 = A*B C1 = A*B 3

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
C2 = A * B_trans %Multiplication C3 = A_trans * B C3 = A_trans * B %Multiplication C4 = A_trans * B_trans C4 = A_trans * B_trans The script will return the following results: A_trans = 2 -1 0 0 -1 -2 B_trans = 1 -2 -1 1 3 1 -1 0 0 >> C1 = A*B ??? Error using ==> mtimes Inner matrix dimensions must agree. >> C2 = A * B_trans ??? Error using ==> mtimes Inner matrix dimensions must agree. C3 = 4 -1 -2 4 -5 0 C4 = 1 -7 -3 1 -3 -1 Multiplication of two matrices can happen only if the no. of rows of the ﬁrst matrix is equal to the no. of columns of the second matrix. If this is not true then the two matrices cannot be multiplied. This is the reason we get errors when we try to calculate C1 and C2. ————————————————————————————– II. Vectors and Matrices as a language in other courses The TAs will provide help with any of these problems, if you need it. 1. Work out example 5.28. Write a MATLAB script to perform the computations.
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/30/2009 for the course ECE 220 taught by Professor Nilson during the Spring '08 term at N.C. State.

### Page1 / 15

problem_lab_02_sol_s08 - Solutions, ECE220 Problem Lab #2...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online