clear;
clc;
close all;
fprintf ('Ajuste de curva por mínimos quadrados \n\n')
%Dados Iniciais
x_tab = [0.3 2.7 4.5 5.9 7.8];
y_tab = [1.8 1.9 3.1 3.9 3.3];
n = length (x_tab);
p = 2;
Sx = sum (x_tab);
Sy = sum (y_tab);
Sxy = sum (x_tab.*y_tab);
Sx2 = sum (x_tab.^2);
Sy2 = sum (y_tab.^2 );
b1 = (Sx*Sy-n*Sxy)/(Sx^2-n*Sx2)
b0 = (Sy-b1*Sx)/n
U_tab = b0 + b1*x_tab;
D = sum ((y_tab-U_tab).^2);
r2 = 1 - (D / (Sy2-(1/n)*Sy^2))
sigma2 = D/(n-p)
U=@(x)b0+b1*x;
x_grid = min(x_tab) - 0.5 : 0.1 : max (x_tab)+0.5;
figure(1)
plot(x_grid, U (x_grid));
hold on;
plot(x_tab,y_tab,'o');
grid on;
title ('Ajuste de curvas');
xlabel('x');
ylabel('y');
legend ('Modelo','tabela');
To embed this project on your website, copy the following code and paste it into your website's HTML: