Page

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Example: 42 The equations the nonlinear motion of a mechanical oscillator is

𝑦̈ (𝑡) + 2𝑦(𝑡) + sin(𝑦(𝑡)) = 𝑢(𝑡) 𝑦(0) = 0 𝑦̇ (0) = 1


The objective is to linearize the model around the following nominal trajectory
𝑦𝑛 (𝑡) = 1 − 𝑒 −𝑡 which leads to the nominal control trajectory

𝑢𝑛 (𝑡) = 𝑦̈𝑛 (𝑡) + 2𝑦𝑛 (𝑡) + sin(𝑦𝑛 (𝑡)) = 2 + sin(1 − 𝑒 −𝑡 ) − 3𝑒 −𝑡


Here is the MATLAB code for the numerical linearization of the given nonlinear
oscillator around this nominal trajectory.
clear, clc, function dx=Linear(A,B,xd,up,t), dx=A*xd+B*up; end
function [A,B]=linearizedesys(f,x0,u0)
n=size(x0,1);m=size(u0,1);h=0.001;
In=eye(n,n);Im=eye(m,m); A=zeros(n,n);B=zeros(n,m);
for k=1:n, A(:,k)=(f(x0+h*In(:,k),u0)-f(x0,u0))/h; end
for k=1:m, B(:,k)=(f(x0,u0+h*Im(:,k))-f(x0,u0))/h; end
end
dt=0.01; t=0:dt:10; x(:,1)=[0; 1]; xd(:,1)=[0; 0];
f=@(x,u)[x(2);-2*x(1)-sin(x(1))+u]; % The Nonlinear Model
for k=1:length(t)-1
un(k)=2+sin(1-exp(-t(k)))-3*exp(-t(k)); % The nominal control
du(k)=0.2*(1+sign(sin(100*t(k)))); % The input perturbation
u(k)=un(k)+du(k); x(:,k+1)=x(:,k)+dt*f(x(:,k),u(k));
xn(:,k)=[1-exp(-t(k));exp(-t(k))]; % Nominal state trajectory
[A,B]=linearizedesys(f,xn(:,k),un(k)); % Numerical linearization
xd(:,k+1)=xd(:,k)+dt*Linear(A,B,xd(:,k),du(k),t(k));
xl(:,k)=xn(:,k)+xd(:,k);
end
figure, subplot(2,1,1), plot(t, x(1,:),'-r','linewidth',1.5),
grid on, hold on, plot(t(1:end-1),xl(1,:),'--b','linewidth',1.5),
subplot(2,1,2), plot(t(1:end-1),u,'linewidth',1.5)

Comparision Study

Nonlinear 𝑦
scope
system

+ 𝛿𝑢 Linearized 𝛿𝑦
𝑢 system + mux
− +

𝑢𝑛 𝑦𝑛
From storage From storage
Let we design a state feedback controller 𝛿𝑢 = −𝐾. 𝛿𝑦 and we try to do a comparision
study with the nonlinear results

clear, clc, function dx=Linear(A,B,xd,up,t), dx=A*xd+B*up; end


function [A,B]=linearizedesys(f,x0,u0)
n=size(x0,1);m=size(u0,1);h=0.001;
In=eye(n,n);Im=eye(m,m); A=zeros(n,n);B=zeros(n,m);
for j=1:n, A(:,j)=(f(x0+h*In(:,j),u0)-f(x0,u0))/h; end
for j=1:m, B(:,j)=(f(x0,u0+h*Im(:,j))-f(x0,u0))/h; end
end
function du=control(A,B,xd), du=-place(A,B,[-1, -2])*xd; end

dt=0.01; t=0:dt:10; x(:,1)=[0; 1]; xd(:,1)=[0.002 0.001];


f=@(x,u)[x(2);-2*x(1)-sin(x(1))+u]; % The Nonlinear Model

for k=1:length(t)-1
un(k)=2+sin(1-exp(-t(k)))-3*exp(-t(k)); % The nominal control
xn(:,k)=[1-exp(-t(k));exp(-t(k))]; % Nominal state trajectory
[A,B]=linearizedesys(f,xn(:,k),un(k)); % Numerical linearization
du(k)=control(A,B,xd(:,k)); % State Feedback Control
u(k)=un(k)+du(k); x(:,k+1)=x(:,k)+dt*f(x(:,k),u(k));
xd(:,k+1)=xd(:,k)+dt*Linear(A,B,xd(:,k),du(k),t(k));
xl(:,k)=xn(:,k)+xd(:,k);
end
figure, subplot(2,1,1), plot(t, x(1,:),'-r','linewidth',1.5),
grid on, hold on, plot(t(1:end-1),xl(1,:),'--b','linewidth',1.5),
subplot(2,1,2), plot(t(1:end-1),u,'-b','linewidth',1.5)
figure, plot(t, xd(1,:),'-r','linewidth',1.5), grid on

Nonlinear control Problem

From storage
𝑢𝑛

+ 𝑢 Nonlinear 𝑦
scope
system
+
𝛿𝑢

Linearized 𝛿𝑦
system + mux
+
𝛿𝑢
−K 𝑦𝑛
From storage

You might also like