summaryrefslogtreecommitdiff
path: root/3432/CH7/EX7.18/Ex7_18.sce
blob: 5be65a2a617ce92c7e170588882e3511f66271d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//Example 7.18
//Introducing the reference input.

xdel(winsid())//close all graphics Windows
clear;
clc;
//------------------------------------------------------------------
//Pendulum state model;
w0=1;

F=[0 1;-w0^2 0];
G=[0 1]';
H=[1 0]; //representing x1 and x2 states as outputs
J=0;
n=sqrt(length(F));

//computing state feedback matrix to place poles at [-2 -2]
exec('./acker_dk.sci', -1);
K=acker_dk(F,G,[-2, -2]);
//------------------------------------------------------------------
//augmented matrix for tracking the reference
A=[F G;H J];
N=A\[zeros(1,n) 1]';
Nx=N(1:n);
Nu=N(n+1);

//feedforward gain (input weight)
Ntilde=Nu+K*Nx;

//------------------------------------
//Alternately, it can be computed as /
Ntilde1=-inv(H*inv(F-G*K)*G); //     /
//------------------------------------

//Closed loop system and step response
syscl=syslin('c',(F-G*K),G*Ntilde,H,J); //closed loop system

t=0:0.1:7;
[y x]=csim('step',t,syscl); //closed loop response
plot(t',x');

u=-K*x+Ntilde;
plot(t',u'/4,'r--'); //control law u plot (scaled to 1/4 in figure);
legend("x1","x2","u/4");
xset('font size',3);
xstring(5,0.93,"$x_{ss}$")
xstring(5,0.25,"$u_{ss}$")

//Title, labels and grid to the figure
exec .\fig_settings.sci; //custom script for setting figure properties
title('Step response of undamped oscillator to reference input',...
'fontsize',3);
xlabel('Time t (sec.)','fontsize',2);
ylabel('Amplitude','fontsize',2);

//------------------------------------------------------------------