Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. x = [1;2;3;4;5;6;7;8;9;10;11;12];
  2. y = [69.2; 77.5; 84.7; 86.8; 90.1; 105.9; 105.1; 107.7; 100.3; 90.0; 73.4;65.4];
  3.  
  4. plot(x,y,'o')
  5. X = [ones(size(x)),x, x.^2, x.^3, x.^4, x.^5];
  6. z = X'*y;
  7. S = X'*X;
  8. U = chol(S);
  9. w = U'\z;
  10. c = U\w;
  11. q = 1:0.1:12;
  12. fit = c(1)+c(2)*q+c(3)*q.^2+c(4)*q.^3+c(5)*q.^4+c(6)*q.^5;
  13. hold on
  14. axis tight
  15. plot (q, fit,'red','linewidth', 2);
  16. hold off
  17. legend('data points', 'quadratic fit' , 'location' ,'northwest');
  18. format short e
  19. c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement