access mathematics linear graphs & best line fits (least squares)

27
Access Mathematics Linear Graphs & Best line fits (Least squares)

Upload: charity-johnson

Post on 27-Dec-2015

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Access Mathematics Linear Graphs & Best line fits (Least squares)

Access Mathematics

Linear Graphs &

Best line fits (Least squares)

Page 2: Access Mathematics Linear Graphs & Best line fits (Least squares)

2

Learning objectives

• After the session you will be able to:• Compute the salient details of a straight line in

space• Find the solution to two simultaneous equations

using graphical means• Algebraic solutions to systems of two equations.• Computer solutions to systems of equations• Use a computer (and/or calculator) to compute the

best line fit

Page 3: Access Mathematics Linear Graphs & Best line fits (Least squares)

3

Graphs Draw a table of values Plot the points accurately Draw a straight line or smooth curve, with a

sharp pencil. Read off values accurately

Page 4: Access Mathematics Linear Graphs & Best line fits (Least squares)

4

Recap: Graphs Plot the graph y = 2x + 1

x -3 -2 -1 0 1 2 3

2x -6 -4 -2 0 2 4 6 +1 1 1 1 1 1 1 1 y -5 -3 -1 1 3 5

7 Plot x and y

Page 5: Access Mathematics Linear Graphs & Best line fits (Least squares)

5

y = 2x + 1

-6-5-4-3-2-1012345678

-3 -2 -1 0 1 2 3

RiseRun

Rise

Run

Page 6: Access Mathematics Linear Graphs & Best line fits (Least squares)

6

y = 3x - 2

Plot the graph y = 3x - 2Plot the graph y = 3x - 2

•x -3 -2 -1 0 1 2

•y -11 -8 -5 -2 1 4

-3 -2 -1 0 1-12

-10

-8

-6

-4

-2

0

2

Page 7: Access Mathematics Linear Graphs & Best line fits (Least squares)

7

y = -2x + 3

0 1 2 3 4 5 6-10

-8

-6

-4

-2

0

2

4

MATLAB Commands:>>y=‘-2*x+3’>>fplot(y,[0,6])OR>>y=‘-2*x+3’>>ezplot(y)

Page 8: Access Mathematics Linear Graphs & Best line fits (Least squares)

8

Straight line summary

The equation for a straight line is always in the form: y = mx + c m is the gradient (calculated from the rise over the

run). And c is simply the intercept on the y axis.

x

y

Run

RisemNB

:

+ve -ve

Page 9: Access Mathematics Linear Graphs & Best line fits (Least squares)

9

Fractional coefficients

22

1 xy

23

1 xy

24

11 xy

-2 0 2 4 6-5

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-2 0 2 4 6-4

-3.5

-3

-2.5

-2

-1.5

-1

-2 0 2 4 6-4

-3.5

-3

-2.5

-2

-1.5

-1

Page 10: Access Mathematics Linear Graphs & Best line fits (Least squares)

10

3x + 2y = 12

How would we approach this problem

Note for implicit functions you must use the ezplotcommand

MATLAB Commands:>>ezplot(‘3*x+2*y=12)

Page 11: Access Mathematics Linear Graphs & Best line fits (Least squares)

11

2x – 3y = 18

MATLAB Commands:>>ezplot(‘2*x-3*y=18)

Page 12: Access Mathematics Linear Graphs & Best line fits (Least squares)

12

Group Discussion

14) xya

Sketch the graphs of the following:

xyb2

15)

3) yxc

Page 13: Access Mathematics Linear Graphs & Best line fits (Least squares)

13

The Intercept Method

3) yxa

42) yxb

623) yxc

623) yxd

Page 14: Access Mathematics Linear Graphs & Best line fits (Least squares)

14

Learning Check Solve the following using a

graphical method y=2x -1 & y= 8-x Use MATLAB to verify your

results.

Q. Is there a way to solve such problems algebraically?

0 1 2 3 4 5 6-2

0

2

4

6

8

10

12

