Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #3485 > unrolled thread

linear fit of looped (and cutted) data set

Started byMarkus Grünwald <m_grueni@web.de>
First post2016-11-27 07:31 -0800
Last post2016-11-27 22:11 +0100
Articles 5 — 3 participants

Back to article view | Back to comp.graphics.apps.gnuplot


Contents

  linear fit of looped (and cutted) data set Markus Grünwald <m_grueni@web.de> - 2016-11-27 07:31 -0800
    Re: linear fit of looped (and cutted) data set Ethan A Merritt <EAMerritt@gmail.com> - 2016-11-27 11:29 -0800
      Re: linear fit of looped (and cutted) data set Markus Grünwald <m_grueni@web.de> - 2016-11-27 14:56 -0800
        Re: linear fit of looped (and cutted) data set [solved] Markus Grünwald <m_grueni@web.de> - 2016-12-26 14:52 -0800
    Re: linear fit of looped (and cutted) data set Karl Ratzsch <mail.kfr@gmx.net> - 2016-11-27 22:11 +0100

#3485 — linear fit of looped (and cutted) data set

FromMarkus Grünwald <m_grueni@web.de>
Date2016-11-27 07:31 -0800
Subjectlinear fit of looped (and cutted) data set
Message-ID<4ad61db7-dd62-4b0f-8bb6-ffa3305505fb@googlegroups.com>
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?

[toc] | [next] | [standalone]


#3486

FromEthan A Merritt <EAMerritt@gmail.com>
Date2016-11-27 11:29 -0800
Message-ID<o1fc4s$bo2$1@dont-email.me>
In reply to#3485
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.

[toc] | [prev] | [next] | [standalone]


#3488

FromMarkus Grünwald <m_grueni@web.de>
Date2016-11-27 14:56 -0800
Message-ID<aa2bf3fc-6c30-42a9-ab4b-d04c2dece171@googlegroups.com>
In reply to#3486
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.

[toc] | [prev] | [next] | [standalone]


#3498 — Re: linear fit of looped (and cutted) data set [solved]

FromMarkus Grünwald <m_grueni@web.de>
Date2016-12-26 14:52 -0800
SubjectRe: linear fit of looped (and cutted) data set [solved]
Message-ID<1321e4bf-c117-4ed3-b2a7-317fd0577e10@googlegroups.com>
In reply to#3488
After a bunch of trial and error I've found a better solution (fits now as i expected it should do):

Due to the fact that i limited the ordinates (and not abscissa as expected by gnuplot - and also gnumeric, what I've tried too) I've got this strange results. So i just switched the axis and did a fit on yx-pairs of data:

[code]
f(x) = (x - d) / k
fit [ymin:ymax] [xmin:xmax] f(x) "Data.txt" using 3:2 via k,d
f(x) = k*x + d
[/code]

now it works perfectly.

[toc] | [prev] | [next] | [standalone]


#3487

FromKarl Ratzsch <mail.kfr@gmx.net>
Date2016-11-27 22:11 +0100
Message-ID<o1fi59$uhn$1@solani.org>
In reply to#3485
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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.graphics.apps.gnuplot


csiph-web