Está en la página 1de 23

Numerical Techniques

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

Fit of Water Flow

60

Data
Linear Fit
Quadratic Fit
Cubic Fit

50

200

Flow Rate, CFS

Chapter 12

100

40
30
20

300

10

400
500

100

200

300

400

500

0
-10

3
Water Height, ft

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Section 12.2
Curve Fitting

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

There is scatter in all collected


data
We can estimate the equation that
represents the data by
eyeballing a graph
There will be points that do not fall
on the line we estimate
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

This line is just a best guess

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Least Squares

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

Finds the best fit straight line


Minimizes the amount each point
is away from the line
Its possible none of the points will
fall on the line
Linear Regression
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Polynomial Regression

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

Linear Regression finds a straight


line, which is a first order
polynomial
If the data doesnt represent a
straight line, a polynomial of
higher order may be a better fit

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

In MATLAB you do both linear


and polynomial regression the
same way the only difference is
the order

200
300
400
500

100

200

300

400

500

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

polyfit and polyval

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

polyfit finds the coefficients of a


polynomial representing the data
polyval uses those coefficients to
find new values of y, that
correspond to the known values
of x

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Coefficients of the
first order
polynomial
describing the best
fit line

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

y 2.9143* x 14.2857

100

200
300
400
500

100

200

300

400

500

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4

Linear Regression
(First Order)

-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

Evaluate how close a fit


youve achieved by taking
the difference between
the measured and
calculated points, and
adding them up

400

500

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Rate of Change

-5

Second Order Fit

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

A fifth order polynomial gives a perfect fit


to 6 points

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Improve your graph by adding more


points

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Section 12.3
Using the Interactive Curve Fitting
Tools

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

MATLAB 7 includes new interactive


plotting tools.
They allow you to annotate your plots,
without using the command window.
They include
basic curve fitting,
more complicated curve fitting
statistical tools
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Use the curve fitting tools

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

Create a graph
Making sure that the figure
window is the active window
select

200
300
400
500

100

200

300

400

500

Tools-> Basic Fitting


The basic fitting window will open on
top of the plot
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

120

Rate of Change

-5

Some Data

-4

100

-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

Temperature, degrees F

Rate of temperature change, degrees/hour

-4.5

80

y = 21*x + 3.8

y = 1.1*x 3 - 9.3*x 2 + 41*x - 3.1

60
data 1
linear
cubic

40
20

100

200
300

-20
-1

400
500

100

200

300

400

500

2
3
4
Time, seconds

Plot generated using the Basic Fitting Window

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Some Data

120

Temperature, degrees F

100
Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

80

y = 21*x + 3.8

y = 1.1*x 3 - 9.3*x 2 + 41*x - 3.1

60
40
20
0
-20
-1

3
Time,seconds

residuals
10
5

100

200

300

-5

400
500

100

200

300

400

500

-10
0

0.5

1.5

2.5

3.5

4.5

Residuals are the difference between the actual and calculated data
points
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

Basic Fitting Window


MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

You can also access the


data statistics window
from the figure menu bar.

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5

Select

-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

Tools->Data Statistics

from the figure window.

100

200
300
400
500

Data Statistics Window


100

200

300

400

500

This window allows you


to calculate statistical
functions interactively,
such as mean and
standard deviation,
based on the data in the
figure, and allows you to
save the results to the
workspace.

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Curve Fitting Toolbox

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

An optional toolbox that allows


more sophisticated curve fitting
It must be installed on your
computer
To open type
cftool

MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

Choose the data you want to plot and analyze in the


Curve Fitting and Data Windows
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

Rate of Change

-5

Rate of temperature change, degrees/hour

-4.5
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

100

200
300
400
500

100

200

300

400

500

Curve Fitting Windows


MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

US Population Data

-5

pop vs. cdate


fit 1
fit 2

250

Rate of Change

-4
-3.5
-3
-2.5

200

-2
-1.5
-1
-0.5
0

0.5

1.5

2.5

time, hour

3.5

4.5

Population, in millions

Rate of temperature change, degrees/hour

-4.5

150

100

50

100

200
300

400
500

100

200

300

400

500

1800

1820

1840

1860

1880 1900 1920


Census Year

1940

1960

1980

This plot of US Census Data was created using the


cftool interactive modeling capability
MATLAB for Engineers 2E, by Holly Moore. 2009 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction, storage in a retrieval
system, or transmission in any form or by any means, electronic, mechanical, photocopying, recording, or likewise. For information regarding permission(s), write
to: Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.

También podría gustarte