1%% Copyright (C) 2008 Alexander Barth <barth.alexander@gmail.com> 2%% 3%% This program is free software; you can redistribute it and/or modify it under 4%% the terms of the GNU General Public License as published by the Free Software 5%% Foundation; either version 3 of the License, or (at your option) any later 6%% version. 7%% 8%% This program is distributed in the hope that it will be useful, but WITHOUT 9%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 11%% details. 12%% 13%% You should have received a copy of the GNU General Public License along with 14%% this program; if not, see <http://www.gnu.org/licenses/>. 15 16% Example program of the optimal interpolation toolbox 17 18 19% the grid onto which the observations are interpolated 20 21[xi,yi] = ndgrid(linspace(0,1,100)); 22 23% background estimate or first guess 24xb = 10 + xi; 25 26% number of observations to interpolate 27 28on = 200; 29 30% create randomly located observations within 31% the square [0 1] x [0 1] 32 33x = rand(1,on); 34y = rand(1,on); 35 36% the underlying function to interpolate 37 38yo = 10 + x + sin(6*x) .* cos(6*y); 39 40% the error variance of the observations divided by the error 41% variance of the background field 42 43var = 0.1 * ones(on,1); 44 45% the correlation length in x and y direction 46 47lenx = 0.1; 48leny = 0.1; 49 50% number of influential observations 51 52m = 30; 53 54% subtract the first guess from the observations 55% (DON'T FORGET THIS - THIS IS VERY IMPORTANT) 56 57Hxb = interp2(xi(:,1),yi(1,:),xb',x,y); 58f = yo - Hxb; 59 60% run the optimal interpolation 61% fi is the interpolated field and vari is its error variance 62 63[fi,vari] = optiminterp2(x,y,f,var,lenx,leny,m,xi,yi); 64 65% Add the first guess back 66 67xa = fi + xb; 68