File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments