Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #1548 > unrolled thread
| Started by | marcus.hanson@gmail.com |
|---|---|
| First post | 2012-12-20 13:01 -0800 |
| Last post | 2012-12-22 01:31 +0100 |
| Articles | 7 — 5 participants |
Back to article view | Back to comp.graphics.apps.gnuplot
fit gives different results for identical functions with different var names marcus.hanson@gmail.com - 2012-12-20 13:01 -0800
Re: fit gives different results for identical functions with different var names Brendan Halpin <brendan.halpin@ul.ie> - 2012-12-21 00:55 +0000
Re: fit gives different results for identical functions with different var names Karl <mail.kfr@gmx.net> - 2012-12-21 12:42 +0100
Re: fit gives different results for identical functions with different var names Marcus Hanson <marcus.hanson@gmail.com> - 2012-12-21 07:32 -0800
Re: fit gives different results for identical functions with different var names Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-12-21 19:21 +0100
Re: fit gives different results for identical functions with different var names Marcus Hanson <marcus.hanson@gmail.com> - 2012-12-21 11:54 -0800
Re: fit gives different results for identical functions with different var names Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2012-12-22 01:31 +0100
| From | marcus.hanson@gmail.com |
|---|---|
| Date | 2012-12-20 13:01 -0800 |
| Subject | fit gives different results for identical functions with different var names |
| Message-ID | <4da37e57-cdcd-474e-a3c3-7e98f09b1cb6@googlegroups.com> |
I am using gnuplot for windows, trying to fit gaussian data. I am doing this from a program that has to run many fits on different sets of data, so I would like to use different variable names. Unfortunately, it seems that unless I use single-character names, I get completely unreasonable results. The results are identical for the same data for every function with variable names more than one charcter long, but always reasonable for functions with variables only one variable long. For example: fa(xa) = aa*exp(-(xa-ma)**2/(2*sa**2)) gives results identical to f2(x2) = a2*exp(-(x2-m2)**2/(2*s2**2)), but different from f(x) = a*exp(-(x-m)**2/(2*s**2)) I cannot find any restriction on length of variable names in the documentation. Any ideas?
[toc] | [next] | [standalone]
| From | Brendan Halpin <brendan.halpin@ul.ie> |
|---|---|
| Date | 2012-12-21 00:55 +0000 |
| Message-ID | <878v8s4424.fsf@wivenhoe.ul.ie> |
| In reply to | #1548 |
Does it help to put all the variables in the function argument list? i.e. fa(xa,aa,ma,sa) = aa*exp(-(xa-ma)**2/(2*sa**2)) Otherwise you are referring to global variables in the body of the function, which might be the source of the instability. Brendan -- Brendan Halpin, Department of Sociology, University of Limerick, Ireland Tel: w +353-61-213147 f +353-61-202569 h +353-61-338562; Room F1-009 x 3147 mailto:brendan.halpin@ul.ie ULSociology on Facebook: http://on.fb.me/fjIK9t http://teaching.sociology.ul.ie/bhalpin/wordpress twitter:@ULSociology
[toc] | [prev] | [next] | [standalone]
| From | Karl <mail.kfr@gmx.net> |
|---|---|
| Date | 2012-12-21 12:42 +0100 |
| Message-ID | <kb1i3c$st5$1@news.rz.uni-karlsruhe.de> |
| In reply to | #1548 |
Am 20.12.2012 22:01, schrieb marcus.hanson@gmail.com: > I am using gnuplot for windows, trying to fit gaussian data. I am doing this from a program that has to run many fits on different sets of data, so I would like to use different variable names. Unfortunately, it seems that unless I use single-character names, I get completely unreasonable results. The results are identical for the same data for every function with variable names more than one charcter long, but always reasonable for functions with variables only one variable long. > > For example: > fa(xa) = aa*exp(-(xa-ma)**2/(2*sa**2)) > gives results identical to f2(x2) = a2*exp(-(x2-m2)**2/(2*s2**2)), but different from f(x) = a*exp(-(x-m)**2/(2*s**2)) > > I cannot find any restriction on length of variable names in the documentation. > Any ideas? > I´m sure there is no restriction on the lenght ov variable names. Have you initialized all your variables identically for the three functions? And put all the right variable names in the "via" statement? Karl
[toc] | [prev] | [next] | [standalone]
| From | Marcus Hanson <marcus.hanson@gmail.com> |
|---|---|
| Date | 2012-12-21 07:32 -0800 |
| Message-ID | <5c431d1b-bbc9-418b-8707-588d0ff79beb@googlegroups.com> |
| In reply to | #1550 |
On Friday, December 21, 2012 5:42:08 AM UTC-6, Karl wrote: > Have you initialized all your variables identically for the three > functions? And put all the right variable names in the "via" statement? > Does it help to put all the variables in the function argument list? I have the correct 'via' statements and I have initialized the variables. Here is exactly what I have done: gnuplot>aa=1;ma=1;sa=1;xa=1; gnuplot>fa(xa,aa,ma,sa)=aa*exp(-(xa-ma)**2/(2*sa**2)) gnuplot>fit fa(xa,aa,ma,sa) 'test.dat' u 1:2 via aa,ma,sa This gives aa=55,ma=0.98,sa=1 (rounded off values) with enormous standard errors (on the order of 10^16 to 10^19). These numbers do not even remotely fit the data. On the other hand, I have tried the following: gnuplot>a=1;m=1;s=1;x=1; gnuplot>f(x)=a*exp(-(x-m)**2/(2*s**2)) gnuplot>fit f(x) 'test.dat' u 1:2 via a,m,s This gives a=236,m=-1,s=-2.6 (also rounded), with standard errors less than 10%. This also fits the function remarkably well by all measures I know. I tried various different variable names of more than one character, and they all gave exactly identical results, all of them very wrong. Could this be some setting I accidentally changed a while ago in gnuplot?
[toc] | [prev] | [next] | [standalone]
| From | Hans-Bernhard Bröker <HBBroeker@t-online.de> |
|---|---|
| Date | 2012-12-21 19:21 +0100 |
| Subject | Re: fit gives different results for identical functions with different var names |
| Message-ID | <50D4A8B1.5060708@t-online.de> |
| In reply to | #1551 |
On 21.12.2012 16:32, Marcus Hanson wrote:
> On Friday, December 21, 2012 5:42:08 AM UTC-6, Karl wrote:
> I have the correct 'via' statements and I have initialized the variables. Here is exactly what I have done:
>
> gnuplot>aa=1;ma=1;sa=1;xa=1;
> gnuplot>fa(xa,aa,ma,sa)=aa*exp(-(xa-ma)**2/(2*sa**2))
Those two lines are overdoing things a bit. You would normally either
do it with global variables:
gnuplot>aa=1;ma=1;sa=1;xa=1;
gnuplot>fa(xa)=aa*exp(-(xa-ma)**2/(2*sa**2))
gnuplot>fit fa(xa) 'test.dat' u 1:2 via aa,ma,sa
or locally, using function arguments:
gnuplot>fa(x,a,m,s)=aa*exp(-(xa-ma)**2/(2*sa**2))
gnuplot>fit fa(x,aa,ma,sa) 'test.dat' u 1:2 via aa,ma,sa
But that's not the real problem. That rather is your use of 'xa'>
> gnuplot>fit fa(xa,aa,ma,sa) 'test.dat' u 1:2 via aa,ma,sa
^^
Where did you expect this 'xa' to come from?
[toc] | [prev] | [next] | [standalone]
| From | Marcus Hanson <marcus.hanson@gmail.com> |
|---|---|
| Date | 2012-12-21 11:54 -0800 |
| Subject | Re: fit gives different results for identical functions with different var names |
| Message-ID | <128492cd-ff3e-4d40-a6a1-1314f9ec2c92@googlegroups.com> |
| In reply to | #1553 |
On Friday, December 21, 2012 12:21:37 PM UTC-6, Hans-Bernhard Bröker wrote: > > gnuplot>fit fa(xa,aa,ma,sa) 'test.dat' u 1:2 via aa,ma,sa > > ^^ > Where did you expect this 'xa' to come from? I see. So does this mean that GNUPlot assumes that the independent variable will be 'x'? My assumption (given my experience with mathematics notation and not programming) was that it would assume that whatever is in the parentheses after the function name would be and independent variable. (It was only at the suggestion of Brendan Halpin, which I did not understand at the time, that I put all of the variables in these parentheses.) Everything makes quite a bit more sense if GNUPlot just assumes the use of the variable 'x'. Thank you!
[toc] | [prev] | [next] | [standalone]
| From | Hans-Bernhard Bröker <HBBroeker@t-online.de> |
|---|---|
| Date | 2012-12-22 01:31 +0100 |
| Subject | Re: fit gives different results for identical functions with different var names |
| Message-ID | <ajkdbhF55doU1@mid.dfncis.de> |
| In reply to | #1554 |
On 21.12.2012 20:54, Marcus Hanson wrote: > I see. So does this mean that GNUPlot assumes that the independent > variable will be 'x'? By default: yes. See "help fit" (first paragraph after the syntax outline) or "help set dummy" for how to change that assumption.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.graphics.apps.gnuplot
csiph-web