Final Project - Introduction to Numerical Analysis
Ex 1: Hermite and Chebyshev Interpolations
1. Given the function
f (x) =
1
25x2 + 1
on the interval x ∈ [−1, 1], perform the following steps:
(a) Equispaced Interpolation: Divide the domain into n = 10 subintervals (i.e.,
use 11 equally spaced points). Construct the interpolating polynomial p10 (x)
using these points.
(b) Chebyshev Nodes Interpolation: Compute the Chebyshev nodes {xi } in the
given interval. Construct the interpolating polynomial c10 (x) using these nodes.
(c) Plot Comparison: Plot f (x), p10 (x), and c10 (x) on the same graph for visualization.
(d) Error Evaluation: Compute the absolute errors:
Ep (x) = |f (x) − p10 (x)| ,
Ec (x) = |f (x) − c10 (x)|
Plot Ep (x) and Ec (x) in the same graph. Ensure you use a sufficient number of
points to make the error plots smooth.
Exercise 2
Objective
The goal of this project is to apply various numerical techniques studied in class to solve, approximate, and analyze the behavior of a second-order ordinary differential equation (ODE)
involving both the first and second derivatives.
Physical Background
We consider the motion of a damped spring-mass system under an external force, which is
modeled by the following ODE:
y 00 (t) + 2y 0 (t) + y(t) = cos(t),
1
(1)
with boundary conditions:
y(0) = 1,
y(π) = −1.
This equation models a damped harmonic oscillator with an external forcing term cos(t).
Damper
Fext (t) = cos(t)
Mass
Spring
y(t)
Instructions
1. Discretization: Discretize the ODE in Equation (1) using finite differences on a
uniform grid in the interval [t0 , tn ] = [0, π]. Use:
• Central differences for the second derivative.
• A one-sided or central difference scheme for the first derivative.
2. Numerical Solution: Write a Matlab script to solve the linear system that arises
from the discretized equation. Solve it using:
• 6 nodes (5 intervals)
• 11 nodes (10 intervals)
• 21 nodes (20 intervals)
• 101 nodes (100 intervals)
3. Plotting: Plot the three numerical solutions (for 6, 11, and 101 nodes) in the same
graph.
4. Interpolation: For the cases with 6 and 11 nodes:
2
• Compute the interpolating polynomial I6 (t) and I11 (t) that passes through the
respective nodes using either Lagrange or Newton interpolation.
• Plot I6 (t) and I11 (t) on the same graph (see the example below).
y
I6
x
I11
Note: This example was generated using arbitrary curves and is intended solely to
illustrate how the graphs in the final project should be presented.
5. Least Squares Approximation: For the case with 101 nodes:
• Fit a second-order polynomial LS2 (t) and a third-order polynomial LS3 (t) to the
data using the least squares method.
• Plot LS2 (t) and LS3 (t) on the same graph along with the 101 computed values.
6. Analytical Solution: The exact solution of the ODE is:
a(t) = e−t −
1 + e−π −t 1
te + sin(t) .
πe−π
2
7. Error Analysis: Plot the following absolute error functions:
• |a(t) − I6 (t)|
• |a(t) − I11 (t)|
• |a(t) − LS2 (t)|
• |a(t) − LS3 (t)|
8. Numerical Integration of Errors: Compute numerically the integral of each error
in the interval [0, π], e.g.,
Z
π
|a(t) − I6 (t)| dt,
0
using:
• Either the Midpoint or Trapezoidal numerical integration with n = 5 and n = 10.
• A Gauss quadrature rule with n = 2 and n = 3.
Note: You must upload a report with your results, plots, and a clear explanation of each
step, along with the MATLAB code used.
3