Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.26 KB | None | 0 0
  1. a0=1;
  2. a1=2;
  3. N=20;
  4. x = rand(1,N)*100;
  5. y0 = a0 + a1*sqrt(x);
  6. y = y0 + randn(1,N) *0.5;
  7.  
  8. X = [ones(N,1), sqrt(x(:))];
  9. a = (X'*X)^(-1)*X'*y(:),
  10.  
  11. xx = 0.1: 0.01:100;
  12. yy = a(1)+a(2)*sqrt(xx);
  13.  
  14. figure(1)
  15. clf;
  16. plot(x,y,'bo'); grid on; hold on;
  17. plot(xx,yy,'r');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement