-
Notifications
You must be signed in to change notification settings - Fork 0
/
interpolation.m
executable file
·32 lines (29 loc) · 1.08 KB
/
interpolation.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
%% function to generate next choose of alpha by
%% quadratic interpolation
function alpha = interpolation(f_a, df_a, f_b, a, b, a1, b1, alpha);
za1 = f_a + df_a*(a1 - a) + (f_b - f_a - (b-a)*df_a)*(a1 - a)*(a1 - a)/((b - a)*(b - a));
zb1 = f_a + df_a*(b1 - a) + (f_b - f_a - (b-a)*df_a)*(b1 - a)*(b1 - a)/((b - a)*(b - a));
if za1 < zb1; endptmin = a1;
else endptmin = b1; end;
root = a - (b-a)*(b-a)*df_a/(2*(f_b - f_a - (b-a)*df_a));
if f_b - f_a - (b-a)*df_a < 0; %% Opens downward.
if a1 < b1;
if a1 <= root & root <= b1; alpha = endptmin; end;
if root < a1; alpha = b1; end;
if root > b1; alpha = a1; end;
else;
if b1 <= root & root <= a1; alpha = endptmin; end;
if root < b1; alpha = a1; end;
if root > a1; alpha = b1; end;
end;
else; %% Opens upward.
if a1 < b1;
if a1 <= root & root <= b1; alpha = root; end;
if root < a1; alpha = a1; end;
if root > b1; alpha = b1; end;
else;
if b1 <= root & root <= a1; alpha = root; end;
if root < b1; alpha = b1; end;
if root > a1; alpha = a1; end;
end;
end;