Control Systems Assignment
Control Systems Assignment
ASSIGNMENT
NAME: P. L. P. ISHIKA
Elements of A:
B = [5, 5, 6;
20, 1, 6;
25, 6, 12];
% (a) Computations
disp('Size of A:');
disp(size(A))
disp('A + B =');
disp(A + B)
disp('A - B =');
disp(A - B)
disp('A / B =');
disp(A / B)
disp('Inverse of A (inv(A)) =');
disp(inv(A))
disp('A + i*B =');
disp(A + 1i*B)
% (b) Matrix multiplications and transpositions
disp('A * B =');
disp(A * B)
disp('Transpose of A (A'') =');
disp(A.')
disp('Transpose of B (B'') =');
disp(B.')
disp('A'' * B'' =');
disp(A.' * B.');
disp('A^2 =');
disp(A^2);
disp('(A'')^2 =');
disp((A.')^2);
% (c) Special matrices
n = 3;
disp('Identity matrix eye(n):');
disp(eye(n));
disp('Zero matrix zeros(n):');
disp(zeros(n));
disp('Ones matrix ones(n):');
disp(ones(n));
disp('Diagonal matrix diag(1:n):');
disp(diag(1:n));
disp('Random matrix rand(n):');
disp(rand(n));
OUTPUT:
OUTPUT:
2 . Write a MATLAB program to solve a quadratic equation 𝑎𝑥2 +
𝑏𝑥 + 𝑐 = 0 for any values of a, b and c.
CODE:
a = input('Enter the value of a: ');
b = input('Enter the value of b: ');
c = input('Enter the value of c: ');
if a == 0
disp('This is not a quadratic equation (a = 0).');
else
D = b^2 - 4*a*c ;
fprintf('D = %.2f\n', D);
if D > 0
root1 = (-b + sqrt(D)) / (2*a);
root2 = (-b - sqrt(D)) / (2*a);
fprintf('The roots are real and distinct:\n');
fprintf('Root 1 = %.2f\n', root1);
fprintf('Root 2 = %.2f\n', root2);
elseif D == 0
root = -b / (2*a);
fprintf('The roots are real and equal:\n');
fprintf('Root = %.2f\n', root);
else
realPart = -b / (2*a);
imagPart = sqrt(-D) / (2*a);
fprintf('The roots are complex and imaginary:\n');
fprintf('Root 1 = %.2f + %.2fi\n', realPart, imagPart);
fprintf('Root 2 = %.2f - %.2fi\n', realPart, imagPart);
end
end
OUTPUT:
(i)
CODE:
N = 136 ;
h = pi/N;
x = 0: h: pi ;
y = sin(x) ;
plot(x,y)
text(2, 0.9, 'Name: Ishika', 'FontSize', 11, 'Color', 'black')
text(2, 0.8, 'Roll No: AM.EN.U4ECE23136', 'FontSize', 11,
'Color', 'black')
OUTPUT:
(ii)
CODE:
N = 136;
h = pi/N;
x = 0:h:2*pi;
plot(x, sin(x), 'r-.', x, cos(x), 'g--')
legend('sine', 'cosine');
grid
xlabel('x');
ylabel('functions');
title('Test of multi-plot option in Matlab');
text(2, 0.9, 'Name: Ishika', 'FontSize', 11, 'Color', 'black')
text(2, 0.8, 'Roll No: AM.EN.U4ECE23136', 'FontSize', 11,
'Color', 'black')
OUTPUT:
(iii)
CODE:
N = 136;
h = 2*pi/N;
x = 0:h:2*pi;
subplot(1,2,2);
plot(x, cos(x));
xlabel('x');
ylabel('cosine');
title('Cosine Function');
grid on
subplot(1,2,1);
plot(x, sin(x));
xlabel('x');
ylabel('sine');
title('Sine Function');
grid on
text(4, 0.4, 'Name: Ishika', 'FontSize', 10, 'Color', 'black')
text(4, 0.3, 'Roll No: AM.EN.U4ECE23136', 'FontSize', 10,
'Color', 'black')
OUTPUT:
CODE:
x = 0 : 0.1 : 3*pi;
y = sin(x);
y_half = y;
y_half(y_half < 0) = 0;
plot(x, y_half, 'r', 'LineWidth', 2);
xlabel('x (radians)')
ylabel('Half-wave rectified sin(x)');
title('Half-Wave Rectified Sine Wave');
grid on;
text(3.5, 0.4, 'Name: Ishika', 'FontSize', 10, 'Color', 'black')
text(3.5, 0.3, 'Roll No: AM.EN.U4ECE23136', 'FontSize', 10, 'Color',
'black')
OUTPUT:
5.
CODE :
zeta = 0.4;
wn = 5;
num = wn^2;
den = [1 2*zeta*wn wn^2];
G = tf(num, den);
figure;
step(G);
title('Unit Step Response of Second Order System (ζ = 0.4, ωn = 5
rad/s)');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
name = 'Ishika';
roll_number = 'AM.EN.U4ECE23136';
text(1, 0.8, ['Name: ' name ', Roll No: ' roll_number], 'FontSize', 12, 'Color',
'blue');
OUTPUT:
6.
CODE:
syms s
num= 25;
den=[1 6 25];
system = tf(num,den) ;
step(system)
stepinfo(system)
title('Step Response');
text(0.8, 0.4, 'Name: Ishika', 'FontSize', 10, 'Color', 'black')
text(0.8, 0.3, 'Roll No: AM.EN.U4ECE23136', 'FontSize', 10, 'Color', 'black')
OUTPUT:
7.
CODE:
syms s
num= 1;
den=[1 0.2 1];
system = tf(num,den) ;
impulse(system)
title('Impulse Response');
name = 'Ishika';
roll_number = 'AM.EN.U4ECE23136';
text(3, 0.8, ['Name: ' name ', Roll No: ' roll_number], 'FontSize',
12, 'Color', 'blue');
OUTPUT:
8. Write a MATLAB program to obtain the step response of the
given electrical system (RLC series circuit). Given R = 1000 ohms,
L =1 H, C= 0.1µF. Determine all the time domain specifications of
the system. Obtain the plots for different damping ratios by
changing the value of R to 200 Ω , 600 Ω, and 1200 Ω ( Plots with
different colours on the same graph sheet). (Hint: Derive the TF
of a RLC series circuit, and substitute the values of R, L and C.
Use step(sys) to obtain the step response of the system. See Help
step in MATLAB)
CODE:
L = 1;
C = 0.0000001;
num = 25;
R_values = [200, 600, 1000 ,1200];
figure;
hold on;
for i = 1:length(R_values)
R = R_values(i);
den = [L*C, R*C, 1];
system = tf(num, den);
[y,t] = step(system);
plot(t, y, 'DisplayName', ['R = ' num2str(R) ' \Omega']);
info = stepinfo(system);
fprintf('Step response characteristics for R = %d Ohms:\n', R);
fprintf(' Rise Time: %f seconds\n', info.RiseTime);
fprintf(' Settling Time: %f seconds\n', info.SettlingTime);
fprintf(' Overshoot: %f%%\n', info.Overshoot);
fprintf(' Peak: %f\n', info.Peak);
fprintf(' Peak Time: %f seconds\n\n', info.PeakTime);
end
legend show;
title('Step Responses for Different R Values');
xlabel('Time (seconds)');
ylabel('Output');
hold off;
text(0.04, 8, 'Name: Ishika', 'FontSize', 10, 'Color', 'black')
text(0.04, 5, 'Roll No: AM.EN.U4ECE23136', 'FontSize', 10, 'Color', 'black')
OUTPUT:
9.
IN MATLAB:
CODE:
num = 1;
den = conv([1 0], conv([0.2 1], [1 1]));
G = tf(num, den);
t = 0:0.01:10;
step(G, t);
title('Step Response using MATLAB');
xlabel('Time (seconds)');
ylabel('Amplitude');
grid on;
text(5, 2, 'Name: Ishika', 'FontSize', 10, 'Color', 'black')
text(5, 1, 'Roll No: AM.EN.U4ECE23136', 'FontSize', 10, 'Color', 'black')
OUTPUT:
IN SIMULINK:
MODEL:
OUTPUT:
10.
IN MATLAB:
CODE:
OUTPUT:
IN SIMULINK:
MODEL:
OUTPUT: