Numerical Analysis Lab Q (2020-2021)
Numerical Analysis Lab Q (2020-2021)
Department of Mathematics
Numerical Analysis Lab Questions
Write a Python program to implement the Fixed Point Iteration method for finding a root of
the equation.
(i) Rewrite the given function in form and define the function and
in python.
(ii) Create a Python function that returns the approximate root, number of iterations, and
error list.
(iii) Implement a Python script that asks the user to input the function an
initial guess, and number of iterations.
(iv) Check convergence of at an initial guess
(v) Visualize both the curve and the line to show graphically where
Fixed Point Iteration converges.
Write a Python program to implement the Newton-Raphson method for finding a root of
the given equation.
Write a Python program to implement the Newton’s backward Interpolation for the given set of
data points and computes the interpolated value at a specified .
(i) Implement a Python function that generates the backward difference table for the
given set of data points
(ii) Prints the forward difference table for better understanding
(iii) Compute the interpolated value at .
1 2 3 4 5
1 8 27 64 125
Write a Python program to implement the Lagrange’s formula for the given set of data points and
computes the interpolated value at a specified
(i) Implement a Python function that takes the given set of data points
(ii) Compute the Lagrange basis polynomials for the given set of data points and
use them to find the interpolated polynomial.
(iii) Calculates the interpolated value at a given using Lagrange’s formula.
(iv) Adjust your Python program to display the final interpolating polynomial using a
symbolic library like SymPy.
Write a Python function to approximate the definite integral of a given function using the
Trapezoidal Rule.
(i) Define a Python function to approximate the definite integral of a given function
using the Trapezoidal Rule.
(ii) Implement a Python script that asks the user to input the function, the interval
and the number of sub-intervals , and then computes the integral using the
Trapezoidal Rule.
(iii) Calculate the percentage error between the Trapezoidal Rule result and the exact
integral (using SymPy) value.
(iv) Plot the function and visually show how the trapezoids approximate the area under
the curve using Matplotlib.
Write a Python function to approximate the definite integral of a given function using the
Simpson’s 1/3 or 3/8 Rule.
(i) Define a Python function to approximate the definite integral of a given function
using the Simpson’s 1/3 or 3/8 Rule.
(ii) Implement a Python script that asks the user to input the function, the interval
and the number of sub-intervals , and then computes the integral using the
Simpson’s 1/3 or 3/8 Rule.
(iii) Calculate the percentage error between the Simpson’s 1/3 or 3/8 Rule result and the
exact integral (using SymPy) value.
(iv) Plot the function and visually show how the trapezoids approximate the area under
the curve using Matplotlib.
7. Consider the system of linear equations:
Write a Python program to solve the linear system using the Jacobi method.
(i) Define a Python function to solve the given system of linear equations using the
Jacobi method.
(ii) Check if a matrix is diagonally dominant before applying the Jacobi method.
(iii) Modify your Jacobi function to track the error at each iteration and plot the error
convergence using Matplotlib.
Write a Python program that solves the system of linear equations using the Gauss-Seidel
method.
(i) Define a Python function that solves the system of linear equations using the Gauss-
Seidel method.
(ii) Modify your function to print the solution at each iteration.
(iii) Add a feature to track the error (difference between successive iterations) and plot the
convergence using matplotlib.
(iv) Compare the convergence speed of Gauss-Seidel and Jacobi methods using Python.
Write a Python program to solve the first-order ODE using Taylor's method.
(i) Define a Python function to solve the given first-order ODE using Taylor's method of
order 3.
(ii) Use SymPy in Python to automatically compute the necessary derivatives of the
function for Taylor’s method of order 3
(iii) Modify your function to accept and use second derivatives for Taylor’s method of
order 3.
(iv) Use your Taylor's method function to solve the initial value problem ,
with , step size , and steps.
(v) Compare the numerical solution obtained from Taylor’s method with the exact
solution for a known ODE using matplotlib. Plot both on the same graph.
Write a Python program to solve the first-order ODE using Euler's method.
(i) Define a Python function to approximate the solution of the given ODE over steps.
(ii) Use your defined function to solve , with initial condition ,
using step size for steps.
(iii) Modify your function to return and plot the full solution curve y(x) using matplotlib.
(iv) Compare the numerical solution from Euler’s method with the exact solution (if known),
and plot both on the same graph.
11.Consider the first order ODE:
Write a Python program to solve the first-order ODE using the 4th-order
Runge-Kutta method.
(i) Define a Python function to solve the first-order ODE using the 4th-
order Runge-Kutta method.
(ii) Use your function to solve with using a step size of and
steps.
(iii) Modify your RK4 function to store and return all computed values so they can be
plotted.
(iv) Compare the RK4 solution with Euler’s method and the exact solution (if available) on
the same plot using Matplotlib.
Write a Python program to compute the slope and intercept of the best-fit line using
the least squares method.
(i) Implement the mathematical formula for the slope (m) and intercept (c) in simple
linear regression using the Least Squares Method without using NumPy or other
libraries.
(ii) Use scipy.stats.linregress to perform linear regression. Compare the slope and
intercept obtained with your manual implementation.
(iii) Define a Python function to calculate the residuals for the given linear model and
dataset.
(iv) Plot the original data and the best-fit line using Matplotlib.