ES341
ES341
Construct the cubic spines for the collected data points to replace them
with continuous and smooth curves using MATLAB
Submitted to:
Prof. Dr. Sirajul Haq
Submitted by:
Muhammad Omar Amin (2022411)
Page 1 of 4
I. MATLAB Code
% ES341 Assignment
% Cubic Spline Interpolation
% Muhammad Omar Amin (2022411)
% Construct vector B
for i = 2:N-1
B(i) = (3/h(i)) * (Alpha(i+1) - Alpha(i)) - (3/h(i-1)) * (Alpha(i) -
Alpha(i-1));
end
Page 2 of 4
figure;
scatter(X, F, 40, 'r', 'filled', 'DisplayName', 'Data Points'); % Pretty
data points
hold on;
% Finalize plot
title('Cubic Spline Interpolation', 'FontSize', 14, 'FontWeight', 'bold');
xlabel('X-axis', 'FontSize', 12);
ylabel('f(X)', 'FontSize', 12);
grid on;
set(gca, 'FontSize', 10, 'GridColor', [0.8, 0.8, 0.8], 'GridAlpha', 0.5);
legend('Data Points', 'Location', 'northwest');
hold off;
Page 3 of 4
III. Conclusion
The generated cubic splines effectively approximate the data set with continuous and
differentiable curves, demonstrating the utility of this method in handling numerical problems
involving interpolation. The results confirm that the implemented code is accurate and
efficient, with the graph validating smoothness and continuity across all segments. This
analysis underscores the importance of careful algorithm implementation and aesthetic
presentation in numerical analysis tasks.
Page 4 of 4