clear all; close all; clc; %% help help eig %% Commands concerning matrix manipulation % Building matrix A=[1 2; 3 4]; B=eye(2); C=ones(2,2); D=zeros(2); F=diag(ones(3,1)); G=tril(ones(4,4),-1); % Matrix operations Add=A+B; Multi=A*B; Power=A^2; Element_power=A.^2; Tran=A'; % Matrix functions determinant=det(A); Rank=rank(A); Inverse=inv(A); Eigenvalue=eig(A); %% Define transfer funcions in different form num=[3 12]; den=[1 11 10]; % Find TF of system sys=tf(num,den); % Find TF of system in state space form sys1=ss(sys); % Find TF of system in Zero/pole/gain form sys2=zpk(sys); % Plot the poles and zeros in a complex plane pzmap(sys); %% Useful command to deal with polynomials %Convert between partial fraction expansion and polynomial coefficients [r p k]=residue(num,den); % Inverse Laplace transform syms s; sys3=(3*s+12)/(s^2+11*s+10); y_t=ilaplace(sys2); zeros=roots(num); poles=roots(den); %% Simulate LTI system % Impulse input impulse(sys); % Step input step(sys); % Other inputs t=0:1:1000; lsim(sys,t,t); % ramp input lsim(sys,sin(0.05*t),t); % sinusoidal input lsim(sys,t.^2,t) % input is t^2 %% Bode plot bode(sys); margin(sys); % plot the root locus of system rlocus(sys); %% Create and plot signals y=sin(0.05*t); plot(t,y,'rd'); % plot the signal with red color and diamond marker y1=t.^2; plot(t,y1,'b.'); % plot the signal with blue color and dot marker % plot the figure in 3 dimensional coordinate t1 = 0:pi/50:10*pi; plot3(sin(t1),cos(t1),t1) grid on axis square % Use surface command to plot 3-d figure x=-3:.2:3; y=-3:.2:3; [X,Y]=meshgrid(x,y); Z=X.^2+Y.^2; mesh(X,Y,Z); % contour figure contour(X,Y,Z); colorbar;