Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
12 views

CS2ASSIGNMENT

The document discusses control system assignments involving state space models. It provides MATLAB code to analyze and simulate systems using different methods like unit step response, Euler integration, Runge-Kutta, and ODE solvers. It also covers topics like controllability, observability, controller and observer design.

Uploaded by

alokb210846ee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

CS2ASSIGNMENT

The document discusses control system assignments involving state space models. It provides MATLAB code to analyze and simulate systems using different methods like unit step response, Euler integration, Runge-Kutta, and ODE solvers. It also covers topics like controllability, observability, controller and observer design.

Uploaded by

alokb210846ee
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

ALOK P

B210846EE

CONTROL SYSTEMS ASSIGNMENT


Q1:-

For me, p=Root(84.6)=9.19


MATLAB CODE:-
%putting down the matrix

A = [-1 0 9.19; 1 -2 0; -1 0 -3];


B = [0; 0; 1];
C = [1 0 0;];
D = [0];

%------------ Unit step

system = ss(A,B,C,D);
figure;
step(system);

%------------Euler method

% Initially relaxed
x0 = [0; 0; 0]; % Initial state

% Define the time vector


dt = 0.1;
t = 0:dt:10;

u = ones(size(t)); % Unit step input


x = zeros(3, length(t));
x(:, 1) = x0;
% Perform Euler's integration
for i = 3:length(t)
x(:, i) = x(:, i-1) + dt * (A * x(:, i-1) + B * u(i-1));
end

% Compute the output


y=C*x;

plot(t, y);
xlabel('Time');
ylabel('Output');
title('Output response using Euler''s integration');

%---------------------Runge-Kutta approximation
dt = 0.1;
t = 0:dt:10;

%unit step already defined

x = zeros(3, length(t));

x(:, 1) = x0;

% Runge-Kutta 4th order approximation


for i = 3:length(t)
k1 = dt * (A * x(:, i-1) + B * u(i-1));
k2 = dt * (A * (x(:, i-1) + k1/2) + B * u(i-1));
k3 = dt * (A * (x(:, i-1) + k2/2) + B * u(i-1));
k4 = dt * (A * (x(:, i-1) + k3) + B * u(i-1));

x(:, i) = x(:, i-1) + (k1 + 2*k2 + 2*k3 + k4) / 6;


end

% Compute the output


y = C * x;
% Plot the output
figure;
plot(t, y);
xlabel('Time');
ylabel('Output');
title('Output response using Runge-Kutta 4th order approximation');

%------------------ODE Method

function dx_dt = state_space_eq(t, x)


u = heaviside(t); % Unit step input signal
A = [-1 0 9.19; 1 -2 0; -1 0 -3];
B = [0; 0; 1];
dx_dt = A*x + B*u;
end

% Define initial condition


x0 = [0; 0; 0]; % Initial state

% Define time span


tspan = [0 10]; % Time span from 0 to 10 seconds

% Solve the state-space equations using ode45


[t, x] = ode45(@state_space_eq, tspan, x0);

% Compute the output


y= [];
for i = 1:101
y = [y,C*(x(i,:).')];
end

% Plot the output


figure;
plot(t, y);
xlabel('Time');
ylabel('Output');
title('Output response using ODE solver');
%------------------transfer function
func_trans = tf(system)

a) Unit step response:-

b)
i.

ii.
iii.

Comparing the unit step response of the system and output


response by different methods, all of the response looks similar!.
c)

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

% Define the time vector


t = 0:0.1:20; % Time span

u = ones(size(t));

sys = ss(A, B, C, D);


[y, t, x] = lsim(sys, u, t, x0);

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

% Define the time vector


dt = 0.1;
t = 0:dt:20;
x = zeros(2, length(t));
x(:, 1) = x0;

% Perform Euler's integration


for i = 2:length(t)
x(:, i) = x(:, i-1) + dt * (A * x(:, i-1) + B * u(i-1));
end

% Compute the output


y = C * x;

% Plot the output


figure;
plot(t, y);
xlabel('Time');
ylabel('Output');
title('Output response using Euler''s integration');

a) Output array:-
b)

c)

Comparing b and c, Both of them seems similar!!!


Q3:-

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:-

Here Rank = 3 = n, There it is Controllable.

Here Rank = 2!= n,There it is not observable.


Q4:-

For me, a=8


CODE:-
A=[1 1 0; 0 1 0; 0 1 8];
B=[0 1; 1 0; 0 1];
C=[1 1 1];
D=0;
ctrbf(A,B,C,D)

%ctrbf(sys)
%%

obsvf(A,B,C,D)
Q5:-

For me, a=1


CODE:-
%system matrices
A = [0 1 0; 0 0 1;-1 -5 -1];
B = [0;1;1];
C = [1 0 0];
D = 0;

% Create state-space system


sys = ss(A, B, C, D);

% Plot the unit step response


figure;
step(sys);
title('Unit Step Response');

% Get step response information


info = stepinfo(sys);

% Display settling time and peak overshoot


settling_time = info.SettlingTime;
peak_overshoot = info.Overshoot;

% Display closed-loop poles


poles = pole(sys);

disp(['Settling Time: ', num2str(settling_time), ' seconds']);


disp(['Peak Overshoot: ', num2str(peak_overshoot), '%']);
disp('Closed-Loop Poles:');
disp(poles);

%-------------------Controller Design

% Desired settling time and peak overshoot


Ts = 2; % Settling time
Mp = 0.16; % Peak overshoot

% Calculate natural frequency and damping ratio


zeta = sqrt(log(Mp)^2 / (pi^2 + log(Mp)^2));
omega_n = 4 / (zeta * Ts);

% Desired closed-loop poles


desired_poles = roots([1, 2*zeta*omega_n, omega_n^2]);
%add one more pole
desired_poles = [desired_poles;8];
disp(desired_poles)

% 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);

% Display controller gain


disp('Controller Gain (K):');
disp(K);
end

%---------------New State Space Model


%with the obtained controller gain
A_closed = A - B*K;

%finding the new state space


new_state = ss(A_closed,B,C,D);

%compute the step function


step(new_state)
poles = pole(new_state);
disp("The new poles are:")
disp(poles)

%----------------------Observer Design

% Desired observer eigenvalues


observer_eigenvalues = [-10, -10, -15];

% Calculate the observer gain using pole placement


L = acker(A', C', observer_eigenvalues)';

% Display the observer gain


disp('Observer Gain:');
disp(L);

%-----------------System Response

% Time vector
t = 0:0.01:10; % Define time span (0 to 10 seconds)

% Input signal (for example, a unit step)


u = ones(size(t));

% Initial conditions

x0 = [0;0;0]; % Assuming zero initial conditions

% Simulate the response of the closed-loop system


[y, t, x] = lsim(new_state, u, t, x0);

% Plot the output response


figure;
plot(t, y);
xlabel('Time (seconds)');
ylabel('Output');
title('System Response with State Feedback Controller');
a)

b)

c)
d)
e)

f)
Comparing c) and e), Both seems similar.

You might also like