Advertisement
makispaiktis

Matlab - Test8_Polynomials.m

Apr 11th, 2020 (edited)
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.68 KB | None | 0 0
  1. clear all
  2. clc
  3.  
  4. polya = poly([1 2])
  5. polyb = poly([4 6])
  6. polyc = poly([3 -4])
  7. polyd = poly([1 1 1])
  8. polye = poly([2 3 5])
  9. rootsb = roots(polyb)
  10. rootse = roots(polye)
  11. sumPolyAandPolyB = polya+polyb
  12.  
  13. value = polyval([1 4 4], 3)
  14. product = conv([1 2], [1 4])
  15. integral = polyint([3 2 10])
  16. diff = polyder([1 5 8])
  17.  
  18. % Polyfit
  19. % I will create 5 points
  20. for i = 1:5
  21.     x(i) = i;
  22.     y(i) = randi(10);
  23. end
  24. x
  25. y
  26. p = polyfit(x, y, 6)
  27. for i = 1:5
  28.     value = y(i)
  29.     evaluation = polyval(p, i)
  30. end
  31.  
  32. % Using the p fitting polynomial, I will create a plot
  33. % based on spots
  34. x2 = 1: 0.05: 5;
  35. y2 = polyval(p, x2);
  36. plot(x,y,x2,y2,'r--')
  37. title('Plot of Data (Points) and Model (Line)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement