Advertisement
Guest User

schnoot

a guest
May 15th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. %This script fits a polynomial to a provided dataset.
  2. clc; clear; clf;
  3.  
  4. %Call the data points from the provided txt files.
  5. volHotLiq = dlmread('HotLiquid.txt');
  6. volIce = dlmread('Ice.txt');
  7.  
  8. %Declare the initial cells to be filled.
  9. n = 4;
  10. range = 1:n;
  11. coeff = cell(n, 1);
  12. anonFunc = cell(n, 1);
  13. hold on
  14.  
  15. %Write the for loop that will fit the polynomial to the 4th degree,
  16. %as well as plotting and labeling the polynomials over the given parameters.
  17. for i = range
  18. coeff{i} = polyfit(volHotLiq, volIce, i);
  19. anonFunc{i} = @(x) polyval(coeff{i},x);
  20. subplot(4,1,i);
  21. fplot(anonFunc{i},[1,5]); %This plots the function from domain 1 to 5.
  22. hold on
  23. scatter(volHotLiq, volIce, 'r*');
  24. xlabel('Volume of hot liquid water'); ylabel('Volume of ice');
  25. legend('Filled polynomial','Data points','Location','Northwest');
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement