f



linear fit of looped (and cutted) data set

I've done measurements of cycling loads and saved into a text-file. Now i n=
eed to make a linear fit to these data points by only take care of a specif=
ic part of data points (limited y-range). - Hard to descirbe - therefore i =
tried to make a sketch of it: see http://ovh.to/2u45XF4

If i'll do this by setting a set of range during fit-command by using:
[code]
f(x) =3D k*x + d
fit [x_min:x_max] [y_min:y_max] f(x) "DATA.txt" using 2:3 via k,d
[/code]
i'll get a wrong fitting curve, because gnuplot seams to connect the dead e=
nds of the cutted Data-set (seen in (1) of my sketch).

I think i will need a function that fits the linear function best to existi=
ng points ignoring the cutted dead ends (seen in (2) of my sketch).

Does anyone know a solution to get this behaviour?
0
UTF
11/27/2016 3:31:07 PM
comp.graphics.apps.gnuplot 5008 articles. 0 followers. Post Follow

3 Replies
134 Views

Similar Articles

[PageSpeed] 59

Markus Grünwald wrote:

> I've done measurements of cycling loads and saved into a text-file.
> Now i need to make a linear fit to these data points by only take care
> of a specific part of data points (limited y-range). - Hard to
> descirbe - therefore i tried to make a sketch of it: see
> http://ovh.to/2u45XF4
> 
> If i'll do this by setting a set of range during fit-command by using:
> [code]
> f(x) = k*x + d
> fit [x_min:x_max] [y_min:y_max] f(x) "DATA.txt" using 2:3 via k,d
> [/code]
> i'll get a wrong fitting curve, because gnuplot seams to connect the
> dead ends of the cutted Data-set (seen in (1) of my sketch).
> 
> I think i will need a function that fits the linear function best to
> existing points ignoring the cutted dead ends (seen in (2) of my
> sketch).
> 
> Does anyone know a solution to get this behaviour?

Looks like maybe you want to fit the first derivative of the
trajectory rather than fitting the trajectory itself.
0
Ethan
11/27/2016 7:29:47 PM
Am 27.11.2016 um 16:31 schrieb Markus Grünwald:
> I've done measurements of cycling loads and saved into a text-file. Now i need to make a linear fit to these data points by only take care of a specific part of data points (limited y-range). - Hard to descirbe - therefore i tried to make a sketch of it: see http://ovh.to/2u45XF4
> 
> If i'll do this by setting a set of range during fit-command by using:
> [code]
> f(x) = k*x + d
> fit [x_min:x_max] [y_min:y_max] f(x) "DATA.txt" using 2:3 via k,d
> [/code]
> i'll get a wrong fitting curve, because gnuplot seams to connect the dead ends of the cutted Data-set (seen in (1) of my sketch).
> 
> I think i will need a function that fits the linear function best to existing points ignoring the cutted dead ends (seen in (2) of my sketch).


Note that the order of datapoints makes no difference to the fitting
algorithm. It only sees a cloud of pairs of xy values.

And each section of your curve has its own intersect d.
0
Karl
11/27/2016 9:11:01 PM
Am Sonntag, 27. November 2016 20:29:46 UTC+1 schrieb Ethan A Merritt:

> Looks like maybe you want to fit the first derivative of the
> trajectory rather than fitting the trajectory itself.

Good advice.

After little research and help of following blog https://stackoverflow.com/questions/15751226/how-can-i-plot-the-derivative-of-a-graph-in-gnuplot

if done following:
[code]
limitlo(x,lo) = (x > lo) ? x : 0/0
limithi(x,hi) = (x < hi) ? x : 0/0
limitlohi(x,lo,hi) = limitlo(limithi(x,hi),lo)
d2(x,y) = ($0 == 0) ? (x1 = x, y1 = y, 1/0) : (x2 = x1, x1 = x, y2 = y1, y1 = y, (y1-y2)/(x1-x2))

dx=.5; ylo=550; yhi=2500
fit [0:20] kwm "Data.txt" using ($2-dx):(d2($2,(limitlohi($3,ylo,yhi)))) via kwm
fm(x) = kwm*x + dwm
fit [0:20] [ylo:yhi] fm(x) "Data.txt" using 2:3 via dwm
[/code]

and now i got quite what i expected to.
0
UTF
11/27/2016 10:56:41 PM
Reply: