1% Computes diagnostics for the analysis.
2%
3% [Jb,Jo,Jeof,J] = divand_diagnose(s,fi,d)
4%
5% Computes the value of different terms of the cost-function
6%
7% Input:
8%   s: structure created by divand_solve
9%   fi: analysis
10%   d: observations
11%
12% Output:
13%   Jb: background constrain
14%   Jeof: observation constrain
15%   Jeof: EOF constrain
16
17function [Jb,Jo,Jeof,J] = divand_diagnose(s,fi,d)
18
19d = s.yo;
20xa = statevector_pack(s.sv,fi);
21
22Jb = xa' * s.iB * xa - s.betap * (s.WE'*xa)' * (s.WE'*xa);
23Jo = (s.H*xa - d)' * (s.R \ (s.H*xa - d));
24
25if all(s.EOF_lambda == 0)
26  Jeof = 0;
27else
28  Jeof = s.betap * ((s.WE'*xa)' * (s.WE'*xa)) - (s.E'*xa)' * (s.E'*xa);
29end
30
31Jo = full(Jo);
32
33J = Jb + Jo + Jeof;
34% Copyright (C) 2014 Alexander Barth <a.barth@ulg.ac.be>
35%
36% This program is free software; you can redistribute it and/or modify it under
37% the terms of the GNU General Public License as published by the Free Software
38% Foundation; either version 2 of the License, or (at your option) any later
39% version.
40%
41% This program is distributed in the hope that it will be useful, but WITHOUT
42% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
44% details.
45%
46% You should have received a copy of the GNU General Public License along with
47% this program; if not, see <http://www.gnu.org/licenses/>.
48