Download presentation
Presentation is loading. Please wait.
Published byMyron Wilkins Modified over 9 years ago
1
COMP 116: Introduction to Scientific Programming Lecture 11: Linear Regression
2
Revisiting linear programs A store has requested a manufacturer to produce pants and sports jackets. For materials, the manufacturer has 750 m 2 of cotton textile and 1,000 m 2 of polyester. Every pair of pants (1 unit) needs 1 m 2 of cotton and 2 m 2 of polyester. Every jacket needs 1.5 m 2 of cotton and 1 m 2 of polyester. The price of the pants is fixed at $50 and the jacket, $40. What is the number of pants and jackets that the manufacturer must give to the stores so that these items obtain a maximum revenue?
3
Solving linear programs Design a linear program ◦ What are the unknowns? ◦ What is the cost/objective function? ◦ What are the constraints? Implement it in Matlab ◦ x=linprog(f,A,b)
4
Linear Equations When is there a solution for a m x n matrix A? ◦ A is square (m = n) A has rank m Equations are linearly independent ◦ m < n More unknown than equations A is underdetermined ◦ m > n More equations than unknowns A is overdetermined
5
Least Squares Overdetermined systems: too many equations! What to do? ◦ Can’t solve Ax = b exactly Instead, minimize the “residual” Residual vector: Ax - b Residual square error: (Ax – b) ’ *(Ax – b) Matlab command >>x=A\b
6
Example: Linear Friction You measured friction in response to a force. What’s the best fitting line to the data?
7
Example: Linear Friction You measured friction in response to a force. What’s the best fitting line to the data?
8
Least Squares % set up and solve matrix % equation A*[m;c] = y A = [x, ones(10,1)]; mc = A\y mc = 2.5121 3.4707 % evaluate error res = A*mc - y; err = res'*res err = 5.8308
9
Least Squares In general: Once you have Mathematical model with parameters Observed data Fit parameters to data by minimizing sum of squared residuals
10
Least Squares Linear least squares if model is linear in the parameters Written as Ax = b A, b observed data x is set of unknowns Error (scalar): squared residual (Ax-b)'*(Ax-b)
11
Same LS principle Minimize sum of squared distance to model (parabola).
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.