Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all
- close all
- clc
- N = 10;
- X = [4 5 5 6 6 8 10 12 7 6];
- Y = [1.5 2.2 1.6 2.5 2.9 4.2 2.5 2.7 6.8 1.9];
- x1 = sort(X);
- y1 = sort(Y);
- figure(1)
- plot(x1,y1,'r',x1,y1,'r .')
- title('Экспериментальная линия регрессии у по х')
- xlabel('x')
- ylabel('y')
- sum_x = sum(x1);
- sum_y = sum(y1);
- sum_xx = sum(x1.^2);
- sum_xy = sum(x1.*y1);
- b = (length(x1) * sum_xy - sum_x * sum_y)/(length(x1)*sum_xx - (sum_x^2));
- a = (sum_y - b * sum_x/length(x1));
- regression = @(x1)b * x1 + a;
- plot(x1,y1,'bo','LineWidth',2);
- hold on
- grid on
- plot(x1,regression(x1),'k-','LineWidth',2);
- hold off
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement