-
Notifications
You must be signed in to change notification settings - Fork 0
/
lti_int.m
136 lines (128 loc) · 2.64 KB
/
lti_int.m
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
%LTI_INT Integrate LTI ODE with Gaussian Noise
%
% Syntax:
% [x,P,A] = lti_int(x,P,F,L,Q,T)
%
% Description:
% Integrates LTI differential equation
%
% x' = F*x + L*w , w ~ N(0,Q)
%
% from t0=0 to t1=T or over given steps t0,t1,t2,t3,...
% Initial conditions can be in form
%
% x(t0) = x0
%
% or
%
% x(t0) ~ N(x0,P0)
%
% See also
% LTI_DISC
% History:
% 20.11.2002 The first official version.
%
% Copyright (C) 2002 Simo Särkkä
%
% $Id$
%
% This software is distributed under the GNU General Public
% Licence (version 2 or later); please refer to the file
% Licence.txt, included with the software, for details.
function [x,P,A] = lti_int(x,P,F,L,Q,T)
%
% Check number of arguments
%
if nargin < 3
error('Too few arguments');
end
if nargin < 4
L = [];
end
if nargin < 5
Q = [];
end
if nargin < 6
T = [];
end
%
% Integrate one or many steps
%
if length(T) > 1
%
% Handle multiple time steps recursively
%
if isempty(P)
if isempty(x)
%
% No x or P given, return only A's
%
tA = eye(size(x,1));
A = zeros(size(x,1),size(x,1),length(T));
A(:,:,1) = tA;
for i=2:length(T)
[tx,tP,tA] = lti_int([],[],F,L,Q,T(i)-T(i-1));
A(:,:,i) = tA;
end
else
%
% Only x given, returns x's and A's
%
tx = x;
tA = eye(size(x,1));
x = zeros(size(x,1),length(T));
A = zeros(size(x,1),size(x,1),length(T));
x(:,1) = tx;
A(:,:,1) = tA;
for i=2:length(T)
[tx,tP,tA] = lti_int(tx,[],F,L,Q,T(i)-T(i-1));
x(:,i) = tx;
A(:,:,i) = tA;
end
end
else
%
% Both x and P given, return all
%
tx = x;
tP = P;
tA = eye(size(x,1));
x = zeros(size(x,1),length(T));
P = zeros(size(x,1),size(x,1),length(T));
A = zeros(size(x,1),size(x,1),length(T));
x(:,1) = tx;
P(:,:,1) = tP;
A(:,:,1) = tA;
for i=2:length(T)
[tx,tP,tA] = lti_int(tx,tP,F,L,Q,T(i)-T(i-1));
x(:,i) = tx;
P(:,:,i) = tP;
A(:,:,i) = tA;
end
end
else
%
% One step integration from 0 to T
%
if isempty(L)
L = eye(size(x,1));
end
if isempty(Q)
Q = zeros(size(x,1),size(x,1));
end
if isempty(T)
T = 1;
end
%
% Closed form integration of mean
%
A = expm(F*T);
x = A*x;
%
% Runge-Kutta Integration of Covariance
%
if ~isempty(P) & (nargout > 1)
f = inline('F*P+P*F''+L*Q*L','P','t','F','L','Q');
P = rk(f,P,0,T,F,L,Q);
end
end