Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- x = [1;2;3;4;5;6;7;8;9;10;11;12];
- 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];
- plot(x,y,'o')
- X = [ones(size(x)),x, x.^2, x.^3, x.^4, x.^5];
- z = X'*y;
- S = X'*X;
- U = chol(S);
- w = U'\z;
- c = U\w;
- q = 1:0.1:12;
- fit = c(1)+c(2)*q+c(3)*q.^2+c(4)*q.^3+c(5)*q.^4+c(6)*q.^5;
- hold on
- axis tight
- plot (q, fit,'red','linewidth', 2);
- hold off
- legend('data points', 'quadratic fit' , 'location' ,'northwest');
- format short e
- c
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement