File: example_optiminterp.m

package info (click to toggle)
octave-optiminterp 0.3.5-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 344 kB
  • sloc: f90: 299; makefile: 167; cpp: 92; sh: 2
file content (67 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (5)
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
%% Copyright (C) 2008 Alexander Barth <barth.alexander@gmail.com>
%%
%% This program is free software; you can redistribute it and/or modify it under
%% the terms of the GNU General Public License as published by the Free Software
%% Foundation; either version 3 of the License, or (at your option) any later
%% version.
%%
%% This program is distributed in the hope that it will be useful, but WITHOUT
%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
%% details.
%%
%% You should have received a copy of the GNU General Public License along with
%% this program; if not, see <http://www.gnu.org/licenses/>.

% Example program of the optimal interpolation toolbox


% the grid onto which the observations are interpolated

[xi,yi] = ndgrid(linspace(0,1,100));

% background estimate or first guess
xb = 10 + xi;

% number of observations to interpolate

on = 200;

% create randomly located observations within 
% the square [0 1] x [0 1]

x = rand(1,on);
y = rand(1,on);

% the underlying function to interpolate

yo = 10 + x + sin(6*x) .* cos(6*y);

% the error variance of the observations divided by the error 
% variance of the background field

var = 0.1 * ones(on,1);

% the correlation length in x and y direction

lenx = 0.1;
leny = 0.1;

% number of influential observations

m = 30;

% subtract the first guess from the observations
% (DON'T FORGET THIS - THIS IS VERY IMPORTANT)

Hxb = interp2(xi(:,1),yi(1,:),xb',x,y);
f = yo - Hxb;

% run the optimal interpolation
% fi is the interpolated field and vari is its error variance

[fi,vari] = optiminterp2(x,y,f,var,lenx,leny,m,xi,yi);

% Add the first guess back

xa = fi + xb;