[go: up one dir, main page]

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

Numerical Analysis Lab Q (2020-2021)

The document outlines a series of programming tasks for a Numerical Analysis Lab at Jamalpur Science and Technology University, focusing on various numerical methods such as Fixed Point Iteration, Newton-Raphson, interpolation techniques, and integration methods. Each task requires the implementation of Python functions to solve mathematical problems, including plotting results and checking convergence. The tasks also emphasize the use of libraries like SymPy and Matplotlib for symbolic computation and visualization.

Uploaded by

mdriazlp2111
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)
13 views6 pages

Numerical Analysis Lab Q (2020-2021)

The document outlines a series of programming tasks for a Numerical Analysis Lab at Jamalpur Science and Technology University, focusing on various numerical methods such as Fixed Point Iteration, Newton-Raphson, interpolation techniques, and integration methods. Each task requires the implementation of Python functions to solve mathematical problems, including plotting results and checking convergence. The tasks also emphasize the use of libraries like SymPy and Matplotlib for symbolic computation and visualization.

Uploaded by

mdriazlp2111
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

Jamalpur Science and Technology University

Department of Mathematics
Numerical Analysis Lab Questions

1.Consider the equation

Write a Python program to implement the Fixed Point Iteration method for finding a root of
the equation.

Performs the following tasks:

(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.

2. Consider the equation:

Write a Python program to implement the Newton-Raphson method for finding a root of
the given equation.

Performs the following tasks:

(i) Define the given function 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) Use symbolic library like SymPy to automatically approximates the derivative
numerically if the user only inputs and then applies the Newton-Raphson
method.
(v) Plot the convergence of the Newton-Raphson method by graphing error vs iteration
number using Matplotlib for the given function .

3. Consider the data points:


x 1 2 3 4 5
y 1 8 27 64 125

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 .

Performs the following tasks:

(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 .

4. Consider the data points:

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

Performs the following tasks:

(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.

5. Consider the definite integral: ∫

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.

6. Consider the definite integral: ∫

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.

Performs the following tasks:

(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.

8. Consider the following system of linear equations:

Write a Python program that solves the system of linear equations using the Gauss-Seidel
method.

Perform the following tasks:

(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.

9. Consider the first order ODE:

Write a Python program to solve the first-order ODE using Taylor's method.

Perform the following tasks:

(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.

10. Consider the first order ODE:

Write a Python program to solve the first-order ODE using Euler's method.

Performs the following tasks:

(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.

Performs the following tasks:

(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.

12.Consider two lists and

Write a Python program to compute the slope and intercept of the best-fit line using
the least squares method.

Perform the following tasks:

(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.

You might also like