# Fixed Point Iteration Method in MATLAB

The fixed point iteration method is a numerical algorithm used to find the roots of a given function. It is a simple iterative method that can be used to solve a wide variety of problems in mathematics and engineering.

The basic idea behind the fixed point iteration method is to find a fixed point of the function that we are trying to solve. A fixed point of a function f(x) is a point x such that f(x) = x. In other words, a fixed point is a solution to the equation x = f(x).

The fixed point iteration method works by starting with an initial guess for the root and then using the function to generate a new guess. This process is repeated until the difference between successive guesses becomes smaller than some predetermined tolerance level.

The algorithm for the fixed point iteration method is as follows:

1. Start with an initial guess x_0 for the root of the function.
2. Calculate the new guess x_{n+1} using the formula x_{n+1} = f(x_n).
3. Repeat step 2 until the difference between successive guesses is less than some tolerance level.
4. The final value of x is an approximation to the root of the function.

The convergence of the fixed point iteration method depends on the function and the initial guess. If the function has a fixed point that is attractive, meaning that the sequence of guesses generated by the method converges to the fixed point, then the method will converge. However, if the function has a fixed point that is repulsive, meaning that the sequence of guesses generated by the method diverges away from the fixed point, then the method will not converge.

One disadvantage of the fixed point iteration method is that it can be slow to converge, especially for functions with a small attractive region or for initial guesses that are far from the root. In these cases, other numerical methods such as Newton’s method or the bisection method may be more effective.

## Fixed-Point Theorem

Let g C[a, b] and suppose that g(x) [a, b] for all x in [a, b]. Suppose, in addition, that g’ exists on (a, b) with |g'(x)| k 1 for all x (a, b). If p0 is any number in [a, b], then the sequence defined by pn=g(xn-1), n 1, converges to the unique fixed point p in [a, b].

## MATLAB Code of Fixed Point Iteration

Here’s an example of MATLAB code for implementing the fixed point iteration method:

function [root, iter] = fixedPointIteration(f, g, x0, tol, maxiter)
% f: the function to find the root of
% g: the function to use in the fixed point iteration
% x0: the initial guess for the root
% tol: the tolerance level for the difference between successive guesses
% maxiter: the maximum number of iterations allowed

iter = 0; % initialize iteration counter
x = x0; % initialize guess

while iter < maxiter
xprev = x; % store previous guess
x = g(x); % calculate new guess using fixed point formula
iter = iter + 1; % increment iteration counter
if abs(x - xprev) < tol % check if the difference between successive guesses is below the tolerance level
root = x; % if yes, return the root
return;
end
end

% if the maximum number of iterations is reached without finding a root, return an error message
error('Maximum number of iterations reached without finding a root.');

end


To use this function, you would need to define your function f and the function g to be used in the fixed point iteration. For example, if you wanted to find the root of the function f(x) = x^2 – 2 using the fixed point iteration method with the function g(x) = (x + 2/x)/2, you could call the function like this:

f = @(x) x^2 - 2;
g = @(x) (x + 2/x)/2;
x0 = 1;
tol = 1e-6;
maxiter = 100;

[root, iter] = fixedPointIteration(f, g, x0, tol, maxiter);


This would return the approximate root of f(x) = x^2 – 2 using the fixed point iteration method, as well as the number of iterations required to find the root