% question 6 % an example of a signal with frequency of 10 oscillations per second % f(t) = cos(10*2*pi*t), where t is expressed in seconds t = 0:0.1:3; % a first trial s1 = cos(10*2*pi*t); plot(t,s1) t = 0:1/20:3; % try two times the frequency s2 = cos(10*2*pi*t); plot(t,s2) % we need to sample at least two times the frequency for every second, % here we sample for three seconds at a rate of 20 samples per second, % thus a total of 60 samples as absolute lower bound % # 7 answer for n = 3 p3 = [ 0 0 1; 0 1 0; 1 0 0] p3 = 0 0 1 0 1 0 1 0 0 p3*[1:3]' ans = 3 2 1 % for any n, say n = 37 n = 37; rows = [1:n]; % there is a one on every row cols = [n:-1:1] % this defines where the ones in the columns come cols = Columns 1 through 12 37 36 35 34 33 32 31 30 29 28 27 26 Columns 13 through 24 25 24 23 22 21 20 19 18 17 16 15 14 Columns 25 through 36 13 12 11 10 9 8 7 6 5 4 3 2 Column 37 1 p37 = sparse(rows,cols,1); p37*[1:n]' ans = 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 % # 4 We have seen polyfit, fft, and spline. % polyfit fits the approximate data with a polynomial, preferably of low degree % we use the fft to remove noise from signals, because with fft we can get the % essential characteristics (amplitudes and frequencies) from a signal % splines are used in modeling, to design objects % # 5, see http://www.math.uic.edu/~jan/MCS320f01.html, last lecture % # 8 % Let xA, xB, and xC be the amount of shares of type A, B, and C % max 4*xA + 6*xB + 9*xC the objective is to maximize the interest % subject to the following constraints: % xA + xB + xC <= 100,000 % xC <= 20,000 % - xA <= -10,000 % xA >= 0, xB >= 0, xC >= 0 do not forget these constraints! % the answer to part (b): f = [-4 -6 -9]; % linprog deals with minimization A = [1 1 1; 0 0 1; -1 0 0; -1 0 0; 0 -1 0; 0 0 -1] A = 1 1 1 0 0 1 -1 0 0 -1 0 0 0 -1 0 0 0 -1 b = [100000; 20000; -10000; 0;0;0]; linprog(f,A,b) Optimization terminated successfully. ans = 1.0e+004 * 1.0000 7.0000 2.0000 format bank ans ans = 10000.00 70000.00 20000.00 diary off