You are on page 1of 5

Lab Report 4

Numerical Computation

Submitted by:
Muhaib ul Islam

Submitted to:
Sir Ifthikar Ahmed
Registration no:
FA20-BEE-222

COMSATS UNIVERSITY ISLAMABAD


Fixed Point Method Implementation:
The fixed-point iteration method is a numerical approach to find solutions of equations \(f(x) =
0\), where the equation is transformed into the form \(x = g(x)\). Starting with an initial guess, \
(x_0\), the method iteratively applies \(g(x)\) to generate a sequence of values \(x_0, x_1, x_2, \
ldots\). Convergence is determined by assessing the closeness of successive iterations, and a
suitable choice of \(g(x)\) and initial guess is crucial for success. This method is widely used in
various fields for solving equations that are challenging to solve analytically.

Advantages of Fixed-Point Iteration:

1. Simplicity: The method is conceptually simple and easy to implement, making it accessible
to a wide range of users.

2. Broad Applicability: Fixed-point iteration can be applied to a wide variety of equations,


including those for which analytical solutions are not readily obtainable.

3. Convergence in Many Cases: When properly chosen, the function \(g(x)\) and initial guess \
(x_0\) can lead to fast convergence, providing accurate solutions efficiently.

4. Useful in Numerical Analysis: Fixed-point iteration serves as a foundational technique for


more complex numerical methods, forming the basis for algorithms used in various fields.

Disadvantages of Fixed-Point Iteration:

1. Dependence on Initial Guess: The choice of initial guess is crucial. If it's too far from the
actual solution, or if \(g(x)\) is poorly chosen, the method may fail to converge.

2. Potential for Divergence: Depending on the chosen \(g(x)\) and initial guess, the method
can diverge, leading to incorrect results.

3. Slower Convergence Compared to Some Methods: While simple, fixed-point iteration


may converge more slowly than more advanced numerical techniques for certain equations.

4. Sensitivity to Function Behavior: Convergence depends on the behavior of the function \


(g(x)\) in the vicinity of the solution, which can be challenging to predict in some cases.
Code:
import numpy as np
import matplotlib.pyplot as plt

def g(x):
return 10 / (x**2 + 4*x)

# Initial guess
x0 = 1.0

# Number of iterations
num_iterations = 10

# Lists to store x values and corresponding f(x) values


x_values = [x0]
y_values = [g(x0)]

for _ in range(num_iterations):
x_new = g(x_values[-1])
x_values.append(x_new)
y_values.append(g(x_new))

plt.plot(x_values, y_values, 'o-', label='Fixed-Point Iteration')


plt.xlabel('x')
plt.ylabel('g(x)')
plt.title('Fixed-Point Iteration')
plt.grid(True)
plt.show()

print("Final estimate of the fixed point:", x_values[-1])


Output:

You might also like