Tutorial: Linear Regression
Least Squares Regression
Part 1: Linear Regression (line)
Problem
Predict the pressure if the temperature is increased to 150C based on Charles's law for ideal gas P=kT, where k is a constant.


Tutorial: Matlab
Exercise: MATLAB
Download the tutorial source file
Fill-in the blanks to create function [a0,a1] = linearFit(X, Y)
Exercise: C
Download the tutorial source code
Fill-in the blanks to create functions that calculates coefficients of least squares regression (line)
void linearRegression (double z_opt[], double xdata[], double ydata[], int dataN)
Part 2: Higher-order polynomial curve fitting (Optional)
Problem
Find the optimal higher-order polynomial to fit the given dataset. assume the model has n=4 order polynomial form

Exercise: MATLAB
Exercise: C (optional)
Fill-in the blanks to create functions that calculates coefficients of least squares regression of Nth order polynomial
Download the tutorial source code
void polyFit(double vecZ[], double vecX[], double vecY[], int n);
If you choose to use Matrix structure
Matrix polyFit_mat(Matrix _vecX, Matrix _vecY, int n);
Last updated
Was this helpful?