Discussion about math, puzzles, games and fun.   Useful symbols: ÷ × ½ √ ∞ ≠ ≤ ≥ ≈ ⇒ ± ∈ Δ θ ∴ ∑ ∫  π  -¹ ² ³ °

You are not logged in.

## #1 2010-08-26 21:15:08

DaveRobinsonUK
Member
Registered: 2010-04-24
Posts: 123

### Curve Fitting

If I have some data and I do a scatter plot of the data.

How could I produce a function which plots a line through the data points?

Would it have to be piecewise, between the points or could you have one function and some algorithm to do this?

Can feel it coming together.. Slowly but Surely

Offline

## #2 2010-08-26 21:36:33

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Curve Fitting

Hi Dave;

Just provide me with the data the scatter plot will not be necessary.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #3 2010-08-26 22:08:11

DaveRobinsonUK
Member
Registered: 2010-04-24
Posts: 123

### Re: Curve Fitting

Hi Bobby

It's nothing actually recorded, and the set is not big (only 5 elements). I was just trying to see how I could put what I am learning into some practice.

The set is this

Time(t)    Fluid(F)
0             0
1             3
2             10
3             12
4             15
5             18

I can do plots and regression lines and also find gradients between the elements, but not sure how I would go about creating something that would smoothly pass through them as a function of (t)

Also my MATLAB has stopped working, so trying to fix that at the moment.

Can feel it coming together.. Slowly but Surely

Offline

## #4 2010-08-26 22:22:44

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Curve Fitting

Hi dave;

The least square fit through that is

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #5 2010-08-26 22:30:24

DaveRobinsonUK
Member
Registered: 2010-04-24
Posts: 123

### Re: Curve Fitting

Would you have to do something like Fourier Analysis to get a smooth curve?

Can feel it coming together.. Slowly but Surely

Offline

## #6 2010-08-26 22:32:58

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Curve Fitting

You don't need a fourier fit. I can fit a polynomial through all the points. What kind of fit do you require?

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #7 2010-08-26 22:40:32

DaveRobinsonUK
Member
Registered: 2010-04-24
Posts: 123

### Re: Curve Fitting

not sure, I am just trying to put what I have learned to some practical use.

Say I go out everyday and measure the growth of a plant, and wanted to find the rate at which it is growing on a particular day.

I suppose what I am asking it how do you create a polynomial that fits the data.

Can feel it coming together.. Slowly but Surely

Offline

## #8 2010-08-26 22:42:09

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Curve Fitting

Hi dave;

For an interpolating polynomial, one that goes through all the points exactly:

I have to caution you about going past your data points to make predictions for the future. Interpolation or going between your data points is much more reliable. Extrapolation can only be done when you know the underlying law of the points. Usually a DE. A fit cannot guarantee that it will continue.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #9 2010-08-26 22:53:50

DaveRobinsonUK
Member
Registered: 2010-04-24
Posts: 123

### Re: Curve Fitting

Hi Bobby

Thanks for this, I will have a go with that one.

Is there some process that you used to get the result, that works universally or is it dependent on the data?

Can feel it coming together.. Slowly but Surely

Offline

## #10 2010-08-26 22:58:08

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Curve Fitting

Yes, there is. For the first one as you know from linear regression there is a formula. For the interpolating poly there is a method. You must solve a 5 x 5 linear set of simultaneous equations. This is difficult by hand. Best done by computer. That is why we use least squares over interpolation. We are always dealing with a smaller degree polynomial, less computational hassles.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #11 2010-08-27 00:02:58

DaveRobinsonUK
Member
Registered: 2010-04-24
Posts: 123

### Re: Curve Fitting

Cool.

Yes, just been looking at Linear Interpolation on Wikipedia. I can see how that it complicated and would take some time.

Can feel it coming together.. Slowly but Surely

Offline

## #12 2010-08-27 00:07:44

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Curve Fitting

Hi Dave;

I am having trouble uploading any images right now so I can't show the plots of these functions. Because it is only 6 points we can a do an interpolating fit. But what if it were 10000 points. Nobody wants to look at a 10000 degree polynomial. That is where least square fits come in handy.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline

## #13 2010-08-27 00:42:31

DaveRobinsonUK
Member
Registered: 2010-04-24
Posts: 123

### Re: Curve Fitting

Hi Bobby

Yes I see. The least squares fit is more accurate over a large number of points, than it seems to be with a small number.

You always see these diagrams in books with 5 or 6 points and fitting doesn't look that good.

Can feel it coming together.. Slowly but Surely

Offline

## #14 2010-08-27 00:53:01

bobbym
bumpkin
From: Bumpkinland
Registered: 2009-04-12
Posts: 109,606

### Re: Curve Fitting

Hi;

For a very big number of points it is the only option.

In mathematics, you don't understand things. You just get used to them.
If it ain't broke, fix it until it is.
Always satisfy the Prime Directive of getting the right answer above all else.

Offline