Math 343 Lab 7: Line and Curve Fitting

Similar documents
Least squares and Eigenvalues

Characteristics of Linear Functions (pp. 1 of 8)

Basic Fraction and Integer Operations (No calculators please!)

2-7 Solving Quadratic Inequalities. ax 2 + bx + c > 0 (a 0)

Solve the problem. Determine the center and radius of the circle. Use the given information about a circle to find its equation.

reflector screen 10 g masses

AP Physics 1 Summer Assignment Unit Conversions Review 1.) Finish the SI prefix table below. Follow the example of the centi prefix.

171S1.1 Graphs, Functions, Models August 23, 2012

Experiment 1: Linear Regression

Geometry Summer Assignment 2018

Chapter 1: Precalculus Review

January 18, 2008 Steve Gu. Reference: Eta Kappa Nu, UCLA Iota Gamma Chapter, Introduction to MATLAB,

b) Write the contrapositive of this given statement: If I finish ALEKS, then I get points.

TEST 150 points

Student Instruction Sheet: Unit 2, Lesson 2. Equations of Lines, Part 2

AP Physics 1 LCHS Summer Work

AP Physics C: Mechanics Summer Work 2015

Basic Linear Algebra in MATLAB

Investigating Limits in MATLAB

GOOD LUCK! 2. a b c d e 12. a b c d e. 3. a b c d e 13. a b c d e. 4. a b c d e 14. a b c d e. 5. a b c d e 15. a b c d e. 6. a b c d e 16.

Linear Equations. Find the domain and the range of the following set. {(4,5), (7,8), (-1,3), (3,3), (2,-3)}

Section 1.4 Circles. Objective #1: Writing the Equation of a Circle in Standard Form.

LESSON EII.F ABSOLUTE VALUE 89

1.2 Graphs and Lines. Cartesian Coordinate System

Example. 171S Introduction to Graphing. January 06, Introduction to Graphing. Cartesian Coordinate System

REVIEW PACKET. We want all students to be successful and confident in math!

Class President: A Network Approach to Popularity. Due July 18, 2014

Absolute Value Inequalities 2.5, Functions 3.6

( ) AP Physics 1 Math Review

Introduction to SVD and Applications

Harmonic Motion. Mass on a Spring. Physics 231: General Physics I Lab 6 Mar. 11, Goals:

Math 2 Variable Manipulation Part 7 Absolute Value & Inequalities

PHYS 1401General Physics I Hooke s Law, Simple Harmonic Motion

Sample Questions to the Final Exam in Math 1111 Chapter 2 Section 2.1: Basics of Functions and Their Graphs

Reteach 2-3. Graphing Linear Functions. 22 Holt Algebra 2. Name Date Class

Assignment 1b: due Tues Nov 3rd at 11:59pm

Math Placement Test Review Sheet Louisburg College _ Summer = c = d. 5

INSTRUCTIONS USEFUL FORMULAS

Math 2250 Lab 08 Lab Section: Class ID: Name/uNID: Due Date: 3/23/2017

REVIEW PACKET. Classical Academy High School Algebra 2 Readiness Assessment

SKILL BUILDER TEN. Graphs of Linear Equations with Two Variables. If x = 2 then y = = = 7 and (2, 7) is a solution.

AP Physics Summer Assignment

Section 1.4. Meaning of Slope for Equations, Graphs, and Tables

Sect The Slope-Intercept Form

MATH.2720 Introduction to Programming with MATLAB Vector and Matrix Algebra

E-BOOK / FINDING THE EQUATION OF A PARABOLA GIVEN THREE POINTS EBOOK

Math 10. Lesson 4 7 General Form of Linear Equation

Investigating Springs (Simple Harmonic Motion)

MATH 100 Introduction to the Profession

Math 138: Introduction to solving systems of equations with matrices. The Concept of Balance for Systems of Equations

The Coordinate Plane; Graphs of Equations of Two Variables. A graph of an equation is the set of all points which are solutions to the equation.

GOOD LUCK! 2. a b c d e 12. a b c d e. 3. a b c d e 13. a b c d e. 4. a b c d e 14. a b c d e. 5. a b c d e 15. a b c d e. 6. a b c d e 16.

Summer Review. For Students Entering. Algebra 2 & Analysis