Commands:>> ezplot('8-x‘)>> fplot(y,[0,6])>> hold on>> grid on>> y='2*x-1‘>> fplot(y,[0,6])>> fplot(y,[0,6],'r')

Read off or use ginput

Page 15: Access Mathematics Linear Graphs & Best line fits (Least squares)

15

Class Examples Time

• Solve the following problems using a graphical method and verify the results using algebra/MATLAB

• y=x+3 & y=7-x• y=x-4 & 2x+y=5• x+y =3 & y=1-2x• y=x+4 & y=3x• y=2x-1 & y=3x+2

Page 16: Access Mathematics Linear Graphs & Best line fits (Least squares)

16

Finding the Line

• Here’s the StarGate bit:• A point in three dimensions needs six pieces of

information to be fully described.• A course therefore seven • Since a line exists essentially in 2D then only two

pieces of information.• Two points• A gradient and a point

Page 17: Access Mathematics Linear Graphs & Best line fits (Least squares)

17

Example

Find the equation of the line given that it passes though the points (-2,1) and (6,5)

2

1

62

51Gradient theFind

x

ym

cxy 2

1intercept theFind

c )5(2

16 do point willAny c )2(

2

11or

Page 18: Access Mathematics Linear Graphs & Best line fits (Least squares)

18

Examples

1. Find the equation of the line given the points (-2,4) and (4,1) expressing your answer in the form ax+by=c.

2. A line has a gradient of –0.75 and passes through a point (3,-4), state the equation of the line.

3. Find the equation of a line with a gradient of unity given that it passes through the point (-1,-2).

Page 19: Access Mathematics Linear Graphs & Best line fits (Least squares)

19

Best Line Fit Consider the

following data if we suspect that these must fall on a straight line what is the best way of finding the relationship (the law of the line)

-4 -2 0 2 4-10

-5

0

5

10

Page 20: Access Mathematics Linear Graphs & Best line fits (Least squares)

20

Example: Best Line Fit

Find the best line fit given the following data

Hence or otherwise find the law of the line

-4 -2 0 2 4-10

-5

0

5

10

Page 21: Access Mathematics Linear Graphs & Best line fits (Least squares)

21

Class Discussion Time

• Plot the graph given the following data:• Find the best

line fit• Hence the law of

the line.

y-9.81-5.87-3.18-1.81-2.331.503.715.817.66

x-4-3-2-101234

Page 22: Access Mathematics Linear Graphs & Best line fits (Least squares)

22

Analytical: Best Line Fit

MATLAB is a useful tool to evaluate the line of best fit for you. The procedure is:

• Enter data • x=[-4:1:4]• y=[-9.81 -5.87 etc

• Plot graph • plot(x,y,’x’)

x-4-3-2-101234

y-9.81-5.87-3.18-1.81-2.331.503.715.817.66

Page 23: Access Mathematics Linear Graphs & Best line fits (Least squares)

23

Analytical: Best Line Fit

• Fit data to line• ployfit(x,y,1)• ans=2.0545 -0.5500

• Set up function• y1=‘2.0545*x-0.5500’

• Plot the function• hold on• fplot(y1,[-4:4],’k’)

-4 -2 0 2 4-10

-5

0

5

10

Page 24: Access Mathematics Linear Graphs & Best line fits (Least squares)

24

Group Activity:

The width of keyways for various shaft diameters are given by:

D 10 20 30 40 50 60 w 3.8 6.3 8.3 11.3 13.8 16.3

(1) Show that the relationship between D and W is linear and find the law of the line

(2) Use MATLAB or otherwise to find the analytical law of the line

Page 25: Access Mathematics Linear Graphs & Best line fits (Least squares)

25

Lesson summary

• Have we met our leaning objectives, specifically can you now:• Find the solution to two simultaneous equations

using graphical means• Algebraic solutions to systems of two equations.• Computer solutions to systems of equations• Use a computer (and/or calculator) to compute the

best line fit

Page 26: Access Mathematics Linear Graphs & Best line fits (Least squares)

26

Homework

1. Find the equation of the line given the points (-1,6) and (4,1) expressing your answer in the form ax+by=c.

2. A line has a gradient of 1/2 and passes through a point (-2,4), state the equation of the line.

3. Find the equation of a line with a gradient of unity given that it passes through the point (0,-4).

Page 27: Access Mathematics Linear Graphs & Best line fits (Least squares)

27

Homework

During an experiment to find the coefficient of friction between two surfaces the following results were obtained.

Load W (N) 10 20 30 40 50 60 Friction Force F (N) 1.5 4.3 7.6 10.4 13.5 15.6

Find the law connecting the variables in the form of:F=aW+b (You may use a computer if you wish)