📊

Module 8 Video - Polyfit

Mar 7, 2025

MATLAB Mathematical Modeling with Polyfit

Introduction to Model Fitting

  • MATLAB offers more flexibility than Excel for constructing mathematical models.
  • Focus on three model types: linear, power, and exponential.
  • Use MATLAB function polyfit for all three models with variations.

Linear Model

  • Equation: ( y = mx + b )
    • m: slope of the line (rise over run)
    • b: intercept with the vertical axis
  • Polyfit Usage:
    • Command: C = polyfit(X, Y, 1)
    • X: vector of independent data
    • Y: corresponding dependent data
    • 1: indicates fitting a first-order polynomial
    • Returns: a vector ([m, b])
  • Steps to Use:
    • Extract values: m = C(1) and b = C(2)

Power Model

  • Equation: ( y = bx^m )
    • m: power of ( x )
    • b: value of ( y ) when ( x = 1 )
  • Linearization:
    • Take base 10 log: ( \log(y) = m \log(x) + \log(b) )
    • Plot ( \log(y) ) versus ( \log(x) ) to get a straight line
  • Polyfit Usage:
    • Use ( \log_{10}(X) ) and ( \log_{10}(Y) ) with polyfit
    • Extract m and calculate b as ( b = 10^{\log(b)} )

Exponential Model

  • Equation: ( y = be^{mx} )
    • m: can be any value, not limited to integers
    • b: intercept where ( x = 0 )
  • Linearization:
    • Take natural log: ( \ln(y) = mx + \ln(b) )
    • Use natural log of ( Y ) in polyfit
  • Polyfit Usage:
    • Use ( X ) and ( \ln(Y) ) with polyfit
    • Extract m and calculate b as ( b = e^{\ln(b)} )

Graphical Representation

  • Linear Model: straight line on a rectilinear graph
  • Power Model: straight line on a full logarithmic graph
  • Exponential Model: straight line on a semi-log graph with the vertical axis logarithmic

Conclusion

  • Each model requires specific manipulation to use polyfit effectively.
  • Refer to Chapter 13 in the text for more details on linearizing equations.