Time for action – using polyfit

  1. Assume that we have loaded the relevant data into Octave and stored the leaf lengths of tree A and B in variables yA and yB. The corresponding heights are stored in xA and xB.
  2. To fit the linear model to the data in yA, we do the following:
    octave:15> [cA sA] = polyfit(xA, yA, 1);
    
  3. We must check if the fit made any sense at all. First, we can plot the resulting linear fit together with the data:
    octave:16> plot(xA, yA, 'rs', xA, sA.yf, 'r');
    

    and is shown in the figure below with red squares and a red line.

  4. The fit of yB to the third order polynomial follows the same procedure:
    octave:17> [cB  sB] = polyfit(xB, yB, 3);
    
    octave:18> hold on; plot(xB, yB, 'bv', xB, sB.yf, 'b');
    

    The plot is shown in the figure below:

    Note

Get GNU Octave now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.