Numerical Methods
FExer02] Numerical Interpolation, Integration
Create a new .NET class library project named FExer02_<Lastname>.
You may use the NuGet packages: [Link] and [Link].
For each item, do the following:
a. 10 pts. Create unit tests to show multiple examples along with their outputs.
b. 5 pts. Discuss your code implementation. Show each code section in relation to the steps we use to
manually solve the problem.
Submit a report on your project using the Exercise Template. Include your source code.
Follow the instructions in the How to Submit an Exercise Containing Code document.
1. Write a method that solve for the interpolated value given an array of 𝑥 and 𝑓(𝑥) values using Lagrange
interpolation.
Method header:
public LagrangeResult Interpolate(double[] xValues, double[] yValues, double x)
Store the interpolated value, Lagrange interpolating polynomial, and the simplified interpolating polynomial.
Sample method usage:
var xValues = new double[] { 0, 20, 40 },
var yValues = new double[] { 3.85d, 0.8d, 0.212d };
double x = 15;
var result = Interpolate(xValues, yVDoubles, x);
// result should contain
x = 1.3316875
interpolating polynomial:
f(x) = ((x-20)(x-40)(3.85)/((-20)(-40))) + ((x-0)(x-40)(0.8)/((20)(-20))) + ((x-0)(x-
20)(0.212)/((40)(20)))
simplified polynomial:
f(x) = 3.85 - 0.21405000000000002*x + 0.0030775*x^2
Numerical Methods
2. Write a method that will solve for the integral given an array of 𝑥 and 𝑓(𝑥) values using the Trapezoidal
Rule.
Method header:
public IntegralResult IntegrateTrapezoid(double[] xValues, double[] yValues)
Sample method usage:
var xValues = new double[] { 0, 0.8 },
var yValues = new double[] { 0.2d, 0.232d };
var result = IntegrateTrapezoid(xValues, yVDoubles);
// result should contain
I = 0.1728
Newton-Cotes polynomial:
f(x) = 0.04x + 0.2
simplified polynomial:
f(x) = 0.04x + 0.2
For items 3–7, modify your method headers according to numerical integration requirements, like the
parameter 𝑛 for composite rules.
3. Repeat #2 using the Composite Trapezoidal Rule.
4. Repeat #2 using Simpson’s 1/3 & 3/8 Rules.
5. Repeat #4 with their composite versions.
6. Write a method that will solve the integral using Romberg Integration.
7. Write a method that will solve the integral using Gauss-Legendre Integration.