Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %This script fits a polynomial to a provided dataset.
- clc; clear; clf;
- %Call the data points from the provided txt files.
- volHotLiq = dlmread('HotLiquid.txt');
- volIce = dlmread('Ice.txt');
- %Declare the initial cells to be filled.
- n = 4;
- range = 1:n;
- coeff = cell(n, 1);
- anonFunc = cell(n, 1);
- hold on
- %Write the for loop that will fit the polynomial to the 4th degree,
- %as well as plotting and labeling the polynomials over the given parameters.
- for i = range
- coeff{i} = polyfit(volHotLiq, volIce, i);
- anonFunc{i} = @(x) polyval(coeff{i},x);
- subplot(4,1,i);
- fplot(anonFunc{i},[1,5]); %This plots the function from domain 1 to 5.
- hold on
- scatter(volHotLiq, volIce, 'r*');
- xlabel('Volume of hot liquid water'); ylabel('Volume of ice');
- legend('Filled polynomial','Data points','Location','Northwest');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement