clear;
clc
close all
x = randn(1, 100);
y = 2*x + 0.5*randn(1, 100);
figure;
scatter(x, y, 'o', 'filled');
hold on;
p = polyfit(x, y, 1);
x_fit = linspace(min(x), max(x), 100);
y_fit = polyval(p, x_fit);
plot(x_fit, y_fit, 'r-', 'LineWidth', 2);
xlabel('X轴');
ylabel('Y轴');
title('散点图与拟合曲线');
grid on;
hold off;