%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% pp. 5 - 6 Creating and Plotting Functions of Time %%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% t=0:0.01:5; y=3*(t.^2) + t + 5; plot(t,y) %%%%%%%%%%%%%%%%%%%%%%%%%%%%% t=-5:0.01:5; u=(t>=0); r=t.*u; plot(t,r) y=r.*sin(5*pi*t); plot(t,y) %%%%%%%%%%%%%%%%%%%%%%%%%%%% t=0:0.01:8; fo=1/2; s=sin(2*pi*fo*t); plot(t,s) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% p. 9 Matrix Rows containing separate functions of time %%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% t=0:0.01:5; x=t; y=t.^2; A=[x;y]; plot(t,A) % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% p. 10 Summation %%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% S=sum(1:10) %%%%% B=[1:10;10:19] sum(B) %%%%% z=sum(A); plot(t,z) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% p. 10 Indexing %%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% x=20:30 x(3) x(1:2:11) x(2:2:10) x=1:3 y=(1:4)' B=y*x z=B(2,:) z=B(2,1:2) z=B(:,3) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% p. 12 Looping %%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% N=10; for n=1:N X1(n)=1/(n^2); end X1 %%%%% vs. Non-Looping %%%%% N=10; n=1:N X2=1./(n.^2); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%% p. 13 Signals & Systems %%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% del_t = 0.02e-3; t=0:del_t:10e-3; % creates a 1 x 501 row vector of time points n=(1:10).'; % creates a 10x1 column vector of integers 1 to 10 COS=cos((n*t)*2*pi*500); plot(t,COS(1,:),'b') hold on plot(t,COS(2,:),'r--') hold off A=-5./(pi*n.^2) size(A(:,ones(1,501))) plot(t,A(1,:)) plot(t,A(2,:)) size(A(:,ones(1,501)).*COS) B=A(:,ones(1,501)).*COS; plot(t,B(1,:)) x=sum(A(:,ones(1,501)).*COS); plot(t,x)