clc;
clearvars;
close all;
workspace;
format long g;
format compact;
fontSize = 22;
numOriginalPoints = 20;
xOriginal = sort(100 * rand(1, numOriginalPoints), 'ascend');
yOriginal = 30 * rand(1, numOriginalPoints) - 10;
subplot(3, 1, 1);
plot(xOriginal, yOriginal, 'ro-', 'LineWidth', 2);
grid on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Training Points', 'FontSize', fontSize);
numNewPoints = 100;
xInterpolated = linspace(min(xOriginal), max(xOriginal), numNewPoints);
yInterpolated = interp1(xOriginal, yOriginal, xInterpolated);
subplot(3, 1, 2);
plot(xInterpolated, yInterpolated, 'bo-', 'LineWidth', 2);
hold on;
plot(xOriginal, yOriginal, 'ro', 'LineWidth', 2);
grid on;
title('Interpolated Points without Including Training Points', 'FontSize', fontSize);
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
legend('Interpolated', 'Training');
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
subplot(3, 1, 3);
xInterpolated = sort([xInterpolated, xOriginal], 'ascend');
yInterpolated = interp1(xOriginal, yOriginal, xInterpolated);
plot(xInterpolated, yInterpolated, 'bo-', 'LineWidth', 2);
hold on;
plot(xOriginal, yOriginal, 'ro', 'LineWidth', 2);
grid on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
title('Interpolated Points Including Training Points', 'FontSize', fontSize);
legend('Interpolated', 'Training');
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0, 0.04, 1, 0.96]);
Best Answer