forked from orcioni/Volterra2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swapassess.m
executable file
·69 lines (62 loc) · 2.29 KB
/
swapassess.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
% function swap=swapassess(N,swaptable)
% It should be used in combination with a swap table obtained with demo/swaptest
% script which generates a swaptable.mat containing a swaptable array, made
% of two columns the first of which being the vector of input lengths and the the
% second being the corresponding swap values obtained, example:
% swaptable =
%
% 100 2
% 500 4
% 1000 5
% 5000 25
% 10000 31
% 50000 17
% 100000 10
% 500000 10
% 1000000 9
%
% swaptable can be the pathname of file containing swaptable array
% or a swaptable array ready to be used
% N is the input length for which a swap value is desired
% swap is then obtained by linear interpolation of the values in swaptable,
% if N it's in the interval [swaptable(1,1), swaptable(end,1)], or
% using the extremes values otherwise
%
% If you want to contact the authors, please write to [email protected],
% or Simone Orcioni, DII, Università Politecnica delle Marche,
% via Brecce Bianche, 12 - 60131 Ancona, Italy.
% Copyright (C) 2006 Massimiliano Pirani
%
% 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 2 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, write to the Free Software Foundation, Inc.,
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
function swap=swapassess(N,swaptable)
if ischar(swaptable)
swaptablefile=swaptable;
F=load(swaptablefile);
swaptable=F.swaptable;
clear F;
end
S=size(swaptable);
if S(2)~=2, error('wrong size of swaptable array'),end
x=swaptable(:,1);
y=swaptable(:,2);
if N>=x(end)
swap=round(y(end));
elseif N<=x(1)
swap=round(y(1));
else
xi=1:x(end);
yi=interp1(x,y,xi,'linear');
swap=round(yi(N));
end