Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.58 KB | None | 0 0
  1. close all
  2. clear
  3. clc
  4.  
  5. % deklaracja funkcji
  6. f = @(x) 0.00015.*x.^5 - 0.001.*(x - 3).^4 + 0.1.*x.^3 - 5.*(x - 3) - 17;
  7. X = linspace(-10, 10, 1000);
  8. szum = randn(1, 1000);
  9. hold on
  10. plot(X, f(X), 'r');
  11. plot(X, f(X) + szum);
  12. for i=2:6
  13.     p = polyfit(X, f(X) + szum, i);
  14.     plot(X, polyval(p, X));
  15. end
  16. hold off
  17. legend({'f(x)', ...
  18.     'f(x) + szum', ...
  19.     'wielomian stopnia: 2', ...
  20.     'wielomian stopnia: 3', ...
  21.     'wielomian stopnia: 4', ...
  22.     'wielomian stopnia: 5', ...
  23.     'wielomian stopnia: 6', ...
  24.     }, 'Location', 'northwest')
  25. xlabel('x')
  26. ylabel('y')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement