-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdual.m
More file actions
28 lines (23 loc) · 676 Bytes
/
Copy pathdual.m
File metadata and controls
28 lines (23 loc) · 676 Bytes
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
function [pM] = dual(p0, A, B, tout)
% dualApp receives the adjoint state at time t = T and returns the dual
% solutions average in the parameter space
% Number of time steps
Nt = length(tout);
% Size of parameter space
M = size(A, 3);
% Adjoint variable average: 1/N*sum_i(B*pout(t, nu(i)))
pM = zeros(Nt, 1);
% Solve adjoint problem forward in time for every parameter in nu
for j = 1:M
% Update matrix A
Am = A(:, :, j);
% Update matrix B
Bm = B(:, :, j);
% Solve adjoint problem forward in time
[tout, pout] = ode45(@(t, p) Am'*p, tout, -p0);
pM = pM + pout*Bm;
end
pM = -pM/M;
% Reverse adjoint variable in time
pM = flipud(pM);
end