CSE330 – Numerical Methods Lab 2 Solved

$ 20.99
Category:

Description

Polynomial Interpolation
1 Introduction
Part 1: Representing a Polynomial
Polynomials are function of the following format
p(x) = a0 + a1x1 + a2x2 + … + anxn,
where, [a0,a1,···an] are called coefficients and n (called the degree or order)
is a non-negative integer.
This can also be written as:
y = f(x) = a0x0 + a1x1 + a2x2 + … + anxn.
Example
y = 1 + 2×2 + 5×4
is a polynomial of order 4 (= n) with n + 1 coeffecients a0 = 1,a1 = 0,a2 =
2,a3 = 0,a4 = 5
1.1 Before performing the tasks
1. Open the colab file shared in BUX.
2. Create a copy of that shared file.
3. Rename the colab filename using the format
Name-ID-Lab Section
2
1.2 Task 1 – 2 Marks
You need to set up a Polynomial using the given list of Coefficient [1, 0, 2, 0, 5] and use that to approximate the value of Pn(3.5) Hint: Set up a Loop to traverse through.
Also, using the same polynomial, determine the approximate values for [1.0,
2.0, 3.0, 4.0, 5.0]
1.3 Task 2 – 5 Marks
Now, in the colab file, you will see a Polynomial Class. The constructor is defined for your purpose.
You need to write the code for Constructor to make the object callable.
You will have to remove the ”raise NotImplementedError()” in the call You can cross check whether you have done successfully by creating an instanceof the class.
1.4 Matrix – 3 Marks
Part 2: Polynomial Interpolation (Matrix Method)
If we have n+1 nodes, that is, {(x0,y0),(x1,y1),(x2,y2),(xn,yn)} that satisfies a polynomial of order n, it can be written as:
a a0 + a1x1 + a2x21 + ···an + xn1 = y1 a0 + a1x2 + a2x22 + ···an + xn2 = y2
···
a0 + a1xn−1 + a2x2n + ··· + anxnn = yn
Here, p(x) = a0 + a1x1 + a2x2 + ···anxn is called the fitted polynomial of the given data points (nodes). Using this polynomial to find the yk corresponding to an xk with the range of the given nodes is called polynomial interpolation.
In matrix form, the equations can be written as
Xa = y,
From this, we can solve for a using
a = X−1y.
So,using the colab file shared,here you need to implement a function which takes a discrete x and y array, and returns a Polynomial object (the one we just implemented). This polynomial object can be used to calculate y for any other value of x (not in that list) within the range
3

Reviews

There are no reviews yet.

Be the first to review “CSE330 – Numerical Methods Lab 2 Solved”

Your email address will not be published. Required fields are marked *