In Matlab,
Construct the natural cubic spline (see the LiveScript) to interpolate the Runge function (see Homework 6) using 10, 15, 20, and 25 equispaced nodes.
MATLAB Code:
close all
clear
clc
xx = linspace(-1, 1, 1000);
yy = 1 ./ (1 + 25*xx.^2);
figure, hold on
plot(xx, yy), xlabel('x'), ylabel('f(x)')
title('Cubic Spline Interpolation')
N = [10 15 20 25];
for i = 1:length(N)
n = N(i);
x = linspace(-1, 1, n);
f = 1 ./ (1 + 25*x.^2);
yy = spline(x, f, xx);
plot(xx, yy)
end
legend('Actual Function', 'N = 10 nodes', 'N = 15 nodes', 'N = 20
nodes', 'N = 25 nodes')
Plots:
Zoomed versions of the above plot:
Get Answers For Free
Most questions answered within 1 hours.