CS2ASSIGNMENT
CS2ASSIGNMENT
B210846EE
system = ss(A,B,C,D);
figure;
step(system);
%------------Euler method
% Initially relaxed
x0 = [0; 0; 0]; % Initial state
plot(t, y);
xlabel('Time');
ylabel('Output');
title('Output response using Euler''s integration');
%---------------------Runge-Kutta approximation
dt = 0.1;
t = 0:dt:10;
x = zeros(3, length(t));
x(:, 1) = x0;
%------------------ODE Method
b)
i.
ii.
iii.
d)
Q2:-
CODE:-
% Define the state-space matrices
A = [0, -1; 3, -4]; % State transition matrix
B = [1;1]; % Input matrix
C = [2, 3]; % Output matrix
D = 0;
% Initial condition
x0 = [0; 1]; % Initial state
u = ones(size(t));
disp("Solution-")
disp(x) %getting the required solution
disp("Output-")
disp(y) %finding the output
plot(t,y)
xlabel('Time');
ylabel('Output');
title('Output response to Unit Step Input')
%---------------------------------EULERS INTEGRATION
a) Output array:-
b)
c)
CODE:-
Here p=2 for me
A=[2 1 1; -2 3 6; -2 -1 -4];
B=[1; 0; 0];
C=[1 2 2];
D=0;
sys=ss(A,B,C,D);
Co=ctrb(sys)
rank(Co)
%% Section break
Ob=obsv(sys)
rank(Ob)
output:-
%ctrbf(sys)
%%
obsvf(A,B,C,D)
Q5:-
%-------------------Controller Design
% Check controllability
if rank(ctrb(A, B)) ~= size(A, 1)
disp('System not fully controllable!');
else
% Compute gain matrix using pole placement
K = place(A, B, desired_poles);
%----------------------Observer Design
%-----------------System Response
% Time vector
t = 0:0.01:10; % Define time span (0 to 10 seconds)
% Initial conditions
b)
c)
d)
e)
f)
Comparing c) and e), Both seems similar.