AP Physics 1 Summer Work 2017

State Feedback MAE 433 Spring 2012 Lab 7

Math 46 Final Exam Review Packet

Approximations - the method of least squares (1)

A. 16 B. 16 C. 4 D What is the solution set of 4x + 8 > 16?

LESSON EII.C EQUATIONS AND INEQUALITIES

University of Connecticut Department of Mathematics

Using Linear Equations to Solve Problems

4 The Cartesian Coordinate System- Pictures of Equations

2D Plotting with Matlab

The highest degree term is x $, therefore the function is degree 4 (quartic) c) What are the x-intercepts?

( ) c. m = 0, 1 2, 3 4

8th Grade Common Core Math

Section 5.8 Regression/Least Squares Approximation

= 2 x. So, when 0 < x < 2 it is increasing but it is decreasing

FOUNDATIONS OF ALGEBRAIC GEOMETRY CLASS 27

Fundamentals. Copyright Cengage Learning. All rights reserved.

SOLUTIONS FOR PROBLEMS 1-30

Problem 1: (3 points) Recall that the dot product of two vectors in R 3 is

Projections and Least Square Solutions. Recall that given an inner product space V with subspace W and orthogonal basis for

EEL2216 Control Theory CT1: PID Controller Design

Test 2 Review Math 1111 College Algebra

Department of Mathematics, University of Wisconsin-Madison Math 114 Worksheet Sections 3.1, 3.3, and 3.5

22 Approximations - the method of least squares (1)

Chapter 8: Linear Algebraic Equations

Logarithmic and Exponential Equations and Change-of-Base

(Mathematical Operations with Arrays) Applied Linear Algebra in Geoscience Using MATLAB

Section 2.2 Intercepts & Symmetry

Data Fits. We begin this discussion using a simple linear function. Later, we briefly elaborate to linearized plots and and non-linear fits.

Unit 1 PreCalculus Review & Limits

EDEXCEL NATIONAL CERTIFICATE UNIT 4 MATHEMATICS FOR TECHNICIANS OUTCOME 1

Spring 2015, Math 111 Lab 3: Exploring the Derivative

MATH ASSIGNMENT 06 SOLUTIONS

Section 1.6. Functions

Given the table of values, determine the equation

SUMMER MATH PACKET for students

Chapter 3 Representations of a Linear Relation

Finite Differences TEACHER NOTES MATH NSPIRED

Linear Inverse Problems. A MATLAB Tutorial Presented by Johnny Samuels

MAC College Algebra

Lesson 3-1: Solving Linear Systems by Graphing

Name: Lab Partner: Section: Simple harmonic motion will be examined in this experiment.

These will be no tutorials for Math on Tuesday April 26.

Recognise the Equation of a Circle. Solve Problems about Circles Centred at O. Co-Ordinate Geometry of the Circle - Outcomes

These variables have specific names and I will be using these names. You need to do this as well.

Physics lab Hooke s Law and Pendulums

To get horizontal and slant asymptotes algebraically we need to know about end behaviour for rational functions.

Transcription:

Objective Math 343 Lab 7: Line and Curve Fitting In this lab, we explore another use of linear algebra in statistics. Specifically, we discuss the notion of least squares as a way to fit lines and curves to data. Hooke s Law It is well known that the displacement of a spring is proportional to the force acting upon it, that is, F = kx. The proportionality constant k is called Hooke s spring constant. Consider a laboratory experiment where different loads are placed on a spring and the displacement is measured and recorded in the table below: x F (cm) (dyne) 1.04 3.11 2.03 6.01 2.95 9.07 3.92 11.99 5.06 15.02 6.00 17.91 7.07 21.12 To find the spring constant k, we simply need to solve the following linear system 1.04 3.11 2.03 6.01 2.95 ( ) 9.07 3.92 k = 11.99. 5.06 15.02 6.00 17.91 7.07 21.12 However, there is no solution to this system because it is overdetermined. Instead, we seek the best k that fits the data.

Least Squares In class, you will soon discuss the least squares problem, which finds the best solution to the (usually overdetermined) linear system The main result goes as follows: Ax = b. Theorem: Consider the linear system Ax = b, where A is an m n matrix of rank n. Then A T A is nonsingular, and the least squares solution of the system is x = (A T A) 1 A T b. In other words, even though an overdetermined linear system doesn t generally have a solution, there is a vector x that minimizes the error between Ax and b. This is called the least squares solution. As an example, lets revisit our spring problem. Although it doesn t have a solution, we can find the least squares solution by computing the following in Matlab: >> A = [1.04;2.03;2.95;3.92;5.06;6.00;7.07]; >> b = [3.11;6.01;9.07;11.99;15.02;17.91;21.12]; >> k = inv(a *A)*A *b Hence, we find the spring constant to be k = 2.9957. against the best fit as follows: We plot the data >> x0 = linspace(0,8,100); >> y0 = k*x0; >> plot(a,b, *,x0,y0) See Figure 1 to see how well the line fits the data.

25 20 15 10 5 0 0 1 2 3 4 5 6 7 8 Figure 1: The graph of the spring data together with its linear fit General Line Fitting Suppose that we wish to fit a general line, that is y = mx + b, to the data set {(x k, y k )} n k=1. Assume that the line does not cross through the origin, as in the previous example. Then we seek both a slope and a y-intercept. In this case, we set up the following linear system Ax = b, or more precisely x 1 1 y 1 x 2 1 ( ) y 2 x 3 1 m = y 3. b... x n 1 y n

Note that A has rank 2 as long as not all of the x k values are the same. Hence, the least squares solution will fit the best line for this data. Fitting data to a circle Recall that the equation of a circle, with radius r centered at (c 1, c 2 ), is given by (x c 1 ) 2 + (y c 2 ) 2 = r 2. (1) Suppose we are given a set of data points closely forming a circle {(x i, y i )} n i=1. The best fit is found via least squares by expanding (1) to get 2c 1 x + 2c 2 y + c 3 = x 2 + y 2, where c 3 = r 2 c 2 1 c 2 2. Then we can write the linear system Ax = b as 2x 1 2y 1 1 x 2 1 + y1 2 2x 2 2y 2 1 c 1 c 2 x 2 2 + y 2 2 =... c., 3 2x n 2y n 1 x 2 n + yn 2 where the matrix A and the vector b are obtained by the given data and the unknown x contains the information about the center and radius of the circle and is obtained by finding the least squares solution. Example In this section, we fit the following points to a circle: (134, 76), (104, 146), (34, 176), ( 36, 146), ( 66, 76), ( 36, 5), (34, 24), (104, 5), (134, 76) We enter them into Matlab as the 9 2 matrix: >> P = [134 76; 104 146; 34 176; -36 146; -66 76; -36 5; 34-24; 104 5; 134 76] Then we can separate the x and y coordinates by the commands P(:,1) and P(:,2), respectively. Hence, we compute A and b by entering the following:

>> A = [2*P(:,1) 2*P(:,2) ones(9,1)] >> b = [P(:,1).^2 + P(:,2).^2]; Hence, we get the least squares solution >> x = inv(a *A)*A *b Then we find c 1, c 2, and r by: >> c1 = x(1) >> c2 = x(2) >> c3 = x(3) >> r = sqrt(c1^2 + c2^2 + c3) We plot this by executing >> theta = linspace(0,2*pi,200); >> plot(r*cos(theta)+c1,r*sin(theta)+c2), -,P(:,1),P(:,2), * ) Assignment Problem 1. Download the file lab7a.txt from the following link: http://www.math.byu.edu/~jeffh/teaching/m343/labs/lab7a.txt You can load this datafile by typing load lab7a.txt Note that the data is available in the matrix lab7a. This consists of two columns corresponding to the x and y values of a given data set. Use least squares to find the slope and y-intercept that best fits the data. Then plot the data points and the line on the same graph. Finish off the problem with a discussion of what you ve learned. Problem 2. Download the file lab7b.txt from the following link:

http://www.math.byu.edu/~jeffh/teaching/m343/labs/lab7b.txt You can load this datafile into Matlab by typing load lab7b.txt Note that the data is available in the matrix lab7b. This consists of two columns corresponding to the x and y values of a given data set. Use least squares to find the center and radius of the circle that best fits the data. Then plot the data points and the circle on the same graph. Finish off the problem with a discussion of what you ve learned.