0% found this document useful (0 votes)
7 views6 pages

NM Lab Report 1. 666-60-30

This lab report details the implementation of the Fixed Point Iteration Method in Python to approximate the root of the equation f(x) = x^3 + x^2 - 1. The report includes objectives, source code, and a discussion on the method's convergence criteria. It emphasizes the importance of selecting an appropriate function g(x) and initial guess for successful implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views6 pages

NM Lab Report 1. 666-60-30

This lab report details the implementation of the Fixed Point Iteration Method in Python to approximate the root of the equation f(x) = x^3 + x^2 - 1. The report includes objectives, source code, and a discussion on the method's convergence criteria. It emphasizes the importance of selecting an appropriate function g(x) and initial guess for successful implementation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Southern University Bangladesh

Department of Computer Science and Engineering

TITLE OF THE LAB REPORT


Fixed

Course Code: CSE 0541-362


Course Title: numerical Method Lab
Spring 2025

1. Name : Sadia Ali Priti


2. Student ID : 666-60-30
3. Batch : 60
4. Email ID : sadiapreety2003@gmail.com
5. Date of Assignment : 12-2-2025
6. Date of Submission : 19-2-2025
7. Contact No : 01876302843
8. Signature of Student :
9. Course Teacher : Ms Nabila
10. Signature of Teacher :
Name Of the Experiment: To implement the Fixed Point Iteration Method in Python.

A. Objective:
●​ To implement the Fixed Point Iteration Method in Python.

B. Description: (Use Heading 1)


The Fixed Point Iteration Method is a numerical technique used to approximate the root of a
nonlinear equation. It is an iterative approach that transforms the equation f(x) = 0 into the form x =
g(x), where g(x) is a function that allows iterative computations.

In this lab, we implement the Fixed Point Iteration Method in Python to find the root of the
equation:

f(x) = x^3 + x^2 - 1

The function is rearranged as:

C. Source Code:
# Fixed Point Iteration Method

# Importing math to use sqrt function

import math

# Define the original function f(x) = x^3 + x^2 - 1

def f(x):

return x*3 + x*2 - 1

# Define the rearranged function g(x) for Fixed Point Iteration

def g(x):

return 1 / math.sqrt(1 + x) # g(x) = 1 / sqrt(1 + x)

[666-60-30] Page 2 | 6
# Function to find an interval where the root exists by checking sign changes

def find_interval(a, b, step_size):

current_x = a

previous_f_value = f(current_x)

while current_x <= b:

current_x += step_size

current_f_value = f(current_x)

# Check for sign change between previous and current f(x)

if previous_f_value * current_f_value < 0:

# Root exists between previous_x and current_x

print(f"Root exists between x = {current_x - step_size} and x =


{current_x}")

return (current_x - step_size, current_x)

previous_f_value = current_f_value

# If no sign change was found

print(f"No root found in the interval [{a}, {b}] with the given step
size.")

return None

# Function to perform Fixed Point Iteration and show each step

def fixed_point_iteration(x0, tolerance, max_iterations):

print("\n\n** FIXED POINT ITERATION **")

print(f"Initial guess: x0 = {x0:.6f}")

step = 1

[666-60-30] Page 3 | 6
condition = True

while condition:

# Apply the iteration formula g(x0) to get the next approximation x1

x1 = g(x0)

# Print the details of each iteration

print(f"Iteration-{step}:")

print(f" x1 = {x1:.6f}")

print(f" f(x1) = {f(x1):.6f}") # Print the value of f(x1)

# Update the guess for the next iteration

x0 = x1

# Check if the approximation has converged

if abs(f(x1)) <= tolerance:

print(f"\nRoot found with desired tolerance: {x1:.8f}")

break

# Stop if maximum iterations are exceeded

if step >= max_iterations:

print("\nMaximum iterations reached. Root not found.")

break

# Move to the next iteration

step += 1

# Input Section

a = float(input("Enter the left end of the interval: ")) # Left endpoint

b = float(input("Enter the right end of the interval: ")) # Right endpoint

[666-60-30] Page 4 | 6
step_size = float(input("Enter the step size for interval checking: ")) #
Step size

# Find the interval where the function changes sign

interval = find_interval(a, b, step_size)

# If a valid interval is found, proceed with Fixed Point Iteration

if interval:

# Get the midpoint of the interval as the initial guess for Fixed Point
Iteration

x0 = (interval[0] + interval[1]) / 2

tolerance = float(input("Enter tolerable error (tolerance): ")) #


Precision

max_iterations = int(input("Enter maximum number of iterations: "))

# Call the Fixed Point Iteration method

fixed_point_iteration(x0, tolerance, max_iterations)

D. Program Output:

[666-60-30] Page 5 | 6
E. Discussion:

The Fixed Point Iteration Method was implemented to find the root of f(x) = x³ + x² - 1. Success
depended on choosing a proper g(x) and a good initial guess. The method converged when |g'(x)|
< 1 and stopped when the desired tolerance was reached. Proper selection of parameters ensured
accurate results.

[666-60-30] Page 6 | 6

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy