Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. x = randi([0,100],1,30);
  2. y = randi ([0,100],1,30);
  3.  
  4. save ("lab3")
  5.  
  6. [a0,a1]=linear_regression(x,y);
  7. plot(x,y,'r*'); %points
  8. hold on;
  9. plot(x,a0+a1*x,'b'); %line
  10.  
  11. figure()
  12.  
  13. md1 = fitlm(x,y);
  14. disp(mdl.Rsquared.Adjusted)
  15. plotResiduals(md1)
  16. % Res = table2array(mdl.Residuals);
  17. % boxplot(Res)
  18.  
  19. Osobny plik
  20.  
  21. function [a0,a1]=linear_regression(x,y)
  22. x=x(:);
  23. y=y(:);
  24. X=[x,ones(numel(x),1)];
  25. a = (X'*X)\(X'*y);
  26. a0=a(2);
  27. a1=a(1);
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement