X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=fixed_point_method.m;fp=fixed_point_method.m;h=c28a66e7e88d46e91e971234055b84d454a829d9;hp=0000000000000000000000000000000000000000;hb=13bba59d9d3cc9a508deef1e0f6176cfab73fbcd;hpb=9fb5a1527f1ea90f9074b6e318791e0cc43e18f7 diff --git a/fixed_point_method.m b/fixed_point_method.m new file mode 100644 index 0000000..c28a66e --- /dev/null +++ b/fixed_point_method.m @@ -0,0 +1,31 @@ +function [fixed_point, iterations] = fixed_point_method(g, epsilon, x0) + ## Find a fixed_point of the function `g` with initial guess x0. + ## + ## INPUTS: + ## + ## * ``g`` - The function to iterate. + ## + ## * ``epsilon`` - We stop when two successive iterations are within + ## epsilon of each other, taken under the infinity norm. halt the + ## search and return the current approximation. + ## + ## OUTPUTS: + ## + ## * ``fixed_point`` - The fixed point that we found. + ## + ## * ``iterations`` - The number of bisections that we performed + ## during the search. + ## + + iterations = 0; + prev = x0; + current = g(x0); + + while (norm(current - prev, Inf) > epsilon) + prev = current; + current = g(current); + iterations = iterations + 1; + end + + fixed_point = current; +end