]> gitweb.michael.orlitzky.com - octave.git/blob - fixed_point_method.m
Add ellipses on a multi-line statement.
[octave.git] / fixed_point_method.m
1 function [fixed_point, iterations] = fixed_point_method(g, epsilon, x0)
2 % Find a fixed_point of the function `g` with initial guess x0.
3 %
4 % INPUTS:
5 %
6 % * ``g`` - The function to iterate.
7 %
8 % * ``epsilon`` - We stop when two successive iterations are within
9 % epsilon of each other, taken under the infinity norm. halt the
10 % search and return the current approximation.
11 %
12 % OUTPUTS:
13 %
14 % * ``fixed_point`` - The fixed point that we found.
15 %
16 % * ``iterations`` - The number of iterations that we performed
17 % during the search.
18 %
19
20 iterations = 0;
21 prev = x0;
22 current = g(x0);
23
24 while (norm(current - prev, Inf) > epsilon)
25 prev = current;
26 current = g(current);
27 iterations = iterations + 1;
28 end
29
30 fixed_point = current;
31 end