-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetSubSampInter.m
42 lines (40 loc) · 1 KB
/
getSubSampInter.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
function int = getSubSampInter(f,v,x)
if nargin < 3
x = 1:length(f);
end
order = 1;
if length(f) ~= length(x)
int = 0;
else
ind = find(f-v < 0);
if ind == 1
int = x(1);
elseif ind == length(f)
int = x(end);
else
ind = ind(1)-1;
% linear interpolation
x2 = x(ind:ind+1)';
f2 = f(ind:ind+1)';
M = [];
for k = order:-1:0
M = [M, x2.^k];
end
coef = M\f2;
if numel(coef) == 2
int = (v-coef(2))/coef(1);
else
int = (-coef(2) + sqrt(coef(2).^2-4*coef(1)*(coef(3)-v)))/(2*coef(1));
end
% figure(34256);
% plot(x2,f2); hold on;
% x3 = linspace(x2(1),x2(3),100);
% f3 = zeros(1,numel(x3));
% for k = 1:numel(coef)
% f3 = f3 + coef(k).*x3.^(numel(coef)-k);
% end
% plot(x3,f3);
% plot([int int],[min(f3) max(f3)],'--k')
% hold off
end
end