Skip to content

Commit 9e92791

Browse files
committed
Add inverse_quad_interp
1 parent 4011abb commit 9e92791

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

inverse_quad_interp.m

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function [x] = inverse_quad_interp(x, func)
2+
% INVERSE_QUAD_INTERP Gives the result of interpolating the given function
3+
% by the inverse quardatic method once and can continue interpolating until
4+
% the user says to stop.
5+
%
6+
% INPUT
7+
% x: the first three x values to use for interpolating
8+
% func: the function to use
9+
%
10+
% OUTPUT
11+
% x: the final three values of x (after user says to stop interpolating)
12+
13+
keep_looping = 1;
14+
15+
while keep_looping ~= 0
16+
y = [func(x(1)) func(x(2)) func(x(3))];
17+
18+
% calculate gamma, alpha, beta
19+
gamma = (x(1) - x(3)) / (y(1) - y(3));
20+
alpha = (x(1) - x(2)) / (y(1) - y(2));
21+
beta = (alpha - gamma) / (y(2) - y(3));
22+
23+
% compute next estimates
24+
nextX = x(1) - alpha*y(1) + beta*y(1)*y(2);
25+
x = [nextX, x(1), x(2)];
26+
27+
disp(x);
28+
keep_looping = input('To stop interpolating, type 0, else 1: ');
29+
end
30+
31+
end

0 commit comments

Comments
 (0)