Sunday, March 19, 2023

Fixed point iteration for finding the root of non linear equation: Using matlab

Fixed point iteration for finding the root of non linear equation

Fixed point iteration is a numerical method used to find the root of a non-linear equation. The method is based on the idea of repeatedly applying a function to an initial guess until the result converges to a fixed point, which is a value that doesn't change under further iterations. This fixed point is then taken as an approximation of the root of the original equation.

The fixed point iteration method works by transforming the original equation f(x) = 0 into the form x = g(x), where g(x) is a function that is easier to iterate. Then, starting with an initial guess x0, we can generate a sequence of values xn using the recursion formula:

xn+1 = g(xn)

If this sequence converges to a limit x* as n approaches infinity, then x* is a fixed point of the function g(x), and hence a root of the original equation f(x) = 0. In practice, we stop the iteration when the difference between successive values xn and xn+1 becomes sufficiently small, indicating convergence.

The convergence of the fixed point iteration method depends on the choice of the function g(x). In order for the method to work, the function g(x) must satisfy certain conditions:

  1. The function g(x) must be continuous on an interval containing the root.
  2. The function g(x) must be differentiable on the same interval, with |g'(x)| < 1 for all x in the interval. This condition ensures that the iteration is contractive, meaning that the distance between successive values xn and xn+1 shrinks at each step, leading to convergence.
  3. The initial guess x0 must be chosen close enough to the root, so that the sequence xn generated by the iteration formula actually converges to the root.

Fixed point iteration is a simple and versatile method that can be applied to a wide range of non-linear equations. However, the method may converge slowly or not at all for certain equations, depending on the choice of the function g(x) and the initial guess x0. Therefore, it is important to test the method for convergence and accuracy in each specific case.

habti.geremew@gmail.com
Fixed point iteration for finding the root of a nonlinear equation using Matlab

In MATLAB, you can implement fixed point iteration to find the root of a non-linear equation using the following steps:

  1. Define the function g(x) that transforms the original equation f(x) = 0 into the form x = g(x). Make sure that g(x) satisfies the conditions for convergence, as described in the previous answer.

  2. Choose an initial guess x0 that is close enough to the root.

  3. Define the tolerance level tol, which represents the desired accuracy of the solution. For example, you can set tol = 1e-6 to require that the iteration stops when the absolute difference between successive values xn and xn+1 is less than 1e-6.

  4. Implement the fixed point iteration using a while loop that continues until the absolute difference between successive values xn and xn+1 is less than tol. Inside the loop, update xn to xn+1 using the formula xn+1 = g(xn), and store the values of xn and xn+1 in two separate arrays for later analysis.

  5. Analyze the convergence of the iteration by plotting the sequence of values xn and xn+1 against the iteration index n. If the plot shows that the sequence converges to a fixed point, then that fixed point is an approximation of the root of the original equation.

Here is an example MATLAB code that implements fixed point iteration to find the root of the equation

Here is the code:
% Root finding using fixed point iteration
clear all, clc
syms x; % Setting x as symbolic variable
g = input('Enter non-linear equations as x=g(x): ');
x1 = input('Enter an initial guess: ');
e = input('Tolerable error in decimal: '); % basic stopping criterion
er=1; % error initialization
fprintf('x1\t\t\ter\n');
while er>e
x1_old=x1;
x1 = eval(subs(g,x,x1));
er=abs((x1-x1_old)/x1); % new error distribution
fprintf('%f\t\t%f\n',x1,er);
end
fprintf('\nRoot is: %f\n', x1);

The result can be expressed as:

Enter non-linear equations as x=g(x):
exp(-x)
Enter an initial guess:
0
Tolerable error in decimal:
0.4
x1 er
1.000000 1.000000
0.367879 1.718282
0.692201 0.468536
0.500474 0.383091

Root is: 0.500474
 
===========================================================

No comments:

Post a Comment