You are on page 1of 3

Assignment #02

Submitted to:
Dr. Muhammad Rehan

Submitted by:
Raheel Aslam
Muhammad Hayyan Mehmood

Subject:
Adaptive Control

Class:
MSSE (2021-2023)

Department of Electrical Engineering


Pakistan Institute of Engineering and Applied Sciences
Simple_ode Code:
function dx=simple_ode(t,x)
dx=zeros(9,1);
A=[0 0 0 1; 19.5 0 -19.5 0; 0 1 0 0; -48.6 0 48.6 -1.25];
%x=transpose(x);
phi1=[0; 0; 0; 0];
phi2= -15.86*sin(x(3));
phi2cap= -15.86*sin(x(7));
B=[0;1;0;0];
C=[1 0 0 0; 0 1 0 0];
y=C*x(1:4);
zeta=177.26;
L=[-7.618 -2.213; -2.213 -46.23; -5.606 -1.628; -18.8 -5.464];
lemda=5;
T=[-1.129 3.8880];
if t<=1
theeta=0.25;
elseif t>1 && t<=2
theeta=1.5;
else
theeta=0.75;
end

%xp=x(1), xm=x(2), theta=x(3)and k=x(4)


u=sin(2*pi*t);
psi=[0;0;0;21.6*u];
phi=phi1+ B.*phi2.*theeta;
phicap=phi1+ B.*phi2cap.*x(9);
dx(1:4)=A*x(1:4)+psi+phi;
dx(5:8)=A*x(5:8)+psi+phicap-L*(y-C*x(5:8));
dx(9)=lemda*phi2cap*T*(y-C*x(5:8));

Main Code:
clc
clear all
close all
% options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
[T,x] = ode45(@simple_ode,[0 2.5],[1 -1 1 5 1 -1 0 0 0.5]);
%Time [0 15] for simple case and [0 200] for time-varying parameters.

t=[0 0.5 1 1.0001 1.5 2 2.0001 2.5];


m=[0.25 0.25 0.25 1.5 1.5 1.5 0.75 0.75];

subplot(3,1,1);
plot(T,x(:,3))
hold on
plot(T,x(:,7),'-.')
xlabel('time')
title('Actual and Estimated values of the state variables and system parameter')
ylabel('State x3')
legend('Actual Value','Adaptive State Observer')

subplot(3,1,2);
plot(T,x(:,4))
hold on
plot(T,x(:,8),'-.')
xlabel('time')
ylabel('State x4')
legend('Actual Value','Adaptive State Observer','Location','southeast')
subplot(3,1,3);
plot(t,m)
hold on
plot(T,x(:,9),'-.')
xlabel('time')
ylabel('Parameter m')
legend('Actual value','Adaptive Law')

You might also like